Tip: PreCompact Hook — Block Claude Code Context Compaction to Preserve Critical State
Claude Code Docs·medium signal
Claude Code v2.1.105 introduces PreCompact hooks that fire before compaction and can block it by exiting with code 2 or returning {"decision":"block"}. If triggered proactively (before hitting context limit), the conversation continues uncompacted. If triggered at context limit, the underlying error surfaces. Use case: preserve critical in-memory state during complex multi-step tasks where compaction would lose essential context. Add to your .claude/hooks/PreCompact script.