The Complete Claude Guide
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

Steps

  1. Track window usage with the built-in commands, especially in long sessions with many file reads.
  2. Large files, long logs and command output fill the window fast. Prefer targeted reads over pasting whole files.
  3. When a session grows long, run compact to compress history into a useful summary instead of losing context entirely.
  4. Prompt caching works behind the scenes on repeated context; keeping a stable session structure improves both speed and cost.

Mechanism animation (illustration)

Common pitfall: A large context can make relevant details harder to use. Compact summarizes history and may omit detail; keep durable project decisions in files and check the summary.
Hands-on exercise: Open a session, check context usage, read a large file and check again. Run compact and record how the summary preserves the key decisions.
Filmed demo · Video is added in the media phase

Recap

Comprehension check

What does the compact command do?

Recap

Official sources

← Previous Back to contents Next →