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
{
"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 | 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 | 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 | 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 | 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 | Overrides the context blocking limit for tests. Claude Code passes it as test. | A number | All sessions |
CLAUDE_ | Documented | Turns off 1M context. Removes [1m] model variants and keeps 1M models at 200K. | On or off. Warns about a missing auto compact window when set | All sessions |
CLAUDE_ | Documented | Turns off attachment processing, so @ mentions stay plain text. Also turns off kept deferred tools. | On or off. Docs: ignored in project and local settings | All sessions |
CLAUDE_ | Documented | 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 | Stops all CLAUDE. memory files from loading. | On or off. The loaders return an empty list when set | All sessions |
CLAUDE_ | Documented | 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 | 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 | 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 | 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 | 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 | 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 | Skips the streamed metadata listing in memory store sync. | On or off. A feature flag also gates it | Memory store sync |
CLAUDE_ | Undocumented Gated | Makes the org memory gate return false. That gate also needs a feature flag. | On or off, off by default | Org memory |
CLAUDE_ | Documented | 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 | Adds a token_ attachment with used, total, and remaining tokens to the turn. | On or off, off by default | All sessions |
CLAUDE_ | Documented | 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 Gated | Sets the number of turns between maintenance runs, default 10. No visible effect in a print-mode probe (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 | 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 Gated | 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 | 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 | Gives the JSON config of the post-turn memory pass. | JSON text | Cloud and hosted sessions |
CLAUDE_ | Undocumented | 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 | Sets the memory base dir in a cloud session. It also keeps auto memory on there. | Text | Cloud sessions |
CLAUDE_ | Undocumented Gated | 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 | 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 | 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 Gated | 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 | 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 | Chooses if 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 | 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 | Adds extra guideline text to the auto memory and agent memory prompts. | Text. Ignored when empty | Cowork hosts |
CLAUDE_ | Undocumented | 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 | Supplies the memory index text and not the file. An empty string turns the injection off. | Text | Cowork hosts |
CLAUDE_ | Undocumented | Sets the auto memory directory. It also keeps auto memory on in remote mode. | Text. Must be a valid absolute path, else it is ignored | Cowork hosts |
CLAUDE_ | Undocumented | Mounts extra memory stores from a JSON list. While set, it also turns the org memory feature off. | - | - |
CLAUDE_ | Undocumented Gated | Names a Claude project. Claude Code fetches the project context block and the project memory index for it. | - | - |
DISABLE_ | Documented | Turns off automatic compaction. | On or off | - |
DISABLE_ | Documented | Turns off all compaction. | On or off | - |
DISABLE_ | Documented | Turns off prompt caching for all models. | On or off | - |
DISABLE_ | Documented | Turns off prompt caching for Fable models. | On or off | - |
DISABLE_ | Documented | Turns off prompt caching for the default Haiku model. | On or off | - |
DISABLE_ | Undocumented | Turns off prompt caching for models that the Mythos check matches. | On or off | - |
MAX_ | Documented | Sets the token limit for one MCP tool result. | A number | - |
SLASH_ | Documented | Overrides the character budget for the skill listing shown to the model. | A number, 1 by default. Integer, min 1. If set, it wins over the dynamic budget (context window times 4 times a fraction, default 1%) | All sessions |
USE_ | Undocumented Gated | Would turn on the API context-management beta. It is inert in 2.1.304. | 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, it compacts: it asks the model to summarize older turns and 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.304 binary) and the Environment Variables page of the official docs.