brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: /autocompact decides how full Claude Code lets the context get before it compacts

Claude
~/tips/tip-claude-code-autocompact-window

/autocompact 500k

Sets how much of the context window fills up before Claude Code compacts automatically.

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 500k for one launch, without changing your saved setting.
  • "autoCompactWindow": 200000 in a settings file such as ~/.claude/settings.json, for every model.
  • The CLAUDE_CODE_AUTO_COMPACT_WINDOW environment 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

More Claude tips /recap /focus /skill-doctor claude purge ~/work/my-repo --dry-run claude auth status --text All Claude tips (83) All topics

Link