RC RANDOM CHAOS

The Same Code Fix Can Cost Wildly Different Token Bills — Here's Why

· via Hacker News

Original source

Maximizing the value of your Claude Code sessions

Hacker News →

Agentic coding tools flip a long-standing assumption: your editor used to cost the same whether you fixed one test or fifty, but with Claude Code each task carries its own price, and identical work can cost very different amounts depending on how the session is run. A tight session reads only the two files it needs and finishes in a few turns; a sloppy one greps around, opens a dozen files, and drags all of that accumulated context into every subsequent request. Efficiency isn’t about spending fewer tokens overall — it’s about making sure the tokens you spend go toward the task instead of re-processing irrelevant history.

What you actually pay for is GPU inference time, and three factors set the rate. Model size multiplies everything. Output tokens cost roughly 5x input because they’re generated one at a time during the decode phase, while input is read in bulk during prefill — and a large share of output is the model’s thinking, which the effort level controls. The third factor is prompt caching: because requests always go out in the same order (tool definitions, system prompt, then conversation with CLAUDE.md at the front), an unchanged prefix can be reloaded from cache at 0.1x the input price. Cache writes cost up to 2x, but that happens once while the cheap reads repay it on every later turn.

The catch is that caching only works if the front of the request stays identical. Switching models or effort levels mid-conversation is keyed separately and forces the entire history to be re-prefilled at full price — an avoidable cost spike. The practical playbook follows directly: run /clear between tasks, lock in your model and effort before starting, @-mention files to skip Read calls, quiet or sandbox noisy commands so their output doesn’t linger, check /context in a fresh session to trim unnecessary CLAUDE.md and MCP definitions, and /compact before stepping away while the cache is still warm.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.