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.
Video
Steps
- Track window usage with the built-in commands, especially in long sessions with many file reads.
- Large files, long logs and command output fill the window fast. Prefer targeted reads over pasting whole files.
- When a session grows long, run compact to compress history into a useful summary instead of losing context entirely.
- 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
- The context window is bounded and measurable
- Targeted reads save context
- Compact before sessions grow too long