CLAUDE_CODE_SLEEP_COMPACT
Updated by Alex Sorokoletov
CLAUDE_CODE_SLEEP_COMPACT is a Claude Code environment variable: When set, enables sleep compaction, which compacts the conversation while the session sits idle. Added in v2.1.295 and still present in v2.1.318. It is not in the official reference.
| Status | Present in v2.1.318 |
|---|---|
| Added | Added in v2.1.295 |
| Category | Context and compaction |
| Official docs | Not listed |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_SLEEP_COMPACT=<value>
claudeTo apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_SLEEP_COMPACT": "<value>"
}
}Related variables
CLAUDE_CODE_SLEEP_COMPACT_AFTER_MS: Milliseconds to wait after a turn before idle sleep compaction runs, clamped between 60000 and 210000; defaults to 150000.CLAUDE_AFTER_LAST_COMPACT: Request only conversation logs after last compaction.CLAUDE_CODE_AUTO_COMPACT_WINDOW: Sets the auto-compact window in tokens, 100k to 1M, capped at the model's context window.CLAUDE_CODE_AUTO_MODE_COMPACT_THREAD_RULE: When set, enables the compact thread rule for auto-mode project threads; while off, thread handling stays on the original path.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS: Sets the minimum conversation size, in tokens, before idle compaction runs.DISABLE_AUTO_COMPACT: Disable automatic compaction only (manual /compact still works).DISABLE_CLAUDE_CODE_SM_COMPACT: Disable session memory compaction.DISABLE_COMPACT: Disable all compaction (manual + auto).
Frequently asked questions
What does CLAUDE_CODE_SLEEP_COMPACT do?
When set, enables sleep compaction, which compacts the conversation while the session sits idle.
Which Claude Code version has CLAUDE_CODE_SLEEP_COMPACT?
Added in v2.1.295 and still present in v2.1.318.
How do I set CLAUDE_CODE_SLEEP_COMPACT?
Export it before starting Claude Code (export CLAUDE_CODE_SLEEP_COMPACT=value), or add it to the "env" object in ~/.claude/settings.json to apply it to every session.
All variables, searchable: Claude Code environment variables.