Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 3 min read

Why you keep hitting Claude Code's usage limit: 8 fixes, measured on 6 billion tokens

If Claude Code tells you "You've hit your session limit" more often than you expect, the cause is usually not the work you asked for. It's what rides along with every request. I measured three months of my own logs (6 b

If Claude Code tells you "You've hit your session limit" more often than you expect, the cause is usually not the work you asked for. It's what rides along with every request.

I measured three months of my own logs (6 billion tokens, 624 sessions, 2,193 subagents) with Agent Wrapped. 71% of the spend was context (the conversation written to the prompt cache and read back each turn), not the model's answers. Here are the fixes that matter, roughly in order of what they saved.

1. Find the loop you forgot about

In 7 of my 9 limit walls, the biggest consumer was a scheduled agent: a claude -p job running every 15 to 30 minutes. Each run starts a fresh session and pays the full startup cost (system prompt, tool definitions, memory files) before doing anything.

Fix: list what runs on a schedule (cron, Task Scheduler, launchd, ~/.claude/scheduled-tasks/). Run each job less often, or batch the work into fewer, larger runs.

2. /clear between tasks

Every turn re-reads the entire conversation. Past about 150k tokens, each extra turn pays for all of it again. My most expensive sessions peaked above 500k tokens of context.

Fix: when you switch to a new task, /clear. The new task doesn't need the old task's 200k tokens riding along.

3. /compact before you walk away

The prompt cache expires. Come back after a long pause and the whole conversation is written to the cache again at the full write price, which is much more than reading it.

Fix: at a natural stopping point, /compact and say what to keep (/compact keep the API design and the failing test). Coming back to a small context is cheap.

4. Don't switch models or MCP servers mid-session

Caches are per model, and the tool list sits at the start of the prompt. Switching with /model, or connecting and disconnecting MCP servers partway through, throws the cache away and rewrites everything after it.

Fix: pick the model and tools at the start of a session.

5. Disconnect MCP servers you don't use here

Every connected server adds its tool descriptions to every request of every session and every subagent. My median subagent started at 28k tokens before doing any work.

Fix: /mcp and turn off what this project doesn't need.

6. Keep CLAUDE.md lean

CLAUDE.md and memory files load on every request. A 6,000-token CLAUDE.md costs 6,000 tokens on every turn.

Fix: keep only what the agent needs every time. Move rarely needed detail into separate files it reads on demand.

7. Ask for the part, not the file

One big tool result (a PDF, a lock file, a full test log) is paid for when it arrives and again on every later turn of the session. I had 5,858 results over 4,000 tokens.

Fix: "read lines 100 to 180", Grep first, add | tail -50 to noisy commands, and give page ranges for PDFs. Put "keep command output short" in CLAUDE.md so it's the default.

8. Give search-and-read subagents a cheaper model

Subagents were 60% of my usage. Much of that work is searching and summarizing, which a smaller model handles well.

Fix: in .claude/agents/<name>.md, add model: haiku or model: sonnet to agents that only search, read or summarize. Keep the top model for the main thread.

Check your own setup in one command

I packaged these checks as a Claude Code plugin. Install it:

/plugin install agent-wrapped --marketplace novastudio1shop-source/agent-wrapped

Then run /agent-wrapped:leak-check. Claude inspects your MCP servers, CLAUDE.md size, scheduled jobs, biggest sessions and subagent settings, and gives you a fix list. It's read-only.

For the actual numbers (tokens and API-price value per session, every cache rebuild, oversized context, the biggest tool results, and what was running before each time you hit the limit), open the free Agent Wrapped page. It reads your ~/.claude logs in the browser and uploads nothing. There's also a $9 version with the per-session detail and an export.

What's the biggest leak you've found in your own setup? I'm collecting them for the next version.

Independent tool, not made or endorsed by Anthropic.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.