When your context fills up
Claude Code compacts automatically as you approach the limit, so a full context window doesn't end your session. The automatic pass works the same way as the /compact step in the timeline. See When context fills up for what it preserves.
You can also act before the automatic pass runs:
- Compact with a focus: run
/compactwith instructions, like/compact focus on the auth bug fix, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important. - Compact part of the conversation: run
/rewind, select a message, and choose Summarize from here or Summarize up to here. See Rewind and summarize for what each option keeps and how to guide the summary. - Compact earlier: run
/autocompactwith a token count, like/autocompact 500k, to set how full the context window gets before the automatic pass runs. See Set the auto-compact window for accepted values and overrides. - Clear between tasks: run
/clearwhen switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message. - Delegate large reads: send research to a subagent so the file contents stay in its context window, not yours.
If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See Extended context for availability by plan and how to select a [1m] model variant. Compaction works the same way at the larger limit.
Sonnet 5 runs with the 1M context window and has no [1m] variant to select. See Sonnet 5 context window for its auto-compaction thresholds and the LLM gateway exception.
The point where automatic compaction runs depends on your model and configuration. See Default auto-compact thresholds for the boundaries per model, and Correct the window for a gateway or custom model ID if Claude Code assumes the wrong window for your model ID, such as an LLM gateway alias.