Skip to main content

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​

~/.claude/settings.json
{
"$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.

VariableStatusWhat it doesValues and defaultNotes
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
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 checkMain sessions and subagents. Project env can set it before trust
CLAUDE_BG_MEMORY_TOGGLED_OFF
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_CODE_SESSION_KIND is bg. The dispatcher sets itBackground sessions. Not set from project env before trust
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD
Documented: An official docs page names this item.
Loads memory files from --add-dir directories.On or off. The remote add_directory request also needs it set in the containerAll sessions. Not set from project env before trust
CLAUDE_CODE_AUTO_COMPACT_WINDOW
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 --autocompact (since 2.1.304). Claude Code warns when a value is out of range or ignored. Project env may set it before trustAll sessions, allowed in. Project env can set it before trust
CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE
Undocumented: Only the program shows this item. It can change without notice.
Overrides the context blocking limit for tests. Claude Code passes it as testBlockingOverride.A numberAll sessions
CLAUDE_CODE_DISABLE_1M_CONTEXT
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 setAll sessions
CLAUDE_CODE_DISABLE_ATTACHMENTS
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 settingsAll sessions
CLAUDE_CODE_DISABLE_AUTO_MEMORY
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 autoMemoryEnabled: false.On or offAll sessions
CLAUDE_CODE_DISABLE_CLAUDE_MDS
Documented: An official docs page names this item.
Stops all CLAUDE.md memory files from loading.On or off. The loaders return an empty list when setAll sessions
CLAUDE_CODE_DISABLE_FILE_MENTIONS
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 childrenAll sessions
CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS
Documented: An official docs page names this item.
Removes built-in commit and PR instructions and the git status snapshot. Beats includeGitInstructions.On, off, or unset, on by default. When set to any parsed value, the result is its negation. Else the setting, default onAll sessions
CLAUDE_CODE_DISABLE_MEMORY_BULK_INFLATE
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 itMemory store sync
CLAUDE_CODE_DISABLE_MEMORY_MASS_DELETE_HOLD
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 defaultMemory store sync
CLAUDE_CODE_DISABLE_MEMORY_PERIODIC_RESYNC
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 60Memory store sync
CLAUDE_CODE_DISABLE_MEMORY_RO_UNSAVED_NOTICE
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 defaultMemory store sync. Project env can set it before trust
CLAUDE_CODE_DISABLE_MEMORY_STREAM_LIST
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 itMemory store sync
CLAUDE_CODE_DISABLE_ORG_MEMORY
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 defaultOrg memory
CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT
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 behaviorAll sessions. Project env can set it before trust
CLAUDE_CODE_ENABLE_TOKEN_USAGE_ATTACHMENT
Undocumented: Only the program shows this item. It can change without notice.
Adds a token_usage attachment with used, total, and remaining tokens to the turn.On or off, off by defaultAll sessions
CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS
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 defaultAll sessions. Project env can set it before trust
CLAUDE_CODE_JUNIPER_SUNDIAL
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 10All sessions
CLAUDE_CODE_MAX_CONTEXT_TOKENS
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_COMPACTAll sessions. Project env can set it before trust
CLAUDE_CODE_MEMORY_PUSH_DELETE_MODE
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 corroborateMemory sync
CLAUDE_CODE_POST_TURN_MEMORY
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_CODE_POST_TURN_MEMORY_CONFIG.On or off. With a missing or bad config the code logs a warning and the pass stays offCloud and hosted sessions
CLAUDE_CODE_POST_TURN_MEMORY_CONFIG
Undocumented: Only the program shows this item. It can change without notice.
Gives the JSON config of the post-turn memory pass.JSON textCloud and hosted sessions
CLAUDE_CODE_POST_TURN_MEMORY_SYNC
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_n_turns to 1 and the idle flush to 0Cloud and hosted sessions
CLAUDE_CODE_REMOTE_MEMORY_DIR
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.TextCloud sessions
CLAUDE_CODE_RIPPLING_TULIP
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 disabledTotal-tokens reminder. Also blocked by CLAUDE_CODE_DISABLE_ATTACHMENTS and CLAUDE_CODE_SIMPLE
CLAUDE_CODE_SLEEP_COMPACT
Undocumented: Only the program shows this item. It can change without notice.
Turns on sleep compaction. A timer queues /compact 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 windowIdle sessions on supported hosts
CLAUDE_CODE_SLEEP_COMPACT_AFTER_MS
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 msIdle sessions with sleep compaction
CLAUDE_CODE_TOASTY_THIMBLE
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 hereModels served with the reminder
CLAUDE_CODE_TOTAL_TOKENS_REMINDER
Undocumented: Only the program shows this item. It can change without notice.
Sets the mode of the total_tokens reminder that shows the tokens left. off turns it off.Text. Known modes include off, padded-countdown, infinite, and fixed. Env wins over settings and flagAll sessions
CLAUDE_CODE_TOTAL_TOKENS_REMINDER_AFTER_USER_TURN
Undocumented: Only the program shows this item. It can change without notice.
Chooses whether the total_tokens 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 flagAll sessions
CLAUDE_CODE_TOTAL_TOKENS_REMINDER_BUDGET
Undocumented: Only the program shows this item. It can change without notice.
Sets the starting token budget for the padded-countdown reminder mode.A number, 15000000 by default. Integer above 0. Env wins over settings and flagAll sessions
CLAUDE_COWORK_MEMORY_EXTRA_GUIDELINES
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 emptyCowork hosts
CLAUDE_COWORK_MEMORY_GUIDELINES
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 onCowork hosts
CLAUDE_COWORK_MEMORY_INDEX_CONTENT
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.TextCowork hosts
CLAUDE_COWORK_MEMORY_PATH_OVERRIDE
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 valueCowork hosts
CLAUDE_MEMORY_STORES
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/team/<dir name> folder with a 4 KB per-file note. A list of strings, [], or non-JSON text changes nothing.--
CLAUDE_PROJECT_UUID
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_AUTO_COMPACT
Documented: An official docs page names this item.
Turns off automatic compaction.On or off-
DISABLE_COMPACT
Documented: An official docs page names this item.
Turns off all compaction. Since 2.1.311, an env entry in a settings file and a mod's $.env.set can only turn compaction off.On or off. In a settings file env entry or a mod's $.env.set, only a true value counts. Any other value is ignored-
DISABLE_PROMPT_CACHING
Documented: An official docs page names this item.
Turns off prompt caching for all models.On or off-
DISABLE_PROMPT_CACHING_FABLE
Documented: An official docs page names this item.
Turns off prompt caching for Fable models.On or off-
DISABLE_PROMPT_CACHING_HAIKU
Documented: An official docs page names this item.
Turns off prompt caching for the default Haiku model.On or off-
DISABLE_PROMPT_CACHING_MYTHOS
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_MCP_OUTPUT_TOKENS
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_COMMAND_TOOL_CHAR_BUDGET
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_API_CONTEXT_MANAGEMENT
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 effectInert, 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.

Source: the program (variable names found in the 2.1.312 binary) and the Environment Variables page of the official docs.