Skip to main content

Put AI-generated code on a diet. Detects structural bloat caused by AI coding assistants.

Project description

CodeDiet

Put AI-generated code on a diet.

CodeDiet is a read-only static analysis CLI that detects unnecessary structural bloat caused by AI coding assistants (Cursor, Claude Code, Copilot, Windsurf, ChatGPT). It answers one question: "does this code exist but probably not need to?"

It does not look for bugs, security issues, style violations, performance problems, or dead code. Other tools already do those well (Ruff, Pylint, Vulture, Semgrep). CodeDiet's niche is structural bloat that is syntactically valid, passes tests, and is invisible in normal code review.

Why This Exists

AI-generated code now accounts for a significant share of new commits in AI-heavy repositories — and with it, code churn has risen substantially. For the first time on record, duplicated/copy-pasted code volume has exceeded refactored/moved code volume. The "path of least resistance" for an LLM is additive, not corrective: it layers new wrapper/helper functions over existing logic rather than reorganizing it.

The specific anti-pattern CodeDiet targets — a function that does nothing but forward a call — is a long-recognized code smell ("Middle Man"). LLMs simply produce it at much higher volume because they operate on localized prompts without awareness of existing utilities elsewhere in the codebase.

What It Detects (v0.1)

Wrapper Functions — functions whose entire body is a single pass-through call to another function, forwarding arguments unchanged with no added logic:

# These are wrappers — CodeDiet will flag them
def parse_float(x):
    return float(x)

def process_number(x):
    return helper(x)

Detection is deterministic and mechanical — no AI, no heuristics, no probabilistic scoring. Every finding is a structural fact derived from the AST.

Installation

Requires Python 3.13+.

Install via pip:

pip install codediet

Or install globally as a command-line tool via uv:

uv tool install codediet

Developing from Source

git clone https://github.com/AkshatPal2007/CodeDiet.git
cd CodeDiet
uv sync

Usage

Command Line Interface

If installed globally or via pip:

# Scan a directory
codediet .

# Scan a specific file
codediet path/to/file.py

# JSON output
codediet . --json

If running from the source tree with uv:

uv run codediet .

Programmatic Library API

CodeDiet can also be imported and run directly inside other Python codebases:

from codediet import scan

# Scan a project folder or a single file
findings = scan("/path/to/other/project")

# Process the findings programmatically
for finding in findings:
    print(f"[{finding.kind.upper()}] {finding.file}:{finding.line}")
    print(f"  {finding.function} -> {finding.target}")

Text Output

Files scanned: 42

Wrapper Functions Found: 3

WRAPPER
  utils.py:18
  parse_float -> float

WRAPPER
  helpers.py:44
  process_number -> helper

JSON Output

{
  "wrappers": [
    {
      "file": "utils.py",
      "line": 18,
      "function": "parse_float",
      "target": "float"
    }
  ]
}

No scores. No percentages. No rankings. No suggestions. CodeDiet reports observations, never judgments — the developer decides what to do.

Design Principles

  • Trust over feature count. A tool that's wrong even occasionally gets uninstalled and not reconsidered. CodeDiet aggressively avoids false positives — it would rather miss a real wrapper than flag something that isn't one.
  • Deterministic. No LLMs, no embeddings, no AI scoring. Every finding is mechanically reproducible from the AST.
  • Read-only. CodeDiet never modifies source code, never generates fixes, never suggests deletions.
  • No composite scores. No "Bloat Score: 57" — that's exactly the kind of output this project exists to NOT produce.

Development

# Run tests
uv run pytest tests/ -v

# Lint
uv run ruff check .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codediet-0.1.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codediet-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file codediet-0.1.0.tar.gz.

File metadata

  • Download URL: codediet-0.1.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for codediet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d65ed84611644d57575f739c85cc8ba12aa7239cc33d560f9aa348ee88e09bee
MD5 c0f60aef468e84fd6f367a8a81df0b7a
BLAKE2b-256 4fd59fff5b3fa08e1b71a53e741e8fcc3cef37d7b51b4e06c8d6b933aebb49ae

See more details on using hashes here.

File details

Details for the file codediet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codediet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for codediet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06f562c6ecacbc937a9abae8de5e4026e97e8e2491fdb6c814b7f48e708c7e4c
MD5 d8f604ec4af5f00f1a2409abd935373c
BLAKE2b-256 82dc3d1228d1551a8fa7624b2c3c131818712cb867e4a772a3610749290a186f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page