high severityclaude-code

    Claude Code Memory Bloat & Context Rot — Why Longer CLAUDE.md Makes Agents Worse

    Degradation: Agents get slower, cost 20%+ more per session, and forget critical rules as CLAUDE.md grows.

    Direct-Answer Fix Summary

    Peer-reviewed studies (IFScale NeurIPS 2025 and ETH Zurich 2026) prove that instruction compliance drops steadily past ~150 rules and auto-generated context bloat lowers task success in 5 of 8 benchmarks while raising inference cost by 20–23%. Cure context rot by pruning stale rules (C1/D2), capping root CLAUDE.md at 60–150 lines, and loading deep docs conditionally.

    Broken vs. Fixed Configuration

    Bloated: Auto-generated directory dump + stale session logs
    # CLAUDE.md (640 lines)
    ## Every File In src/ (auto-generated 180 lines...)
    ## Sprint 14 Notes (from 5 months ago...)
    ## Code Style (restating Prettier defaults for 90 lines...)
    Lean: High-signal 90-line harness + conditional docs
    # CLAUDE.md (90 lines)
    ## Verification
    - Single test: npx vitest run <path>
    - Full gate: pnpm tsc --noEmit && pnpm lint && pnpm test
    
    ## Non-Obvious Rules Only
    - Don't hand-edit src/generated/. Instead run pnpm codegen. Because CI overwrites manual edits.
    - For billing state machines, read docs/billing-fsm.md first.

    Why This Happens

    Teams treat CLAUDE.md as an append-only graveyard of one-off bug fixes and auto-generated /init boilerplate. Dead-weight rules compete for attention with the 10 rules that actually matter.

    Step-by-Step Fix

    1. 01
      Audit token footprint and cost

      Drop your file into the AgentLint Token Counter to see its exact context percentage and team monthly spend.

    2. 02
      Delete obvious filler and LLM-generated summaries

      Remove directory trees the agent can discover with ls/rg and persona fluff like You are a senior engineer (Rule I5).

    3. 03
      Split subsystem guides behind conditional pointers

      Keep only universal build/test commands and high-impact boundaries in root CLAUDE.md.

    4. 04
      Keep active task state in HANDOFF.md, not CLAUDE.md

      Session-specific status belongs in HANDOFF.md (Rule C2/C6) so permanent repo rules stay timeless.

    Automated AgentLint Checks That Catch This

    Frequently Asked Questions

    Why did ETH Zurich find auto-generated context files hurt performance?

    Auto-generated files mostly repeat directory structures and obvious tooling facts the model already infers, adding noise tokens (+20–23% cost) without supplying counterintuitive domain boundaries.

    How often should teams prune CLAUDE.md?

    Review CLAUDE.md monthly or whenever a major framework changes; AgentLint rule C1 flags stale documentation drift.

    Related Troubleshooting Guides