Claude Code auto-compacts your conversation when context reaches ~80%. This loses nuance, plan details, and conversation history. Power users who manage context manually need a way to prevent it.
42 reactions on #6689. No --no-auto-compact CLI flag exists. The undocumented autoCompactEnabled: false in ~/.claude.json works but has no granular control.
Add to ~/.claude.json:
{
"autoCompactEnabled": false
}
This disables auto-compaction globally. No conditions, no hooks.
A PreCompact hook gives you conditional control — block compaction sometimes, allow it others.
compact-blocker.sh — unconditional block:
#!/bin/bash
# TRIGGER: PreCompact
# exit 2 = block compaction
exit 2
Conditional variant — toggle with a flag file:
#!/bin/bash
# Allow compaction when flag file exists
[ -f /tmp/allow-compact ] && exit 0
exit 2
Run touch /tmp/allow-compact when you're ready. rm /tmp/allow-compact to block again.
npx cc-safe-setup --install-example compact-blocker
Or add to .claude/settings.json:
{
"hooks": {
"PreCompact": [{
"hooks": [{
"type": "command",
"command": "bash /path/to/compact-blocker.sh"
}]
}]
}
}
Note: Blocking compaction means your context will eventually fill up. Combine with pre-compact-checkpoint.sh to auto-save work before manually triggering compaction.
npx cc-safe-setup
8 safety hooks + 655 examples. 9,200+ tests.
cc-safe-setup · 667 hooks · 9,200+ tests · GitHub