Skip to content

How Claude Code Counts Tokens: A Complete Guide

Problem

When I ran /init in Claude Code, I saw this:

Claude Code output
Token usage: 5,000 tokens
Context window: 96% used

I had just started. Why was 96% of my context already used?

I checked the Reddit thread and found:

“When I was installing Claude code, it appeared that when I run /init it used like 5k tokens, and a message appear saying that I already used 96% of my usage”

“I just used the chat for 5 prompts, 3 of them were to install Claude code”

I needed to understand where all these tokens were going.

Environment

  • Claude Code CLI (latest)
  • Claude Pro subscription
  • macOS Sequoia
  • Python project (~50 files)

What happened?

I launched Claude Code and ran the initialization:

Terminal
$ claude
> /init

The output surprised me. Before I even asked a question, my context was nearly full.

I ran /context to see the breakdown:

Context breakdown
System prompts: 35%
System tools: 28%
MCP tools: 12%
Memory files: 5%
Conversation: 4%

My actual message was only 4% of the context. The rest was overhead.

How to solve it?

Understand What Consumes Tokens

When you send a message in Claude Code, your token usage includes:

Token consumption breakdown
1. System Prompt: ~5,000-15,000 tokens
2. Tool Definitions: ~2,000-10,000 tokens
3. MCP Server Tools: varies by configuration
4. CLAUDE.md: ~500-5,000 tokens
5. Conversation History: grows with use
6. Your Actual Message: typically small

The context window percentage is calculated as:

Calculation
input_tokens + cache_creation_input_tokens + cache_read_input_tokens

This does NOT include output tokens (tracked separately).

Why /init Uses So Many Tokens

The /init command:

  1. Scans your project structure
  2. Reads key files to understand the codebase
  3. Generates a CLAUDE.md file with project context
  4. All of this adds to the context immediately

Leverage Prompt Caching

Claude Code uses prompt caching to reduce costs:

Cache cost comparison
Base input tokens: 1x ($3/MTok for Sonnet)
Cache write: 1.25x ($3.75/MTok)
Cache read: 0.1x ($0.30/MTok) <-- 90% cheaper!

After the initial load, cached content costs 90% less on subsequent requests.

Monitor Context with Built-in Commands

Claude Code commands
# View current token usage
/cost
# See detailed context breakdown
/context
# Clear context when switching tasks
/clear
# Compact with specific focus
/compact Focus on code samples and API usage

Configure Status Line for Real-Time Monitoring

Add to your settings:

settings.json
{
"statusLine": {
"command": "echo '{\"context_window\":{\"used_percentage\":'$PCT'}}'"
}
}

Reduce MCP Server Overhead

Check MCP tools
/mcp

Each MCP server adds persistent tool definitions. Disable unused servers to reduce baseline token overhead.

Keep CLAUDE.md Concise

CLAUDE.md best practice
Good: 100-300 lines, focused instructions
Bad: 1000+ lines, everything including the kitchen sink

Move specialized instructions to separate skill files.

The reason

I think the key reason for high token consumption is that Claude Code is an autonomous agent, not a simple chat interface.

The extensive context (system prompts, tool definitions, MCP servers) enables Claude Code to operate autonomously on your codebase. But it comes with token costs.

A Reddit user speculated:

“I am wondering if this is caused due to some prefix caching changes they made - or a recursive system prompt that takes up a lot of tokens”

The “recursive system prompt” idea is close. Each tool and capability adds definitions that consume tokens.

Common Mistakes

MistakeImpactSolution
Not using /clear between tasksStale context wastes tokensClear when switching focus
Running many MCP serversTool definitions bloat contextDisable unused servers
Large CLAUDE.md filesBaseline token overheadKeep under 500 lines
Vague promptsBroad file scanningBe specific about files/functions

Summary

In this post, I showed how Claude Code counts tokens. The key point is that system prompts, tool definitions, and MCP servers all consume context before you even type a message.

Key takeaways:

  1. Prompt caching reduces costs by up to 90% for repeated content
  2. Use /cost and /context to monitor where tokens are going
  3. Clear context between unrelated tasks
  4. Keep CLAUDE.md concise and focused
  5. Disable unused MCP servers

For developers transitioning from web chat to Claude Code, the initial token consumption can be surprising. But understanding the architecture helps you work efficiently.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments