---
title: "Claude Code Token Cost: How to Estimate Your Monthly Spend"
description: "Coding agent tokens mostly go to resent context. Use a formula built on sessions, requests, cache hit rate and prices, and measure real usage with ccusage."
url: https://cdnping.org/en/blog/ai-coding-agent-token-cost-estimate
language: en
published: 2026-10-31
category: "Developer tools"
tags: ["Claude Code","Codex","token cost","prompt caching","ccusage"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# Claude Code Token Cost: How to Estimate Your Monthly Spend

Most of Claude Code's token consumption doesn't come from the few sentences you type, or from the code the model writes. It comes from the context that gets re-sent with every request: the system prompt, tool definitions, files already read, and earlier conversation. So to estimate a monthly bill, first work out how many requests you send per day, how much context each request carries, and how much of that hits the cache, then multiply by the unit price. Other people's "I spent $X this month" numbers are hard to reuse, because each of these quantities varies enormously from person to person.

Below you'll find an estimation method you can plug your own numbers into, an example calculation table with its assumptions labeled, and steps for measuring real usage from local logs. Other coding agents such as Codex and OpenCode have a similar billing structure to Claude Code, so the method applies to them too.

## Where do a coding agent's tokens go?

Unlike a web chat, a coding agent sends many API requests in a row during a single task: one to read a file, one to run a command, another to edit code after seeing the result. Every request is complete on its own. The model doesn't remember what it said last time, so the client has to send the history again.

The input of one request roughly consists of four parts:

| Component | Contents | Characteristics |
|---|---|---|
| Fixed prefix | System prompt, tool definitions, project instruction files (such as CLAUDE.md), MCP tool descriptions | Sent with every request, essentially unchanged within a session, good for caching |
| Accumulated context | Earlier conversation, contents of files already read, command output | Grows with each turn; the longer the session, the bigger it gets |
| New this turn | Your instruction for this turn, tool results just received | Usually small, but a `cat` of a large file or a long log can make it jump |
| Output | The model's reply, code to be written, tool-call arguments; reasoning models also produce thinking tokens | Unit price is usually 3 to 5 times that of input |

Two conclusions follow. First, for the same task, the longer you drag a session out, the more expensive every later turn gets, because everything before it is re-sent. Second, prompt caching sets the order of magnitude of the bill: if the fixed prefix and the accumulated context hit the cache, they are billed at the cache-read price, which is much cheaper than regular input. For the write, hit and expiry rules of the cache, see [how prompt caching is billed](/en/blog/prompt-caching-pricing-explained); for concrete usage on the Claude API, see [how to use Claude API prompt caching to save money](/en/blog/claude-prompt-caching-save-cost).

If you use a reasoning model, the thinking process is also billed as output. You may not see it in the UI, so the bill can be higher than the visible replies suggest. See [how thinking tokens are billed](/en/blog/reasoning-tokens-billing).

## How do you estimate your own monthly token cost?

Break the monthly cost into the variables below. Each one can be derived from your habits or from your logs:

- `S`: sessions per day (starting an agent to do one thing counts as one session)
- `R`: requests per session (not the number of times you speak; every model call the agent makes counts as one)
- `I`: average input tokens per request (including the fixed prefix and accumulated context)
- `O`: average output tokens per request
- `h`: cache hit rate (the share of input billed at the cache-read price)
- `D`: days of use per month
- `P_in / P_cache / P_out`: unit prices for regular input, cache reads and output

The formula:

```
Monthly requests   N = S × R × D
Monthly input          = N × I
  of which cache reads = N × I × h
  of which regular input = N × I × (1 − h)
Monthly output         = N × O

Monthly cost ≈ regular input × P_in + cache reads × P_cache + output × P_out
```

This leaves out the cost of cache writes. Some providers (Anthropic, for example) bill cache writes at a higher price than regular input, and that portion grows noticeably if you start new sessions often or if the gap between two requests exceeds the cache lifetime. You can ignore it for the first estimate and see how far off you are when you check against real logs.

### Where do you get unit prices?

Prices vary by model and channel. Check the official price pages, or cdnping's [model monitoring](/en/models). For reference: in a snapshot cdnping took from OpenRouter's public model catalog on 2026-10-17, the 16 key models it tracks had input prices of roughly $0.1 to $4 per million tokens and output prices of roughly $0.47 to $12 per million tokens, a spread of several dozen times between the highest and lowest. The cache-read discount relative to input differs by vendor, so look up the relevant price page before filling in the formula. Prices change; the [site changes log](/en/changes) records additions and removals on each vendor's price page line by line, and you can subscribe to its RSS feed. For a more complete tracking method, see [how to find out right away when LLM API prices change](/en/blog/track-llm-price-and-model-changes).

## An example calculation table (all assumptions)

All numbers below are set purely to demonstrate the formula. They don't represent anyone's real usage or any specific model.

Assumed usage habits:

| Variable | Assumed value |
|---|---|
| Sessions per day S | 6 |
| Requests per session R | 30 |
| Days of use per month D | 22 |
| Average input per request I | 60,000 tokens |
| Average output per request O | 1,000 tokens |
| Cache hit rate h | 90% |
| Cache-read unit price | Assumed to be 10% of the regular input price |

Resulting monthly usage:

| Item | Calculation | Result |
|---|---|---|
| Monthly requests | 6 × 30 × 22 | 3,960 |
| Total monthly input | 3,960 × 60,000 | 237.6 million tokens |
| of which cache reads | × 90% | 213.84 million tokens |
| of which regular input | × 10% | 23.76 million tokens |
| Total monthly output | 3,960 × 1,000 | 3.96 million tokens |

Plugging in three price tiers (taken from the range in the OpenRouter snapshot above, in US dollars per million tokens):

| Price tier (input / output) | Regular input | Cache reads | Output | Total |
|---|---|---|---|---|
| Low tier 0.15 / 0.6 | 3.56 | 3.21 | 2.38 | about $9.15 |
| Middle tier 2 / 10 | 47.52 | 42.77 | 39.60 | about $129.89 |
| High tier 4 / 12 | 95.04 | 85.54 | 47.52 | about $228.10 |

At the same middle tier, if the cache never hits (h = 0), the input cost becomes 237.6 million × 2 = $475.2, and with output the total is about $514.8, roughly four times the cost at a 90% hit rate.

A few things you can read from this table:

1. Input volume is 60 times output volume, but thanks to caching, input cost doesn't spiral out of control. For a coding agent, the cache hit rate deserves more attention than the output price.
2. Under these assumptions, the monthly cost of the low and high tiers differs by more than twenty times, a bigger gap than the one caused by the hit rate dropping from 90% to 0. Not every routine small change needs the most expensive model. For splitting work by task, see [how to do multi-model routing](/en/blog/multi-model-routing-save-cost).
3. I is the variable you are most likely to misjudge. If you let the agent read files freely in a large repository, the average input can be far above 60,000; short sessions with only small edits will be much lower. That is why the next step is to calibrate against real logs.

## How do you measure your real usage?

The estimation formula is only a starting point. Claude Code writes a record of each session locally, so you can directly compute real input, output, and cache read and write tokens.

### Use ccusage to measure Claude Code

ccusage is an open-source command-line tool. It reads Claude Code's session logs on your machine (by default, JSONL files under `~/.claude/projects/`) and summarizes tokens by day, month and session. It doesn't upload any data and doesn't need an API key.

1. Make sure Node.js is installed, then run it directly, with no global install needed:

   ```bash
   npx ccusage@latest daily
   ```

2. See the monthly and per-session summaries:

   ```bash
   npx ccusage@latest monthly
   npx ccusage@latest session
   ```

3. The output has separate columns for Input, Output, Cache Create and Cache Read. Take the last 1 to 2 weeks of data and compute:
   - Cache hit rate h ≈ Cache Read ÷ (Input + Cache Create + Cache Read)
   - Total daily input and output, multiplied by days of use per month

4. Plug these numbers back into the formula above, using the unit prices of the model you actually use.

For the full options of each subcommand, refer to the ccusage project's README; options may change as versions update. The ccusage project also offers a version that reads Codex's local logs; see the README for usage.

### Built-in ways to check inside Claude Code

- Type `/cost` in a session to see the current session's token usage and the cost converted at API prices (when you are billed via an API key).
- When a session gets very long, use `/compact` to compress the history, or run `/clear` to start a fresh session after finishing one thing. Either directly lowers I for every later turn. The trade-off is that the first few requests of the new session have to write the cache again.

### Check against your bill

If you call the API pay-as-you-go, the provider's bill is the final word. It is common for local statistics and the bill not to match; causes can include differences in how tokens are counted, cache writes, and retried requests. For how to reconcile, see [why your AI API bill doesn't match](/en/blog/relay-billing-token-mismatch) and [how token billing works](/en/blog/llm-token-billing-explained).

## A checklist for reducing token consumption

If the estimate looks too expensive, go through the items below. Each one shows up in the logs:

- [ ] Keep project instruction files (CLAUDE.md and the like) to what is necessary; they are sent with every request
- [ ] Turn off MCP servers you don't use; every tool description takes up part of the fixed prefix
- [ ] Do one thing per session and start a new session when done, so context doesn't pile up without limit
- [ ] Avoid letting the agent read an entire large file or a full build log in one go; narrow it down with grep or head first
- [ ] Don't leave long gaps between requests; going past the cache lifetime means the cache gets written again
- [ ] Switch simple tasks (renames, formatting, adding comments) to a cheaper model
- [ ] Run `ccusage daily` once a week and watch for an abnormal drop in the cache hit rate

## Pay-as-you-go API or monthly subscription?

The core difference between the two is who absorbs the swings in usage.

| | Pay-as-you-go API | Monthly subscription |
|---|---|---|
| Billing | Actual tokens × unit price | Fixed monthly fee with a built-in allowance |
| Good for | Low or highly variable usage, or when you need exact accounting | Steady usage and a predictable budget |
| Watch out for | Daily cost swings with workload; a large-repo refactor can noticeably raise that day's cost | The rules once the allowance runs out; how the allowance unit converts to tokens |
| Estimation method | Use the formula above directly | Compute monthly usage with the formula, then compare it with the plan allowance |

If the method above shows your monthly spend is fairly steady, the benefit of a subscription is that you don't have to watch the bill every day. If you barely use it for some months and then use it heavily in bursts, pay-as-you-go fits better.

Take AGI Plan as an example (AGI Plan is a commercial partner of cdnping; AGI Plan is a multi-provider aggregation gateway, and the site states it is not an officially authorized channel). It offers both. Its metering unit is the CU, where 1 CU equals 1,000 output tokens of the baseline model. The plans are Lite ¥49/month, Plus ¥119/month, Pro ¥649/month and Max ¥1,368/month, and the four tiers differ only in allowance. Pay-as-you-go is ¥1 = 500 CU, with a minimum top-up of ¥20. It is compatible with both the Anthropic and OpenAI API formats, so Claude Code and Codex can connect by changing a single endpoint URL. For configuration, see [configuring a custom API endpoint for Claude Code, Codex and OpenCode](/en/blog/configure-custom-api-endpoint-claude-code-codex).

The CU is defined by the baseline model's output tokens. How input, cache reads and models in different capability groups convert to CU should follow the explanation on the [agiplan.dev/pricing](https://agiplan.dev/pricing) page; you can't just divide the total token count computed above by 1,000. The safer approach is to run a week or two of real tasks on the minimum pay-as-you-go top-up, compare ccusage's data with the CU actually deducted, work out your own conversion ratio, and only then decide which plan to buy.

## Measure for a week, then set the budget

1. Use `npx ccusage@latest daily` to get the last week's real input, output and cache data.
2. Work out the cache hit rate and the daily average usage, plug them into the formula, and use the unit prices of the models you use.
3. If the result is high, check the cache hit rate and average input first, and only then consider switching models.
4. Consider a subscription only once usage is steady, and convert the allowance according to the provider's published rules.

If you run into Claude Code failing to connect or running slowly on top of the estimate, first check [is Claude Code down](/en/down/claude-code) to see whether the service itself has a problem, and only then look at your own network.
