Skip to content

Claude Code Env Vars Context And Compaction

xsyetopz edited this page Oct 19, 2026 · 1 revision

Claude Code Environment Variables: Context and Compaction

These 57 environment variables of Claude Code 2.1.303 cover the context window, compaction, memory, and the prompt cache. Compaction means that Claude Code replaces a long chat with a short summary. An environment variable is a named setting that you put in your shell or in the env key of settings.json.

Example

Run export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=80 before claude to compact earlier, when the window is 80 percent full. Or put { "env": { "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "80" } } in ~/.claude/settings.json.

Variables

The marks are explained on the index.

Name Mark What It Does Value Where It Works
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE ✅ 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_BG_AUTO_MEMORY_OFF 🔍 The dispatcher sets 1 on a background session when auto memory is off. Purpose unknown. No visible effect in a print-mode probe (Probes). Text. Claude Code sets it at spawn and scrubs it from child env Background sessions. Not set from project env before trust
CLAUDE_BG_MEMORY_TOGGLED_OFF 🔍 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 it Background sessions. Not set from project env before trust
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD ✅ Loads memory files from --add-dir directories. On or off. The remote add_directory request also needs it set in the container All sessions. Not set from project env before trust
CLAUDE_CODE_AUTO_COMPACT_WINDOW ✅ Sets the auto-compact window in tokens. It is capped at the model context window. Text. Invalid values are ignored. Project env may set it before trust All sessions, allowed in. Project env can set it before trust
CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE 🔍 Overrides the context blocking limit for tests. Claude Code passes it as testBlockingOverride. A number All sessions
CLAUDE_CODE_COLD_COMPACT 🔍 A getter returns its value next to the autocompact code. Purpose unknown. No visible effect in a print-mode probe (Probes). On or off All sessions
CLAUDE_CODE_DISABLE_1M_CONTEXT ✅ 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_CODE_DISABLE_ATTACHMENTS ✅ 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_CODE_DISABLE_AUTO_MEMORY ✅ Turns auto memory off. A value of 0 forces it on, even in bare mode or with autoMemoryEnabled: false. On or off All sessions
CLAUDE_CODE_DISABLE_CLAUDE_MDS ✅ Stops all CLAUDE.md memory files from loading. On or off. The loaders return an empty list when set All sessions
CLAUDE_CODE_DISABLE_FILE_MENTIONS ✅ 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_CODE_DISABLE_GIT_INSTRUCTIONS ✅ 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 on All sessions
CLAUDE_CODE_DISABLE_MEMORY_BULK_INFLATE 🔍 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_CODE_DISABLE_MEMORY_MASS_DELETE_HOLD 🔍 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_CODE_DISABLE_MEMORY_PERIODIC_RESYNC 🔍 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_CODE_DISABLE_MEMORY_RO_UNSAVED_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_CODE_DISABLE_MEMORY_STREAM_LIST 🔍 Skips the streamed metadata listing in memory store sync. On or off. A feature flag also gates it Memory store sync
CLAUDE_CODE_DISABLE_ORG_MEMORY 🔍🧪 Makes the org memory gate return false. That gate also needs an internal flag. On or off, off by default Org memory
CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP 🔍 The transcript loader reads it when it loads a transcript. Purpose unknown. No visible effect in a print-mode probe (Probes). On or off, off by default Transcript loading
CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT ✅ 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_CODE_ENABLE_TOKEN_USAGE_ATTACHMENT 🔍 Adds a token_usage attachment with used, total, and remaining tokens to the turn. On or off, off by default All sessions
CLAUDE_CODE_FORCE_EVALUATE_MEMORY 🔍❌ In the schema, but nothing reads it. On or off All sessions
CLAUDE_CODE_FORCE_MEMORY_SURVEY 🔍❌ In the schema, but nothing reads it. On or off All sessions
CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS ✅ 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_CODE_JUNIPER_SUNDIAL 🔍🧪 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_CODE_MAX_CONTEXT_TOKENS ✅ 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_COMPACT All sessions. Project env can set it before trust
CLAUDE_CODE_MEMORY_API_BASE_URL 🔍 The name appears only in a list of env names. Purpose unknown. No visible effect in a print-mode probe (Probes). A URL All sessions
CLAUDE_CODE_MEMORY_API_TOKEN 🔍❌ Would set an Authorization header of type Bearer for the memory API host. In this build the guard always returns nothing, so the branch never runs. Text (a secret) Unknown
CLAUDE_CODE_MEMORY_PUSH_DELETE_MODE 🔍🧪 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_CODE_POST_TURN_MEMORY 🔍 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 off Cloud and hosted sessions
CLAUDE_CODE_POST_TURN_MEMORY_CONFIG 🔍 Gives the JSON config of the post-turn memory pass. JSON text Cloud and hosted sessions
CLAUDE_CODE_POST_TURN_MEMORY_SYNC 🔍 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 0 Cloud and hosted sessions
CLAUDE_CODE_REMOTE_MEMORY_DIR 🔍 Sets the memory base dir in a cloud session. It also keeps auto memory on there. Text Cloud sessions
CLAUDE_CODE_RIPPLING_TULIP 🔍🧪 Overrides an internal 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_CODE_DISABLE_ATTACHMENTS and CLAUDE_CODE_SIMPLE
CLAUDE_CODE_SLEEP_COMPACT 🔍 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 window Idle sessions on supported hosts
CLAUDE_CODE_SLEEP_COMPACT_AFTER_MS 🔍 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_CODE_TOASTY_THIMBLE 🔍🧪 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_CODE_TOTAL_TOKENS_REMINDER 🔍 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 flag All sessions
CLAUDE_CODE_TOTAL_TOKENS_REMINDER_AFTER_USER_TURN 🔍 Chooses 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 flag All sessions
CLAUDE_CODE_TOTAL_TOKENS_REMINDER_BUDGET 🔍 Sets the starting token budget for the padded-countdown reminder mode. A number, 15000000 by default. Integer above 0. Env wins over settings and flag All sessions
CLAUDE_COWORK_MEMORY_EXTRA_GUIDELINES 🔍 Adds extra guideline text to the auto memory and agent memory prompts. Text. Ignored when empty Cowork hosts
CLAUDE_COWORK_MEMORY_GUIDELINES 🔍 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_COWORK_MEMORY_INDEX_CONTENT 🔍 Supplies the memory index text and not the file. An empty string turns the injection off. Text Cowork hosts
CLAUDE_COWORK_MEMORY_PATH_OVERRIDE 🔍 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_MEMORY_STORES 🔍 Mounts extra memory stores from a JSON list. While set, it also turns the org memory feature off. - -
CLAUDE_PROJECT_UUID 🔍🧪 Names a Claude project. Claude Code fetches the project context block and the project memory index for it. - -
DISABLE_AUTO_COMPACT ✅ Turns off automatic compaction. On or off -
DISABLE_COMPACT ✅ Turns off all compaction. On or off -
DISABLE_PROMPT_CACHING ✅ Turns off prompt caching for all models. On or off -
DISABLE_PROMPT_CACHING_FABLE ✅ Turns off prompt caching for Fable models. On or off -
DISABLE_PROMPT_CACHING_HAIKU ✅ Turns off prompt caching for the default Haiku model. On or off -
DISABLE_PROMPT_CACHING_MYTHOS 🔍 Turns off prompt caching for models that the Mythos check matches. On or off -
MAX_MCP_OUTPUT_TOKENS ✅ Sets the token limit for one MCP tool result. A number -
SLASH_COMMAND_TOOL_CHAR_BUDGET ✅ 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
SYSTEM_REMINDER_MEMORY_CONTEXT 🔍🧪 A truthy value helps turn on a memory-context gate, but only for some entrypoints. Purpose unknown. No visible effect in a print-mode probe (Probes). On or off. Also in the list of known names Gated by an entrypoint check
USE_API_CONTEXT_MANAGEMENT 🔍🧪 Would turn on the API context-management beta. It is inert in 2.1.303. On or off. The code ANDs it with a constant false, so it has no effect Inert, first-party models

See Also

Clone this wiki locally