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.2.0.tar.gz (32.6 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.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for codediet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7bf0900adb20f53415e0e5f879e3553e7d4cdfcce48ce7e1e40e165c0884d11d
MD5 59530ac0a145b47a4230f04211f7dd1c
BLAKE2b-256 84268d21b5a0ea29e74892de999f0c6f94d57c92f18b620f84fca78accfb5171

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codediet-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36da4ec7470886b4f8f2ef14020325cf0c56afdd185fd80ded52c9b095c8c464
MD5 3cfcd24954d005ffa4881b9b8e1ac720
BLAKE2b-256 1e31e68a0205dcdd82952b49d1cea3a486408dccf3ea8b3353df9c0491cc7090

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