Claude Code in Practice / How Claude Code works

Context, compaction and usage

Lesson 5 of 34. Open to read. No account needed.

In The agentic loop you saw that Claude's whole context is sent on every step. This lesson makes that visible in your own sessions. You will see what fills the context before you type anything, how a task adds to it, what /clear and /compact do about it, and what a session costs your plan or your API account.

By the end you can:

  • read /context and say what occupies the context window;
  • read /usage and say whether its figures are a bill, an estimate or plan limits for your account;
  • choose between /clear and /compact, and explain what survives compaction;
  • recognise the usage limits, extra-cost options and warnings Claude Code shows.

Before you start

  • The agentic loop is complete.
  • Work in the practice repository's root folder, with the course's Python environment active.

What fills the context before you type

Start a session and run /context before sending anything. It shows the context window as a grid of squares and lists what fills it. In the author's session (illustrative; Claude Code 2.1.308, Opus 5.5 on a Max plan):

29.8k/1m tokens (3%)                        <- used / window size

Estimated usage by category
System prompt: 2.9k tokens (0.3%)          <- Claude Code's instructions to Claude
System tools: 19.4k tokens (1.9%)          <- definitions of Read, Edit, Bash and the rest
MCP tools: 635 tokens (0.1%)               <- tools from connected MCP servers
MCP server instructions: 717 tokens (0.1%)
Skills: 6.2k tokens (0.6%)                 <- one-line descriptions of available skills
Messages: 10 tokens (0.0%)                 <- the conversation so far
Free space: 937.2k (93.7%)
Autocompact buffer: 33k tokens (3.3%)      <- room kept free for automatic compaction

Read it from the top:

  • Used and window size. About 30,000 tokens are in use before any conversation. The window size depends on the model: this one has a 1-million-token window.
  • System prompt and system tools are the largest fixed costs. The tool definitions alone are larger than most source files.
  • MCP tools and skills come from things you or your organisation have connected or installed. Subscribers may also see tools from claude.ai connectors here. Your numbers will differ.
  • Messages is the conversation. It starts near zero and grows with every request, answer and tool result.
  • Autocompact buffer is space Claude Code keeps free so that it can summarise the conversation before the window fills.

/context all expands the list. Running /context sends nothing to Claude and costs nothing.

What a session costs: /usage

/usage opens a panel (also reachable as /cost or /stats). Two parts matter here:

Session
Total cost:            $0.0000            <- an estimate, computed on your computer
Usage:                 0 input, 0 output, 0 cache read, 0 cache write

Current session                10% used    <- subscription plans only
Current week (all models)      95% used
Resets Oct 25, 10:59pm (UTC)

(Illustrative, from the same session; after /status, /context and /usage, the session cost is still $0.0000, because none of them sends a prompt.)

  • Session shows the tokens this session used and a cost computed locally from list prices. On an API account it estimates what you will be billed; the Claude Console's usage page is the authority. On a subscription, usage is included in your plan, so this figure does not affect what you pay.
  • Plan usage bars (Pro, Max, Team and Enterprise) show how much of your current session window and your weekly allowance you have used, and when each resets. These are what stop you working: when one reaches 100%, Claude Code tells you and shows the reset time.
  • The panel may also show which skills, subagents and MCP servers contributed most to recent usage, with suggestions. Those figures are approximate and cover only sessions on this computer.

Two extra-cost options to know about:

  • Usage credits let a subscription keep working past its limit, charged separately. They are off unless you turn them on with /usage-credits.
  • Some models cost extra. Requests to Anthropic's Fable model can bill usage credits; in an interactive session Claude Code asks for your consent first. Decline unless you mean to pay for it.

A spending cap for scripted runs, --max-budget-usd, appears in the scripted-runs module. It is checked after each response, so one response can take you past it.

What a task adds

When Claude reads files and runs commands, their output joins the Messages category and stays there. The author ran this lesson's exercise twice in interactive sessions (illustrative; Claude Code 2.1.308, sonnet alias, Max plan):

MomentContext usedMessagesSession cost (/usage)
Before the question29.9k10 tokens$0.0000
After one read-only question (run 1)45.4k15.5k tokens$0.0959
After one read-only question (run 2)46.3k16.4k tokens$0.0979
After /clear30k130 tokens(unchanged: /clear sends nothing)

Three stacked bars: about 30,000 tokens of system prompt, tool definitions, MCP tools and skill descriptions before any prompt; about 45,000 after one question, the growth all in messages; about 30,000 again after /clear

What fills the context window before a prompt, after one question, and after /clear (author's run 1).

Read the bars top to bottom. The four labelled parts on the left are the same in every bar: they are sent with every request before you type anything. Only Messages changes. One short question that read three small files added about 16,000 tokens to the conversation: the file contents Claude read, its tool calls and its answer. /clear removed them again. The weekly plan bar did not move visibly for either run.

Each new request in a conversation resends everything before it. A long session that has read many files makes every later step slower and more expensive, and gives Claude more to sift through, even when the old material no longer matters.

Clearing and compacting

CommandWhat it doesUse it when
/clearStarts a new conversation with empty Messages. The previous one is kept and can be reopened with /resume. /clear <name> labels it.You are switching to unrelated work
/compactReplaces the conversation so far with a summary, and continues the same conversationYou are mid-task and the context is getting full
/compact <instructions>The same, with focus instructions for the summary, such as /compact focus on the late-fee featureYou know what must be kept
Automatic compactionClaude Code compacts by itself as the context approaches the limitHappens without you; /autocompact changes when

What survives compaction

A summary is shorter than the conversation, so details can be lost. Claude Code reloads some things from disk after compacting:

  • the system prompt, and the project's instruction files at the repository root (a later module);
  • up to five files Claude read or edited, most recently changed first;
  • the plan written in plan mode (the next module).

What it does not keep word for word is anything you only said in the conversation. If you told Claude "don't push until I've reviewed it", that instruction can disappear in the summary. Boundaries that must hold belong in settings, as permission rules, which Permission rules teaches: a deny or ask rule applies whatever the conversation says.

Measure context and usage

Goal: see your own context and usage before and after a small task, then refocus the session.

1. Start and take a baseline

In the practice repository's root folder:

claude --permission-mode default

Run, one at a time, and note the figures:

/context

Note the total used and the Messages figure. Press Esc to close panels when you are done reading them.

/usage

Note the Session line and, on a subscription, the plan bars.

2. Do a small task

Ask the question from the previous lesson again:

Explain how `PYTHONPATH=src python3 -m tidewell quote cargo 2` works out the price it prints: name each file and function involved, in the order they run. Read the code to answer; do not change any files.

Decline any request to change files or to run the quote command.

3. Measure again

Run /context and /usage again. Compare:

  • Messages has grown by roughly the size of the files Claude read plus the answer;
  • Session shows input, output and cache tokens and a cost estimate above zero;
  • the plan bars, if you have them, may have moved by a small amount.

4. Refocus the session

Run:

/clear

Then /context once more. Messages is back near zero; the fixed categories are unchanged. The earlier conversation is not deleted: /resume lists it. Leave with /exit.

What success shows

  • You recorded used tokens and Messages before and after the task, and the difference is explained by what Claude read and wrote;
  • you can say, for your account type, whether the /usage cost is an estimate of your bill or only informational;
  • after /clear, Messages returned to near zero;
  • git status --short prints nothing.

Your numbers will differ from the author's: the model, your plan, installed skills and connected servers all change them.

When your result differs

What you seeWhat it meansSafe next step
/context shows many MCP tools or skills you did not addConnectors or plugins from your account or organisationNothing to fix for this course; note them, as they use context in every session
/usage shows no plan barsYou use an API (Console) accountThe Session cost is your estimate; check the Console's usage page for the bill
"You've hit your session limit" or "your weekly limit"A plan limit, shared across modelsWait for the reset time shown; switching models does not help
"You've hit your Opus limit" (or another model's)A limit on that model family onlySwitch to another model with /model, or wait
A context or auto-compact warningThe conversation is close to the windowNot a usage limit: /compact or /clear
A prompt asking to use usage credits or an extra-cost modelContinuing would cost extraDecline unless you intend to pay

Your turn

Classify each illustrative message, and say what you would do:

  1. "You've hit your weekly limit · resets Oct 25"
  2. A warning that the conversation is close to the auto-compact window
  3. "You've hit your Sonnet limit"
  4. A prompt asking whether to continue on Fable using usage credits

Solution

  1. A plan usage limit shared across all models: wait for the reset, or turn on usage credits if you choose to pay. Switching model does not help.
  2. Not a usage limit: the context is nearly full. Use /compact (with a focus if you know what matters) or /clear if you are changing task.
  3. A model-family limit: switch to another family with /model, or wait.
  4. An extra-cost choice: decline unless you intend to pay for that model; Claude Code then continues on your default model.

Reset and cleanup

Nothing to clean up: the task changed no files. Old conversations are kept locally under ~/.claude/projects/ for 30 days by default.

Check your understanding

  1. Before you type anything, about 30,000 tokens are in use. Where do they come from?
  2. You are halfway through a feature and the context is filling up. Do you use /clear or /compact, and why?
  3. You told Claude early in a long session not to edit tests/. Why might it later forget, and what is the durable fix?
  4. On a Max plan, /usage shows a session cost of $2.40. Will you be billed $2.40?

Answers

  1. Claude Code's system prompt and tool definitions, plus descriptions of available skills and MCP tools. They are sent with every request.
  2. /compact, ideally with a focus: it keeps a summary of the work so far. /clear would start over with no memory of the feature.
  3. Compaction summarises the conversation, and a conversation-only instruction can be lost. A deny rule in settings holds regardless.
  4. No. On a subscription, usage is included in the plan; the figure is a local estimate at list prices. What limits you is the plan usage bars.

29 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy