The Complete Claude Guide
← Back to topic
Chapter 04 · CLI

Context window, tokens, caching and compact

Every session has a bounded context window. Understanding what fills it, how prompt caching saves, and when to run compact directly affects answer quality and cost.

Verified against source on 2026-09-30

Video

Keep the task context useful

You will inspect context, create a short working brief and compact at a natural break. Examples are illustrative, not token measurements from a real session.

The context window includes the ongoing conversation and loaded project material. It is not the whole filesystem or a guarantee that every earlier detail remains exact. Sources checked September 30, 2026 describe automatic compaction and prompt caching as separate mechanisms.

Inspect before reading everything

Use /context in your session. Identify large files or command outputs before requesting more. Read only the relevant source region rather than dumping an entire repository or long log.

For this practice issue, identify the relevant file and function first.
Read only the portion needed to explain the button behavior.
Do not edit or print large logs. State what remains unread.

Expected output distinguishes inspected content from unknowns. A shorter answer is not proof that less input was used; inspect context indicators too.

Create a working brief before changing tasks
Summarize this task for continuation:
confirmed issue, files inspected, changes made, tests actually run,
remaining questions and actions not approved.
Separate proposed fixes from completed edits.
Do not claim a test passed unless its result was observed.

Illustrative brief:

Issue: list remains visible after one click.
Inspected: index.html and its event handler.
Changes: none yet.
Tests run: none.
Next: inspect the handler, propose a one-file fix.
Not approved: publication or new dependencies.

Check against the actual session and files. A summary can omit or misstate details; preserve important source facts in an appropriate project document, not solely conversation memory.

Compact deliberately

At a natural task break, use a focused command such as:

/compact preserve the button issue, inspected files, actual test results and remaining limits

This is a command entered inside Claude Code, not a shell command for Bash. Read the resulting context before continuing. Compaction summarizes history; it is not an undo, a test run or deletion of every stored transcript.

Root project instructions reload through the documented process. Path-scoped and nested material can have different reload behavior. If a critical instruction seems missing, inspect the instruction file and /memory rather than relying on a summary's assertion.

Understand caching without treating it as memory

Prompt caching reuses an unchanged request prefix for efficiency. It does not verify facts or grant persistent knowledge. Model/effort changes can rebuild cache; compaction replaces history and changes the conversation prefix. Pricing and behavior depend on authentication/provider and current version.

Choose model and effort sensibly near task start. Do not enable fast mode or paid extras simply to fix context overload. The smaller useful read often solves the real problem.

Graded practice

Easy: inspect context

Find the largest contributor. Success: identify a concrete source of load, not just “too many tokens”.

Intermediate: accurate brief

Write a continuation summary. Success: tested, changed and proposed states remain distinct.

Challenging: resume after compact

Compact and ask what remains. Success: verify against files before acting on the summary.

Troubleshooting

Repeated compaction: a huge input may refill context immediately; narrow the read.

Instruction lost: inspect root versus nested/path-scoped files and reload behavior.

Unexpected slower turn: cache rebuild may explain it, but does not prove a billing amount.

Old fact repeated: return to the current source. Context continuity is not freshness.

Need to undo: use the appropriate diff/checkpoint/Git route; compact does not revert files.

Mechanism animation (illustration)

Filmed demo · Video is added in the media phase

Recap

Comprehension check

What does the compact command do?

Recap

Sources and further reading

← Previous Back to topic Next →