HeadlinesBriefing favicon HeadlinesBriefing.com

Claude Code Session Cost Optimization

Hacker News •
×

Understanding Claude Code's token usage is key to maximizing value. Requests involve input tokens (your prompt, context, files) and output tokens (model's thinking, tool calls, text). Output tokens are priced higher due to longer GPU processing. The `/effort` command controls thinking tokens and sets a default for future sessions; use `/model` and `/effort` at the start to confirm settings.

Prompt caching significantly reduces costs. When a request shares an initial sequence of tokens with a previous one, the server reuses cached state, costing only 0.1x input price for reads. Writes to the cache cost up to 2x. Breaking the cache occurs when parameters like `/model`, `/effort`, fast mode, or `/compact` are changed mid-conversation, or after an hour of inactivity (or five minutes for API keys). Rewinding is cheaper than compacting as it preserves cache history.

Everything in the conversation context, including tool results and read files, is re-sent on each turn, incurring cheap cache reads. The total cost depends on context size, duration, and concurrent sessions. Keep `CLAUDE.md` concise and move workflow specifics to skills. Avoid unnecessary file reads by being precise; instead of "fix the failing test", specify "fix the failing test in utils.test.ts". Running `/context` shows initial context, and disabling unneeded MCP servers can save costs.