cd /news/artificial-intelligence/how-much-does-claude-code-actually-c… · home topics artificial-intelligence article
[ARTICLE · art-57618] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

How much does Claude Code actually cost per session? I did the math

A developer tracked Claude Code and Codex pass rates for 95 days and calculated the actual cost per session. The analysis shows that a typical mid-size session with 40 model calls and a 90K token window costs about $11.40 on Sonnet at direct API rates, while heavy daily use can exceed $37. The developer also notes that prompt caching and the /compact command can reduce costs, and that flat-rate plans may be economical for light users but can lead to lockouts for heavy agentic use.

read4 min views1 publishedJul 13, 2026

Last month I tracked Claude Code and Codex pass rates for 95 days. The question I got most in response was not about quality at all. It was "what does this actually cost you?"

Fair question. Claude Code is an agentic tool, not a chat window. One request from you can trigger dozens of model calls, and every call re-sends the entire growing conversation as input tokens. Input volume, not output, drives the bill. Output is usually a rounding error.

So I sat down and did the session math properly. Here it is.

Two mechanics soften this. Prompt caching bills cache reads at about a tenth of the normal input rate, and /compact

summarizes history to shrink the window. Both help a lot. Neither changes the fundamental rule: everything sitting in the window is paid for on every call that includes it.

This is why the same prompt costs wildly different amounts in different repos. A question in a fresh session with a lean CLAUDE.md is cheap. The same question 30 turns deep, after a dozen large file reads, rides on top of a six-figure token window.

Model it turn by turn instead of guessing. A typical mid-size session runs about 40 model calls. Once a few files and some test output have accumulated, the full window averages around 90K tokens per call. Forty calls at 90K is 3.6M input tokens. Output stays small, about 40K tokens total.

At Anthropic direct list rates, before caching discounts:

Session profile Input tokens Output tokens Sonnet 4.6 ($3/$15) Opus 4.7 ($5/$25)
Light (10 calls, small repo) ~0.6M ~12K $1.98 $3.30
Typical (40 calls, medium repo) ~3.6M ~40K $11.40 $19.00
Heavy day (3 long sessions) ~12M ~120K $37.80 $63.00

Treat these as ceilings. Prompt caching discounts the repeated prefix heavily, so cached sessions usually land lower. But the shape matches what people report: occasional afternoons cost a few dollars, and running Opus as a daily driver on the API can clear several hundred dollars a month.

Anthropic sells Claude Code two ways: flat-rate plans with usage caps enforced in rolling windows, or metered API billing with no cap.

The break-even is plain arithmetic. If your typical session costs about $11 on Sonnet at direct rates, a $20 plan pays for itself at roughly two sessions a month, provided you stay under its caps. The catch is the caps themselves. Heavy agentic use is exactly the pattern that trips rolling limits, and a flat rate stops being cheap the moment you are locked out mid-session with a failing build.

Many heavy users end up hybrid: a plan for interactive work, an API key for CI jobs and overflow.

/compact

when it drifts.The last two compound. Routing a cheap model through a discounted endpoint can turn a $10 session into well under a dollar for routine work.

Full disclosure on lever six: I operate keaiapi, an OpenAI-compatible gateway with pay-as-you-go billing and no subscription. Global models are priced 20% below official list. The routing ladder I actually use:

Model Input $/1M Output $/1M Use it for
claude-opus-4-7 $4.00 $20.00 Architecture, hard debugging
claude-sonnet-4-6 $2.40 $12.00 Default coding driver
glm-5 $0.514 $2.314 Routine edits, agentic sub-tasks
deepseek-v4-pro $0.3915 $0.783 Boilerplate, tests, commit messages

Claude Code reads ANTHROPIC_BASE_URL

on startup, so switching where tokens are billed is a config change, not a workflow change. Model IDs stay the same, tool execution stays local, and rollback is deleting one line.

// ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.keaiapi.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-keaiapi-...",
    "ANTHROPIC_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-7"
  }
}

Verify the endpoint with a one-off curl before pointing your daily driver at it:

curl https://api.keaiapi.com/v1/chat/completions \
  -H "Authorization: Bearer sk-keaiapi-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [{"role": "user", "content": "Reply with one word: ok"}],
    "max_tokens": 16
  }'

Run /cost

inside a session to see what you are actually burning. If your numbers look very different from my table, I would genuinely like to hear them: repo size, session length, and which model you run as the driver.

The full breakdown with the plan comparison table and FAQ lives here.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-much-does-claude…] indexed:0 read:4min 2026-07-13 ·