Claude Code CLIContext length exceeded / Auto-compact triggered

Claude Code Context Window Full: Preventing Token Bloat & Slowdowns

DIRECT ANSWER

Large contexts resend 150K+ tokens on every single turn, rapidly draining 5-hour and weekly limits. Proactive /compact calls and task-scoped sessions cut token burn by over 60%.

Calculate Context Bloat Cost Impact →

Quick Impact Check: 85% Cache vs 0% Cache (25M tokens/day)

Example based on Claude 3.5 / Sonnet pricing ($3 input / $0.30 cache read / $15 output per 1M tokens) over 22 days.

HEALTHY (85% CACHE HIT)$520 / mo

Most repository context is served at 10% cache-read price.

CACHE BUSTED (0% CACHE HIT)$1,782 / mo (3.4x higher)

Dynamic prefixes force full $3/1M input billing on every turn.

Why this happens

  • Chaining 5+ unrelated features or debugging loops inside a single terminal session.
  • Reading large lockfiles, build artifacts, or verbose test logs directly into the context window.

Step-by-step fix

  1. 1. Run /compact with focus instructions or /clear

    Use /clear after finishing a module; when preserving decisions, pass explicit focus hints like /compact keep API schema.

  2. 2. Exclude noisy directories in .claudeignore

    Block dist/, build/, and verbose log dumps so the agent never pulls megabytes of noise into context.

Frequently Asked Questions

Does Auto-compact invalidate the prompt cache?

Yes. Re-summarizing earlier turns alters the prompt prefix, causing a cache write on the next turn—making clean task boundaries even more cost-effective.

Related troubleshooting guides