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
{
"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_OVERRIDEDocumentedLowers 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_OFFUndocumentedTells 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_MDDocumentedLoads 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_WINDOWDocumentedSets 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_OVERRIDEUndocumentedOverrides the context blocking limit for tests. Claude Code passes it as testBlockingOverride.A numberAll sessions
CLAUDE_CODE_DISABLE_1M_CONTEXTDocumentedTurns off 1M context. Removes [1m] model variants and keeps 1M models at 200K.On or off. Warns about a missing auto compact window when setAll sessions
CLAUDE_CODE_DISABLE_ATTACHMENTSDocumentedTurns off attachment processing, so @ mentions stay plain text. Also turns off kept deferred tools.On or off. Docs: ignored in project and local settingsAll sessions
CLAUDE_CODE_DISABLE_AUTO_MEMORYDocumentedTurns 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_MDSDocumentedStops all CLAUDE.md memory files from loading.On or off. The loaders return an empty list when setAll sessions
CLAUDE_CODE_DISABLE_FILE_MENTIONSDocumentedStops @ 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_INSTRUCTIONSDocumentedRemoves 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_INFLATEUndocumentedSkips 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_HOLDUndocumentedSets 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_RESYNCUndocumentedSets 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_NOTICEUndocumentedSkips 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_LISTUndocumentedSkips the streamed metadata listing in memory store sync.On or off. A feature flag also gates itMemory store sync
CLAUDE_CODE_DISABLE_ORG_MEMORYUndocumented GatedMakes 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_ENFORCEMENTDocumentedSkips 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_ATTACHMENTUndocumentedAdds 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_TOKENSDocumentedSets 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_SUNDIALUndocumented GatedSets 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 10All sessions
CLAUDE_CODE_MAX_CONTEXT_TOKENSDocumentedOverrides 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_MODEUndocumented GatedSets 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_MEMORYUndocumentedTurns 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_CONFIGUndocumentedGives the JSON config of the post-turn memory pass.JSON textCloud and hosted sessions
CLAUDE_CODE_POST_TURN_MEMORY_SYNCUndocumentedMakes 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_DIRUndocumentedSets the memory base dir in a cloud session. It also keeps auto memory on there.TextCloud sessions
CLAUDE_CODE_RIPPLING_TULIPUndocumented GatedOverrides 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_COMPACTUndocumentedTurns 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_MSUndocumentedSets 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_THIMBLEUndocumented GatedOverrides 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_REMINDERUndocumentedSets 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_TURNUndocumentedChooses if 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_BUDGETUndocumentedSets 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_GUIDELINESUndocumentedAdds extra guideline text to the auto memory and agent memory prompts.Text. Ignored when emptyCowork hosts
CLAUDE_COWORK_MEMORY_GUIDELINESUndocumentedReplaces 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_CONTENTUndocumentedSupplies the memory index text and not the file. An empty string turns the injection off.TextCowork hosts
CLAUDE_COWORK_MEMORY_PATH_OVERRIDEUndocumentedSets the auto memory directory. It also keeps auto memory on in remote mode.Text. Must be a valid absolute path, else it is ignoredCowork hosts
CLAUDE_MEMORY_STORESUndocumentedMounts extra memory stores from a JSON list. While set, it also turns the org memory feature off.--
CLAUDE_PROJECT_UUIDUndocumented GatedNames a Claude project. Claude Code fetches the project context block and the project memory index for it.--
DISABLE_AUTO_COMPACTDocumentedTurns off automatic compaction.On or off-
DISABLE_COMPACTDocumentedTurns off all compaction.On or off-
DISABLE_PROMPT_CACHINGDocumentedTurns off prompt caching for all models.On or off-
DISABLE_PROMPT_CACHING_FABLEDocumentedTurns off prompt caching for Fable models.On or off-
DISABLE_PROMPT_CACHING_HAIKUDocumentedTurns off prompt caching for the default Haiku model.On or off-
DISABLE_PROMPT_CACHING_MYTHOSUndocumentedTurns off prompt caching for models that the Mythos check matches.On or off-
MAX_MCP_OUTPUT_TOKENSDocumentedSets the token limit for one MCP tool result.A number-
SLASH_COMMAND_TOOL_CHAR_BUDGETDocumentedOverrides 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_API_CONTEXT_MANAGEMENTUndocumented GatedWould 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 effectInert, 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.

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