Claude Code compacts the conversation on its own when the context window fills up. How full it lets that window get is a setting, and you can change it without touching a config file.
/autocompact 500k
Pass a size and Claude Code saves it to your user settings for the current model and applies it to the session straight away. /autocompact auto returns to the window tuned for your model, and without an argument you get a dialog showing the current window. The command needs Claude Code v2.1.221 or later.
Accepted values are 100K tokens or more, written as a plain count like 200000, with a suffix like 500k or 1M, or as a bare number from 100 to 1000 meaning thousands, so 200 sets 200,000. Claude Code caps whatever you pick at the model’s context window.
There are other ways in:
claude --autocompact 500kfor one launch, without changing your saved setting."autoCompactWindow": 200000in a settings file such as~/.claude/settings.json, for every model.- The
CLAUDE_CODE_AUTO_COMPACT_WINDOWenvironment variable for scripts and cloud environments.
The caveat is precedence. The environment variable beats the command, the flag and the setting. And if managed settings define a window, /autocompact saves your value but the session keeps the managed one, and the command tells you so. The flag, unlike the command, isn’t preempted by a higher-priority scope such as managed settings.
Since the environment variable wins, a forgotten export in a shell profile is the first thing I’d check when the command seems to do nothing.
Further reading: Claude Code docs: model configuration, Claude Code docs: commands