PreCompact API
July 14, 2026 ยท View on GitHub
Available when inheriting from ClaudeHooks::PreCompact:
Input Helpers
Input helpers to access the data provided by Claude Code through STDIN.
| Method | Description |
|---|---|
trigger | Get the compaction trigger: 'manual' or 'auto' |
custom_instructions | Get custom instructions (only available for manual trigger) |
Hook State Helpers
๐ Shared hook state methods
| Method | Description |
|---|---|
block!(reason) | Block the compaction with a reason (top-level decision: 'block') |
Utility Methods
Utility methods for transcript management.
| Method | Description |
|---|---|
backup_transcript!(backup_file_path) | Create a backup of the transcript at the specified path |
Output Helpers
Output helpers provide access to the hook's output data and helper methods for working with the output state.
| Method | Description |
|---|---|
output.blocked? | Check if the compaction was blocked |
output.decision | Get the decision ('block' or nil) |
output.reason | Get the block reason |
Hook Exit Codes
| Exit Code | Behavior |
|---|---|
exit 0 | Operation continuesSTDOUT shown to user in transcript mode |
exit 1 | Non-blocking errorSTDERR shown to user |
exit 2 | N/ASTDERR shown to user only |