Context and Compaction
These variables change how Claude Code manages the conversation size. They set when compaction starts, how big the context window is, how memory files load, and how the prompt cache behaves. Use them for long sessions or when a gateway needs different cache behavior.
This page lists 49 variables. Set a new value and start a new session. Many rows are on or off switches.
Example
{
"$schema": "https://clawdipedia.cc/schemas/claude-code-settings.json",
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "70"
}
}
Compaction starts earlier than the default.
Variables
The table is sorted by name. See Environment Variables for what each column and badge means.
| Variable | Status | What it does | Values and default | Notes |
|---|---|---|---|---|
CLAUDE_ | Documented: An official docs page names this item. | Lowers the percentage of the window at which auto-compaction starts. | Text. Also used for the fork compaction check | Main sessions and subagents. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Tells a background session that memory was turned off. The session then calls its memory-off handler. | Text. Acts only when the value is 1 and CLAUDE_ is bg. The dispatcher sets it | Background sessions. Not set from project env before trust |
CLAUDE_ | Documented: An official docs page names this item. | Loads memory files from -- directories. | On or off. The remote add_ request also needs it set in the container | All sessions. Not set from project env before trust |
CLAUDE_ | Documented: An official docs page names this item. | Sets the auto-compact window in tokens. It is capped at the model context window. | Text. Accepts k and M suffixes, such as 200k, like -- (since 2.1.304). Claude Code warns when a value is out of range or ignored. Project env may set it before trust | All sessions, allowed in. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Overrides the context blocking limit for tests. Claude Code passes it as test. | A number | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Turns off 1M context. Removes [1m] model variants and keeps 1M models at 200K. | On or off. Claude Code warns about a missing auto compact window when it is set | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Turns off attachment processing, so @ mentions stay plain text. It also turns off kept deferred tools. | On or off. Docs: ignored in project and local settings | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Turns auto memory off. A value of 0 forces it on, even in bare mode or with auto. | On or off | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Stops all CLAUDE. memory files from loading. | On or off. The loaders return an empty list when set | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Stops @ mention expansion. Claude gets the paths with a note to read them. | On or off. Docs: ignored in project and local settings. Claude Code also passes it to auto mode classifier children | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Removes built-in commit and PR instructions and the git status snapshot. Beats include. | On, off, or unset, on by default. When set to any parsed value, the result is its negation. Else the setting, default on | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Skips the bulk pull of all memory files from a memory store backend. | On or off. A feature flag also gates it | Memory store sync |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the memory mass delete threshold to infinity. The threshold is otherwise the larger of 50 and 10 percent of the files. | On or off, off by default | Memory store sync |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the memory store resync interval to 0, which turns the periodic resync off. | On or off, 60 by default. Otherwise the interval is a feature flag, default 60 | Memory store sync |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Skips the scan that warns about unsaved writes in a read-only memory store mount. | On or off, off by default | Memory store sync. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Skips the streamed metadata listing in memory store sync. | On or off. A feature flag also gates it | Memory store sync |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Works only behind a feature flag or server gate | Makes the org memory gate return false. That gate also needs a feature flag. | On or off, off by default | Org memory |
CLAUDE_ | Documented: An official docs page names this item. | Skips proactive auto-compaction at an assumed window for a model id that Claude Code does not know. | On or off. Messages say it restores the earlier wait-for-the-API behavior | All sessions. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Adds a token_ attachment with used, total, and remaining tokens to the turn. | On or off, off by default | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Sets the context size in tokens where idle compaction applies. It also feeds the sleep compaction timer. | A number. Whole number min 1, whole value. Unset uses a built-in default | All sessions. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Works only behind a feature flag or server gate | Sets the number of turns between maintenance runs, default 10. A print-mode probe showed no visible effect (Probes). | A number. Whole number min 1, digits only. Order is env, then client data a feature flag, then the flag of that name, then 10 | All sessions |
CLAUDE_ | Documented: An official docs page names this item. | Overrides the context window that Claude Code assumes for the model, when the model id allows it. | A number. A value above 0 counts. Also used with DISABLE_ | All sessions. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Works only behind a feature flag or server gate | Sets the delete mode for memory push. Values are corroborate, immediate, and never. | corroborate by default. enum. Unset reads a feature flag, default corroborate | Memory sync |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Turns on the hosted post-turn memory extraction pass. It needs a valid CLAUDE_. | On or off. With a missing or bad config the code logs a warning and the pass stays off | Cloud and hosted sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Gives the JSON config of the post-turn memory pass. | JSON text | Cloud and hosted sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Makes the post-turn memory pass run after every turn with no idle flush delay. | On or off. Sets every_ to 1 and the idle flush to 0 | Cloud and hosted sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the memory base dir in a cloud session. It also keeps auto memory on there. | Text | Cloud sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. A feature flag or server gate decides by default. This variable overrides it | Overrides a feature flag value for the total-tokens reminder. A positive whole number sets the reminder size. | A number. Must be a positive safe integer. It does nothing when the reminder is off or attachments are disabled | Total-tokens reminder. Also blocked by CLAUDE_ and CLAUDE_ |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Turns on sleep compaction. A timer queues / while the session idles and before the prompt cache expires. | On or off. Active only on a host that qualifies. The timer fires at 0.9 of the cache time window | Idle sessions on supported hosts |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets how long after a turn ends the sleep compaction may fire. | A number of milliseconds. Integer 1 or more. The code clamps it between 60000 and 210000 ms | Idle sessions with sleep compaction |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. A feature flag or server gate decides by default. This variable overrides it | Overrides the batching reminder, a prompt note that tells the model to request all independent tool calls in one response. | Text. The accepted values are not shown here | Models served with the reminder |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the mode of the total_ reminder that shows the tokens left. off turns it off. | Text. Known modes include off, padded-, infinite, and fixed. Env wins over settings and flag | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Chooses whether the total_ reminder shows after each user prompt and re-anchors the budget on each user turn. | On, off, or unset, on by default. Env wins over settings and a feature flag | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the starting token budget for the padded- reminder mode. | A number, 15000000 by default. Integer above 0. Env wins over settings and flag | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Adds extra guideline text to the auto memory and agent memory prompts. | Text. Claude Code ignores it when it is empty | Cowork hosts |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Replaces the auto memory prompt with # auto memory plus this text. It also forces file-based memory. | Text. Needs auto memory on | Cowork hosts |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Supplies the memory index text instead of the file. An empty string turns the injection off. | Text | Cowork hosts |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the auto memory directory. It also keeps auto memory on in remote mode. | Text. Must be a valid absolute path. Claude Code ignores any other value | Cowork hosts |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Takes a JSON list of {"name","path"} objects. The memory section stays. Claude Code names each store as a shared memory/ folder with a 4 KB per-file note. A list of strings, [], or non-JSON text changes nothing. | - | - |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Works only behind a feature flag or server gate | Names a Claude project. Claude Code fetches the project context block and the project memory index for it. | - | - |
DISABLE_ | Documented: An official docs page names this item. | Turns off automatic compaction. | On or off | - |
DISABLE_ | Documented: An official docs page names this item. | Turns off all compaction. Since 2., an env entry in a settings file and a mod's $. can only turn compaction off. | On or off. In a settings file env entry or a mod's $., only a true value counts. Any other value is ignored | - |
DISABLE_ | Documented: An official docs page names this item. | Turns off prompt caching for all models. | On or off | - |
DISABLE_ | Documented: An official docs page names this item. | Turns off prompt caching for Fable models. | On or off | - |
DISABLE_ | Documented: An official docs page names this item. | Turns off prompt caching for the default Haiku model. | On or off | - |
DISABLE_ | Undocumented: Only the program shows this item. It can change without notice. | Turns off prompt caching for models that the Mythos check matches. | On or off | - |
MAX_ | Documented: An official docs page names this item. | Sets the token limit for one MCP tool result. | A number. Default 25000. The warning at 10000 stays fixed | - |
SLASH_ | Documented: An official docs page names this item. | Overrides the character budget for the skill listing shown to the model. | Unset by default. An integer of 1 or more. If set, it wins over the dynamic budget. The dynamic budget is the context window times a fraction, times the characters per token. That number is 4 for Claude 3 to 4.6 models and 3 for newer ones. The default fraction is 1% | All sessions |
USE_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Works only behind a feature flag or server gate | Would turn on the API context-management beta. It is inert in 2.1.312. | On or off. The code ANDs it with a constant false, so it has no effect | Inert, first-party models |
How It Works
Claude Code counts the tokens in the conversation. When the count passes a limit, Claude Code compacts the conversation. It asks the model to summarize older turns. Then it keeps the summary. The variables here move that limit, turn compaction off, or change what stays in the prompt cache. See Context and Compaction for the full flow.
Related Pages
- Environment Variables: how Claude Code reads variables and which value wins.
- Sessions and Storage
- Models and Effort
- Undocumented Items: every item that only the program shows.
Source: the program (variable names found in the 2.1.312 binary) and the Environment Variables page of the official docs.