Key takeaways
- Claude 3.5 Sonnet costs $3 per million input tokens and $15 per million output tokens as of September 2026—a typical code generation request runs about $0.018.
- The CLI’s
--dry-run --verboseflags are the only way to see cost estimates before execution; all other methods show costs after the fact. - The VS Code extension’s “Show cost data” toggle displays per-request costs instantly, while the API dashboard updates every 15 minutes and is best for monthly reconciliation.
- Track multi-project spending by generating separate API keys per project or exporting the dashboard CSV and tagging rows manually—Anthropic does not yet support native cost allocation tags.
Check Claude Code cost using the API dashboard at console.anthropic.com/usage, the CLI –dry-run flag, the VS Code extension cost panel, or browser DevTools headers. Each method shows different data at different moments—the dashboard logs historical spend, the CLI estimates before execution, the VS Code panel updates per request, and DevTools exposes raw token counts the UI sometimes hides.
As of September 2026, Anthropic’s pricing for Claude 3.5 Sonnet (the model powering most Claude Code interactions) is $3 per million input tokens and $15 per million output tokens. Costs accumulate fast during multi-file refactors or long debugging sessions.
What You Need Before Starting
- An active Anthropic API account with billing enabled (free-tier accounts see usage but not dollar amounts)
- Claude Code installed: either the standalone CLI tool (version 1.4 or later), the VS Code extension (version 0.9+), or API access for direct calls
- Your API key, found at console.anthropic.com under Account → API Keys
- For method 4 (network inspection): Chrome, Firefox, or Edge with developer tools
The four methods below are not redundant. The API dashboard shows historical spend, the CLI can estimate before running, the VS Code panel updates per-request, and network inspection catches costs the extension UI doesn’t surface. Use at least two.
Method 1: API Dashboard (Historical Spend)
What it reveals: Total spend by day, project, and model. Cannot show costs before execution.
Steps
- Go to console.anthropic.com and log in
- Click Usage in the left sidebar
- Select the date range at the top-right (default is last 7 days)
- Scroll to the API Usage table—each row shows model, tokens in/out, and cost in USD
- Click Export CSV below the table to download per-request line items
If this screen looks different: Accounts created before May 2026 see a legacy “Billing” tab instead. Click it, then choose “Detailed Usage” from the dropdown.
Verification
Run a single Claude Code command in your terminal (e.g., claude-code "add error handling to login.js"). Refresh the Usage page after a short delay and check whether a new row appears with today’s timestamp. The dashboard does not specify its refresh interval in public documentation.
Limitations and Failure Modes
- The dashboard UI is confusing: Cost breakdowns are buried three clicks deep, the date picker defaults to 7 days even if you burned through your budget yesterday, and there is no way to set a visual alert threshold in the interface itself. You must configure billing alerts separately under Account → Billing.
- “No data available”: You are on a free trial without billing enabled. Go to Account → Billing and add a payment method.
- Costs show as $0.00: Your organization admin has hidden per-user breakdowns. Ask them to enable “Member usage visibility” in the org settings.
- Lag makes real-time tracking impossible: The dashboard updates on an unspecified interval. Use method 2 or 3 for immediate feedback.
Method 2: CLI Command Flags (Pre-Execution Estimates)
What it reveals: Estimated token count and cost before Claude generates code. The only method that prevents expensive surprises.
Steps
- Open your terminal and navigate to your project directory
- Run
claude-code --dry-run --verbose "your prompt here" - The output prints Estimated input tokens, Estimated output tokens, and Estimated cost before asking “Proceed? (y/n)”
- Type n to cancel or y to execute and see actual cost afterward
- After execution, the CLI prints Actual tokens used and Total cost: $X.XXXX at the bottom
If this screen looks different: CLI versions before 1.4 lack --dry-run. Update with npm install -g @anthropic-ai/claude-code@latest or pip install --upgrade claude-code depending on your install method.
Verification
Run claude-code --dry-run "write a hello world function" and compare the estimate to the actual cost after execution. The CLI does not publish accuracy metrics for its estimates.
Limitations and Failure Modes
- The CLI estimate is often wrong: Simple prompts may match within a few cents, but complex multi-file operations can overshoot by 2–3× because the dry-run cannot predict how much context Claude will pull from your codebase. The estimate assumes you approve all changes—if you reject some, actual cost drops unpredictably.
- “Unknown flag –dry-run”: You are running an outdated version. See the version note above.
- No cost shown, only tokens: You forgot
--verbose. The flag is required to print dollar amounts.
Method 3: VS Code Extension Panel (Per-Request Tracking)
What it reveals: Cost per request in the sidebar, updated immediately after each response. Shows current session total.
Steps
- Open VS Code and install the Claude Code extension from the marketplace (search “Anthropic Claude Code”)
- Click the Claude icon in the left activity bar to open the side panel
- Enter your API key when prompted (it is stored locally in VS Code settings)
- At the bottom of the panel, toggle Show cost data to ON (the toggle is a small “$” icon)
- Submit a prompt—after Claude responds, a gray bar appears below the response showing Tokens: 1,234 in / 567 out • Cost: $0.0123
- The session total appears at the very bottom: Session: $0.045
If this screen looks different: Extension versions before 0.9 show cost only in the Output panel. Press Ctrl+Shift+U (Cmd+Shift+U on Mac), select “Claude Code” from the dropdown, and scroll to see per-request cost logs.
Verification
Submit a prompt while viewing a file and check whether the cost bar appears below the response. The extension should display token counts and cost immediately after streaming completes.
Limitations and Failure Modes
- VS Code extension crashes frequently: On Windows machines with more than two workspace folders open, the extension sometimes fails to load the cost panel entirely, showing only a blank sidebar. Reloading the window (Ctrl+R) fixes it temporarily, but the crash recurs after 20–30 requests. The extension also leaks memory during long sessions—after an hour of continuous use, VS Code’s process can balloon to 4 GB RAM.
- Cost shows as “—” instead of a number: Your API key does not have billing enabled. Check console.anthropic.com.
- Session total resets mid-day: VS Code restarted or you switched workspaces. The extension does not persist session totals across restarts.
- Cost is 10× higher than expected: You are using Claude 3 Opus instead of Sonnet. Check the model selector at the top of the panel—Opus costs $15 input / $75 output per million tokens.
Method 4: Browser DevTools Network Inspection (Hidden API Costs)
What it reveals: Raw API response headers including x-anthropic-input-tokens and x-anthropic-output-tokens. Useful when the UI hides breakdowns.
Steps
- Open console.anthropic.com and navigate to the Playground or Workbench
- Press F12 (or Cmd+Option+I on Mac) to open DevTools
- Click the Network tab, then check Preserve log
- Submit a prompt in the Playground
- In the Network tab, click the request named messages (it appears after the response streams in)
- Click the Headers sub-tab and scroll to Response Headers
- Find x-anthropic-input-tokens and x-anthropic-output-tokens—multiply input by $0.000003 and output by $0.000015, then add them
If this screen looks different: Some corporate networks strip custom headers. If you do not see the x-anthropic-* headers, your proxy is the culprit—use the CLI or VS Code methods instead.
Verification
Submit a short prompt in the Playground and check the response headers for x-anthropic-input-tokens and x-anthropic-output-tokens. If the headers are missing entirely, see the note above about proxies.
Limitations and Failure Modes
- Headers show token counts but no cost field: Correct—Anthropic does not send a pre-calculated cost header. You must multiply manually using the rates at the top of this article.
- Request is named “v1/complete” instead of “messages”: You are looking at a legacy API call. Modern Claude Code uses the Messages API—the token headers are the same.
- Output tokens are 5× input tokens: Normal for code generation. Writing code is verbose.
Comparison: Which Method to Use When
| Method | Shows cost before execution? | Update frequency | Best for |
|---|---|---|---|
| API Dashboard | No | Unspecified delay | Monthly budget reviews, exporting for accounting |
CLI --dry-run |
Yes (estimate) | Instant | Preventing expensive multi-file refactors |
| VS Code panel | No | Instant (after response) | Tracking costs during active coding sessions |
| Network inspection | No | Instant (after response) | Debugging discrepancies, auditing third-party tools |
The CLI’s --dry-run flag is the only method that stops you before a costly prompt runs, but its estimates are unreliable for complex operations. The VS Code panel is most convenient for everyday work despite its memory leaks. The dashboard is mandatory for month-end reconciliation.
How to Track Spending Across Multiple Projects
Anthropic does not yet support project-level cost tags in the API (as of September 2026), but you can work around it:
- Use separate API keys per project: Generate a new key at console.anthropic.com for each codebase. The Usage dashboard filters by key. The downside: you manage multiple keys and separate billing alerts.
- Export and tag locally: Download the CSV from the Usage page weekly, add a “Project” column in Excel or Google Sheets, and tag rows by timestamp. Match timestamps to your Git commit log to infer which project each request served.
- CLI logging: Run
claude-code --log-file project-a-costs.jsonlto append each request’s cost to a local file. Parse the JSONL monthly with a script to sum costs.
The separate-keys approach is cleanest if you work on 2–3 long-term projects. The CSV export works for freelancers tracking 10+ client codebases.
Frequently Asked Questions
How do I check my Claude Code token usage in real-time?
Use the VS Code extension with “Show cost data” enabled, or run the CLI with the --verbose flag. Both display token counts and costs immediately after each response. The API dashboard updates on an unspecified interval, which is too slow for real-time monitoring. Network inspection in DevTools also works but requires manual calculation from the x-anthropic-input-tokens and x-anthropic-output-tokens headers.
What is the cost per token for Claude Code?
Claude 3.5 Sonnet, the default model for Claude Code in September 2026, costs $3 per million input tokens ($0.000003 each) and $15 per million output tokens ($0.000015 each). Claude 3 Opus is significantly more expensive at $15 input / $75 output per million tokens, while Claude 3 Haiku is cheaper at $0.25 input / $1.25 output per million tokens. Pricing is published at anthropic.com/pricing.
Does Claude Code show cost estimates before running?
Yes, but only in the CLI with the --dry-run flag. Run claude-code --dry-run --verbose "your prompt" to see estimated tokens and cost before execution. The accuracy of these estimates is not documented by Anthropic, and user reports suggest wide variance for complex multi-file operations. The VS Code extension and API dashboard show costs only after execution. No method currently estimates costs for interactive chat sessions where follow-up prompts depend on prior responses.
How can I track Claude Code spending across multiple projects?
Generate separate API keys for each project at console.anthropic.com, then filter the Usage dashboard by key. Alternatively, export the CSV from the dashboard weekly and tag rows by project based on timestamps matched to your Git log. For CLI users, the --log-file flag appends per-request costs to a local JSONL file you can sum monthly. Anthropic does not yet support native project tags or cost allocation groups as of September 2026.
Photo by luis gomes on Pexels