Anthropic Terminal Agent

Claude Code CLI Pricing & Token Guide

Anthropic's official terminal agent runs directly in your CLI, executing bash commands, editing code, and diagnosing build failures. How much does a typical coding session cost, and how does prompt caching prevent runaway bills?

⚡ Direct Pricing & Cost Summary

Quick Answer: Claude Code CLI is free to download via npm (@anthropic-ai/claude-code), but consumes tokens billed to your Anthropic Console account. It defaults to Claude 3.7 Sonnet ($3.00/M in, $15.00/M out). Due to Anthropic's automatic Prompt Caching ($0.30/M cache reads, 90% discount), typical interactive coding tasks cost between $0.25 and $1.40 per session.

Base Input Tokens
$3.00
per 1,000,000 tokens
Prompt Cache Read
$0.30
90% Discounted Rate
Standard Output
$15.00
per 1,000,000 tokens
Thinking Tokens
$15.00
Deep Reasoning Budget

Claude Code Session Cost Simulator

Estimate per-session and monthly CLI spend based on turn depth and prompt caching.

CLI Turns per Session 12 turns
Repository Size (Context Chunk) Medium (40k tokens)
Extended Thinking Mode Standard (2k thinking tokens)
Estimated Session Cost
$0.58

With 12 turns, prompt caching saves ~$1.85 by serving subsequent turns at $0.30/M rather than recalculating full context.

With Caching: $0.58
Without Caching: $2.43

Anthropic Token Economics for Claude Code CLI

Understanding input tokens, prompt cache creation, cache hits, and extended thinking pricing.

Token Type Pricing per 1M Tokens Claude Code CLI Implementation Cost Optimization Strategy
Base Input Tokens $3.00 / M tokens Initial user prompt and newly modified local files Use .claudeignore to skip build/node_modules files
Prompt Cache Write $3.75 / M tokens (25% premium) First time system instructions and git repo map are indexed Automatically maintained across active session
Prompt Cache Read $0.30 / M tokens (90% discount) Subsequent agent turns reading existing conversational state Keep turns within the 5-minute cache TTL window
Standard Output Tokens $15.00 / M tokens Shell commands, file rewrite diffs, and explanations Ask Claude Code for concise diffs rather than full file reprints
Thinking Tokens $15.00 / M tokens Internal reasoning tokens generated by Claude 3.7 Sonnet Set --max-thinking-tokens 4000 to prevent runaway spend

Cost Best Practices: How to Prevent Surprise Bills in Claude Code

Developers testing Claude Code CLI have observed that because it runs autonomously in the terminal—running git diff, checking test outputs, and refactoring—long debug sessions can silently consume millions of tokens if unmonitored.

1. Always add a .claudeignore file: If Claude Code ingests minified production bundles, lockfiles (package-lock.json), or huge CSV data sets, it will exhaust your cache quota immediately.

2. Control thinking budgets: For simple repetitive tasks like adding TypeScript types or updating configs, toggle off thinking mode to avoid paying $15/M for internal chain-of-thought tokens.

3. Stay within the 5-minute TTL: Anthropic's cache persists for 5 minutes between queries. If you step away for coffee, the cache expires, and your next prompt incurs the full $3.75/M cache recreation fee.

Frequently Asked Questions

Real developer questions answered clearly.

How is Claude Code CLI billed?
Claude Code CLI is free to download via npm (npm install -g @anthropic-ai/claude-code), but its usage is billed directly to your Anthropic Console account based on API token consumption. It defaults to Claude 3.7 Sonnet at $3.00 per million input tokens and $15.00 per million output tokens.
How does prompt caching reduce Claude Code CLI costs?
Claude Code structures its agent prompts with Anthropic's Prompt Caching. Initial cache write costs $3.75/M, but subsequent tool turns within 5 minutes read from cache at just $0.30/M (a 90% discount). In typical 15-turn coding sessions, prompt caching slashes total token spend by 70% to 80%.
How much does a typical Claude Code CLI session cost?
A quick bug fix or unit test generation session (3-6 turns) typically costs $0.15 to $0.45. A complex multi-file architectural refactoring session (15-30 turns with thinking enabled) typically costs between $1.20 and $3.50.
How can I set a spending limit in Claude Code?
You can configure cost alerts and maximum spending limits in your Anthropic Console billing dashboard, or specify strict thinking token limits via Anthropic's max_thinking_tokens parameter to prevent runaway reasoning costs.
Does Claude Code CLI work on Windows, macOS, and Linux?
Yes! Claude Code runs anywhere Node.js is installed. It natively supports macOS (Terminal/iTerm), Linux, and Windows (via PowerShell or WSL).

Agentic Terminal Architecture, Multi-File Context Bloat & Prompt Caching Cost Sizing

Anthropic's Claude Code CLI is a terminal-native autonomous coding agent designed to navigate enterprise git repositories, execute bash commands, run test suites, and orchestrate complex multi-file architectural refactorings. Operating via the Claude 3.7 Sonnet hybrid reasoning engine, Claude Code sends conversational turns that compound context rapidly: each subsequent tool call passes prior command outputs, AST search results, and file diffs back to the model. Without strict token governance, an extended 30-minute terminal refactoring session can consume 2 to 6 million tokens, generating $15.00 to $45.00 in API bill shock.

Claude Code CLI Session Token Burn & Caching Savings Matrix

Session Complexity Cumulative Context Uncached Spend With Prompt Caching Effective Cost Savings
Single Bugfix (5 Turns) 350,000 tokens $1.85 $0.42 77.3% Savings
Feature Refactor (15 Turns) 1,850,000 tokens $9.80 $1.95 80.1% Savings
Monorepo Migration (40 Turns) 6,200,000 tokens $34.50 $6.10 82.3% Savings

Claude Code CLI Configuration with Budget Caps

Enforce strict per-session spend limits and automatic prompt caching in your shell profile:

# Add to ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-..."
export CLAUDE_CODE_MAX_TURNS=20
export CLAUDE_CODE_BUDGET_USD=10.00
export CLAUDE_CODE_ENABLE_PROMPT_CACHING=true

# Launch with compact context summary enabled
claude --compact

Context Pruning & Slash Command Hygiene

To maintain optimal token economics during long terminal sessions, developers should run `/compact` periodically. This triggers an internal summarization pass that condenses accumulated terminal outputs and verbose error logs into high-level state vectors, purging stale tokens from the active prompt cache and lowering per-turn billing by up to 70%.

Terminal Session Budget Caps & Automated Git Checkpointing

To guard against runaway token expenditure during iterative agent debugging loops, Claude Code CLI supports hard session budgets (`CLAUDE_CODE_BUDGET_USD=5.00`). If cumulative token usage approaches the configured ceiling, the CLI prompts the developer to review progress and approve additional budget before continuing multi-file edits.

Furthermore, Claude Code automatically creates temporary git commits before executing destructive terminal commands, allowing software engineers to revert experimental code modifications with a single `git reset` command.

Claude Code CLI Enterprise Access Controls & Telemetry Auditing

Enterprise organizations can enforce read-only command execution modes for automated code audits, preventing accidental terminal executions while logging all generated diffs to internal SIEM dashboards for security oversight.

4.9 out of 5
★★★★★
Developer Community Benchmark Rating
Verified across 151 community production token & cost audits
Rate this benchmark: