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 structural bloat introduced 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 territory is narrower and currently underserved: structural bloat that is syntactically valid, passes every test, and is invisible in a 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.

Duplicate helpers, abandoned _v2/_final implementations, sprawling utils.py files, pass-through wrapper functions — these don't break tests, pass code review, and accumulate silently until the codebase becomes genuinely hard to navigate.

What It Detects

CodeDiet separates findings into two categories — the distinction matters and is always visible in output:

  • Facts — mechanically verifiable structural claims. True by construction; no interpretation required.
  • Review Recommendations — heuristic signals worth a human look, with no claim about what inspection will find.

Shipped (v0.3)

Wrapper Functions (Fact) — 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 as Facts
def parse_float(x):
    return float(x)

def file_exists(path):
    return os.path.exists(path)

Detection is deterministic and mechanical — no AI, no heuristics, no probabilistic scoring. Every fact-class finding is reproducible from the AST.

Roadmap (documented, not yet implemented)

  • Duplicate Helper Detection (Review) — functions with similar names, signatures, and structure, often the AI equivalent of reinventing the same helper under three names.
  • Abandoned Implementation Detection (Review)search_v2, search_new, search_final left behind after iterative prompting.
  • Similar Module Detection (Review) — files with unusually high structural overlap.
  • Utility Explosion Detection (Review) — projects accumulating an unusually large number of helpers.py, utils.py, common.py files.

Roadmap detectors are fully specified and designed — not placeholders — but not yet implemented. The README will be updated as each ships.

Installation

Requires Python 3.12+.

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

# Scan a directory (prints output to stdout)
codediet doctor .

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

# Output findings as JSON
codediet doctor . --json

# Export findings to a file (Markdown or plain text)
codediet doctor . --export findings.md

# Export findings and append an LLM hand-off prompt
codediet doctor . --export findings.md --prompt

Text Output

Files scanned: 42

FACTS — Mechanically Verifiable (3 found)

  [WRAPPER]
    utils.py:18
    parse_float -> float

  [WRAPPER]
    helpers.py:44
    file_exists -> os.path.exists

  [WRAPPER]
    client.py:91
    send -> self._http.post

REVIEW RECOMMENDATIONS — Heuristic Signals (0 found)
  (none)

JSON Output

{
  "facts": [
    {
      "detector": "wrapper",
      "file": "utils.py",
      "line": 18,
      "message": "parse_float -> float",
      "evidence": {
        "function": "parse_float",
        "target": "float"
      }
    }
  ],
  "review_recommendations": []
}

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

Programmatic Library API

CodeDiet can be imported and used directly inside other Python codebases:

from codediet import scan, Finding
from codediet.models import FindingClass

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

# Separate facts from review recommendations
facts = [f for f in findings if f.classification == FindingClass.FACT]
reviews = [f for f in findings if f.classification == FindingClass.REVIEW]

# Inspect a finding
for f in facts:
    print(f"[{f.detector.upper()}] {f.file}:{f.line}")
    print(f"  {f.message}")
    print(f"  evidence: {f.evidence}")

The Finding dataclass fields:

Field Type Description
detector str Detector name, e.g. "wrapper"
classification FindingClass FACT or REVIEW
file str Relative file path
line int Line number
message str Human-readable summary
evidence dict Structured, detector-specific data

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.
  • Honest about uncertainty. The Fact/Review distinction is a user-facing contract, not an internal note. Users can always tell whether a finding is a structural certainty or a "go look at this."
  • 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 .

# Build
uv build

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.3.0.tar.gz (54.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.3.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codediet-0.3.0.tar.gz
  • Upload date:
  • Size: 54.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.3.0.tar.gz
Algorithm Hash digest
SHA256 006477b86d33bb921c5c10b20629026af7a8dfcb52d913516cdac0f42e58db83
MD5 29d79c7a86cfde759af693eb3a783cc1
BLAKE2b-256 644d03f2f91f024d47d04760c189bbba104cde30a3e260f8455a0aa69d134520

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codediet-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71931cd82efc3740d0274cd251354402e8593d23f5ec58dad8218a4da971a119
MD5 daacdf94f8414e61bfa19b6568fc9324
BLAKE2b-256 17a2d0e5fcd350bde061feeef7b4b724c2fd6437bd4a50d42ff902dd1eb4d9c8

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