Managing context and sessions

Claude Code · Practical · 12 min

Quality drops as the context fills; managing it is the single biggest lever on results and cost.

Everything in a session (your messages, every file Claude read, every command output, CLAUDE.md, tool descriptions) sits in the model's context window. It fills fast: one debugging session can use tens of thousands of tokens. As it fills, Claude starts losing track of early instructions and makes more mistakes.

Tools to manage it:

  • /context shows what is using space, as a grid with suggestions.
  • /clear throws the conversation away and starts empty. Use it between unrelated tasks. It is free and usually the best choice.
  • /compact [focus] replaces the history with a summary. Claude Code also does this automatically near the limit, first clearing old tool output. Detailed early instructions can be lost, so put lasting rules in CLAUDE.md, and steer the summary: /compact keep the list of modified files and test commands.
  • The rewind menu (Esc Esc) can summarize only part of the conversation, from or up to a chosen message.
  • /btw <question> asks a side question whose answer never enters the history.

A strong habit: if you have corrected Claude twice on the same thing, the context is full of failed attempts. /clear and restart with a better prompt that includes what you learned.

Sessions are saved locally, so long tasks can span days without one giant conversation:

  • claude -c (--continue) continues the latest session in this folder.
  • claude -r (--resume) or /resume picks from a list.
  • /rename oauth-migration names a session so it is easy to find; /branch forks the conversation to try another direction.

Later lessons add subagents, which do noisy research in their own separate context.

Example

> /context                         # what's filling the window?
> /compact keep: modified files, failing test names, the chosen design
> /btw what's the flag for verbose jest output?   # not added to history
> /rename oauth-migration
> /clear                           # unrelated task next: start clean

$ claude --continue                # pick up the latest session here
$ claude --resume                  # choose any earlier session

Remember

  • Context fills quickly and quality degrades as it does
  • /clear between unrelated tasks; /compact with a focus when you must continue
  • Name sessions with /rename and come back with --continue or --resume

Watch out for

  • Running one "kitchen sink" session all day across unrelated tasks, so every request carries stale context.

Check yourself

  1. You corrected Claude twice and it still gets the same thing wrong. Best next move?
  2. What does /compact do?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: code.claude.com/docs/en/best-practices