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.

๐Ÿ“š Shared input helpers

MethodDescription
triggerGet the compaction trigger: 'manual' or 'auto'
custom_instructionsGet custom instructions (only available for manual trigger)

Hook State Helpers

๐Ÿ“š Shared hook state methods

MethodDescription
block!(reason)Block the compaction with a reason (top-level decision: 'block')

Utility Methods

Utility methods for transcript management.

MethodDescription
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.

๐Ÿ“š Shared output helpers

MethodDescription
output.blocked?Check if the compaction was blocked
output.decisionGet the decision ('block' or nil)
output.reasonGet the block reason

Hook Exit Codes

Exit CodeBehavior
exit 0Operation continues
STDOUT shown to user in transcript mode
exit 1Non-blocking error
STDERR shown to user
exit 2N/A
STDERR shown to user only