What Are Tokens in Claude Code? (And Why They Matter)

You’re in the middle of a complex task with Claude Code — it’s been reading files, writing code, making progress — and then suddenly it seems to lose track of earlier decisions. Or it tells you the context window is getting full. What just happened? The answer is tokens. Understanding them won’t make you a better coder, but it will make you a dramatically better Claude Code user.

This is part of our complete How Claude Code Works — A Beginner’s Deep Dive.


TL;DR

  • A token is roughly 3-4 characters of text — the unit Claude Code uses to measure information
  • Every file Claude Code reads, every message you send, and every response it gives costs tokens
  • The context window is Claude Code’s working memory — it has a token limit
  • When the context fills up, Claude Code can “forget” earlier parts of the conversation
  • You can manage tokens by starting fresh sessions, being specific in prompts, and avoiding unnecessary file reads

What Is a Token?

A token is the basic unit that AI language models use to process text. It’s not quite a word, not quite a character — it’s somewhere in between. As a rough rule:

  • 1 token ≈ 4 characters of English text
  • 1 token ≈ ¾ of a word
  • 100 tokens ≈ 75 words

So a short paragraph like this one is about 50-60 tokens. A typical JavaScript file might be 500-2,000 tokens depending on its length. A long conversation with Claude Code that includes several files being read and multiple rounds of edits can easily reach tens of thousands of tokens.

Think of tokens like the letters in a Scrabble game. You have a fixed number of tiles. Every word you play uses some up. When they’re gone, you can’t play anymore — you need a new bag.


What Is the Context Window?

The context window is Claude Code’s working memory. It’s the total amount of information Claude Code can hold and think about at one time — measured in tokens.

Here’s what lives in the context window:


# Everything that counts toward your context window
Your prompts and messages         → tokens consumed
Claude Code's responses           → tokens consumed
Files Claude Code has read        → tokens consumed
Code Claude Code has written      → tokens consumed
The conversation history          → tokens consumed
CLAUDE.md contents (if it exists) → tokens consumed

All of this adds up. Claude Code for the consumer plan uses Claude’s full-scale model with a large context window — but it’s still finite. When the context window fills up, Claude Code has to start dropping older information to make room for new information.

This is why you might notice Claude Code seeming to “forget” a decision made early in a long session. It didn’t actually forget — that information fell out of the context window.


Step 1: Check Your Token Usage

Claude Code shows you token usage information so you can see where you stand.


# Check token usage with a slash command
/status

# Example output
Mode: Normal
Tokens used this session: 45,230 / 200,000
Files read this session: 8
Messages exchanged: 23
Session started: 47 minutes ago

Claude Code terminal showing /status output with token count and context window usage

When you’re approaching the limit, Claude Code will warn you. You’ll see a message like:


# Warning message when context is getting full
⚠️  Context window is 80% full. Consider starting a new session
    or using /clear to reset the conversation context.

💡 Pro Tip: Check /status at the start of complex tasks. If you’re already at 40%+ from a previous task in the same session, start a fresh session so you have plenty of room.


Step 2: Understand What Uses the Most Tokens

Not all actions consume tokens equally. Here’s a rough sense of relative cost:

High token cost:

  • Reading large files (a 500-line file can cost 1,500-3,000 tokens)
  • Long conversation histories with many back-and-forth messages
  • Reading entire directories instead of specific files
  • Claude Code’s detailed explanations and analysis
  • Pasting large code blocks directly into your prompt

Medium token cost:

  • Reading medium-sized files (100-200 lines)
  • A few rounds of iteration on the same task
  • Claude Code writing new code (shorter files)

Low token cost:

  • Short, focused prompts
  • Simple questions with simple answers
  • @-mentions of small, targeted files
  • Slash commands like /status, /plan

# Rough token comparison — why file size matters
Small utility function (50 lines)    ≈ 500 tokens
Medium component (150 lines)         ≈ 1,500 tokens
Large page component (400 lines)     ≈ 4,000 tokens
Your entire conversation so far      ≈ varies widely

Step 3: Manage Your Tokens Effectively

You can take practical steps to stay within budget without constantly worrying about it.

Be specific with @-mentions:


# Token-efficient: mention only the file you need
@src/utils/pricing.js → reads one 100-line file → ~1,000 tokens

# Token-heavy: mentioning a whole directory
@src/utils/ → reads 12 files, 1,800 lines total → ~18,000 tokens

Avoid pasting large blocks of code into prompts:


# Instead of pasting code into your prompt (token-heavy):
"Here's the function [pastes 200 lines of code] — add error handling to this"

# Use an @-mention instead (token-efficient):
"Add error handling to the processOrder() function in @src/api/orders.js"

Keep prompts focused:

Long, rambling prompts that include background history, previous failed attempts, and unrelated context cost tokens without adding clarity. Say what you need, specifically.

Start fresh sessions for new tasks:

When you move from one task to a completely different one, start a new Claude Code session. The conversation history from the previous task isn’t helping — it’s just using up tokens.


# Starting a fresh Claude Code session
Ctrl+C    # Exit current session
claude    # Start a new one

Step 4: Use /clear When You Need to Reset Context

If you want to stay in the same session but free up context window space, you can use the /clear command:


# Clearing conversation history to free up tokens
/clear

# Output:
# Conversation history cleared.
# Token usage reset: 2,100 / 200,000
# Note: Claude Code still has access to your files —
# only the conversation history was cleared.

What /clear does: Removes the conversation history from the context window. Claude Code “forgets” what you’ve been discussing, but it can still read your files fresh.

What /clear doesn’t do: It doesn’t change your files, close the session, or remove any CLAUDE.md instructions. It just gives you a clean slate for a new task.

⚠️ Warning: After /clear, Claude Code won’t remember any decisions, constraints, or context from the earlier conversation. If you had important rules established in the conversation (like “don’t modify the auth module”), re-state them in your next prompt or add them to CLAUDE.md so they persist.


Step 5: Know When to Start a New Session vs. /clear

Both reset your token budget, but they’re different:

Use /clear when:

  • You’re moving to a new task but want to stay in the terminal
  • The new task is in the same project
  • You’ve already set up useful context through CLAUDE.md that will persist

Start a new session when:

  • You’re switching to a completely different project
  • Something feels “stuck” and you want a completely clean state
  • You want to test how Claude Code approaches a task without any prior influence

For long-running projects, a CLAUDE.md file becomes even more valuable — because no matter how many times you /clear or restart sessions, Claude Code reads CLAUDE.md fresh every time. Your important context always survives.


Tokens and Pricing: A Brief Note

If you’re using Claude Code through Anthropic’s API (rather than the consumer subscription), token usage directly affects your costs. Input tokens (what you send to Claude Code) and output tokens (what Claude Code generates) are billed separately.

For detailed pricing information, see Claude Code Pricing — Free vs Pro vs API Explained.

For subscription users, tokens affect speed and context limits rather than direct costs — but the same efficiency principles apply.


Common Mistakes and How to Fix Them

Mistake 1: Never Checking Token Usage

Problem: You use Claude Code for an hour on a complex task, the context fills up, and Claude Code starts making inconsistent decisions because it’s lost the early context.

Fix: Run /status periodically on long sessions. When you hit 70-80%, wrap up the current task and start fresh.

Mistake 2: Mentioning Entire Directories When You Only Need One File

Problem: You @-mention @src/components/ when you only need @src/components/CheckoutForm.tsx. You spend 15,000 tokens reading 20 files when you needed one.

Fix: Be specific. The more targeted your @-mentions, the more efficiently you use your context window.

Mistake 3: Long Rambling Prompts

Problem: You write a 300-word prompt with background history, previous attempts, and related context that isn’t actually relevant to what you’re asking right now.

Fix: Say what you need. Two clear sentences beat two paragraphs of background. If context is important, make it targeted — mention only what directly affects the current task.

Mistake 4: Keeping Tasks Running in the Same Session for Hours

Problem: You’ve been working in Claude Code for three hours across five different tasks. The context is full of old decisions and file contents that aren’t relevant anymore.

Fix: Treat sessions like work blocks. When you complete a major task, start a new session. It’s the equivalent of clearing your desk between projects.

Mistake 5: Not Using CLAUDE.md to Preserve Important Context

Problem: You /clear the context and then spend 10 minutes re-explaining your project conventions to Claude Code.

Fix: Anything you find yourself explaining repeatedly goes in CLAUDE.md. It survives every /clear and every new session.


Key Takeaways

  • Tokens are the unit of measurement for text — roughly 4 characters each
  • The context window is Claude Code’s working memory — it has a limit
  • Reading large files, long conversations, and pasting code all consume tokens quickly
  • Use /status to check your token usage; use /clear to reset context without ending the session
  • CLAUDE.md is your best tool for preserving important context across sessions and /clear resets

Next Steps

Return to How Claude Code Works — A Beginner’s Deep Dive for the full picture.