Related ToolsClaude CodeClaude

$40 on One Claude Code Session: Where the Money Actually Goes

Claude by Anthropic
Image: Anthropic

$40. That's what some developers are reporting as the cost of a single Claude Code session for what seemed like a minor fix.

If that sounds absurd, it's because Claude Code is billed per token, not per session or per month. Tokens are the chunks of text the model reads and writes - roughly 750 words per 1,000 tokens. A "small task" that involves Claude Code reading your entire codebase, running multiple iterations, and backtracking through errors can burn through hundreds of thousands of tokens before you've seen a working solution.

How a Minor Fix Becomes an Expensive Loop

The most common culprit is context bloat. By default, Claude Code reads the files it thinks are relevant - but if you're working in a large project with a hefty node_modules folder, generated files, or build artifacts sitting in your working directory, the model may read thousands of lines it doesn't need. Every token it reads gets billed.

The second culprit is iteration without limits. Claude Code can autonomously run tools, execute code, read errors, and try again - repeatedly. Without a cap on how many turns it takes, a task that goes sideways can spiral. A bug fix that triggers a test failure that triggers a code change that triggers another test failure can loop six or eight times before Claude gives up or succeeds. Each loop costs tokens.

What Actually Keeps Sessions Cheap

A few specific settings help:

  • .claudeignore: Works like .gitignore but tells Claude Code which files it's not allowed to read. Exclude node_modules/, build folders, lock files, and large generated files. This alone can cut context by 80% on typical web projects.
  • --max-turns: A flag that hard-caps how many autonomous steps the agent takes before stopping and asking for input. Setting it to 5-10 for routine tasks prevents runaway loops.
  • Scope down the starting context: Instead of pointing Claude Code at the whole project, open only the file or folder containing the problem. Less visible context means fewer tokens read and a lower bill.
  • Watch the token counter mid-session: Claude Code logs token counts. If a session is already at 50,000 tokens and hasn't solved the problem, stop and reconsider the approach rather than letting it continue.

The core issue is that Claude Code is an autonomous agent, and autonomous agents are expensive when they're confused or working with too much irrelevant context. A $40 session isn't a billing bug - it's almost always a sign the agent needed tighter constraints or a clearer starting point.

For most well-scoped tasks, a Claude Code session should land under $3-5. The jump to $40 nearly always means the agent read a huge codebase, looped many times, or both.