You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -702,6 +702,68 @@ Notification:
702
702
command: "get-task-status.sh" # Returns JSON with additionalContext
703
703
```
704
704
705
+
### PreCompact JSON Output
706
+
707
+
PreCompact hooks support JSON output format for Claude Code integration. Actions can return structured output for pre-compaction processing:
708
+
709
+
**Output Action** (type: `output`):
710
+
```yaml
711
+
PreCompact:
712
+
- matcher: "manual" # optional: "manual" or "auto"
713
+
actions:
714
+
- type: output
715
+
message: "Pre-compaction processing message"
716
+
```
717
+
718
+
**Command Action** (type: `command`):
719
+
Commands must output JSON with the following structure:
720
+
```json
721
+
{
722
+
"continue": true,
723
+
"stopReason": "Optional stop reason",
724
+
"suppressOutput": false,
725
+
"systemMessage": "Optional system message"
726
+
}
727
+
```
728
+
729
+
**Important**: PreCompact uses **Common JSON Fields only**. Unlike other events, it has no `decision`, `reason`, or `hookSpecificOutput` fields. PreCompact is a pre-processing hook and **cannot block** compaction.
730
+
731
+
**Matcher Support**:
732
+
PreCompact hooks support a `matcher` field to filter by trigger type:
733
+
- `"manual"`: Matches manual compaction triggers
734
+
- `"auto"`: Matches automatic compaction triggers
735
+
- Empty/omitted: Matches all triggers
736
+
737
+
**Field Merging**:
738
+
When multiple actions execute:
739
+
- `continue`: Always `true` (compaction cannot be blocked)
740
+
- `systemMessage`: Concatenated with newline separator
741
+
- `stopReason` and `suppressOutput`: Last value wins
742
+
743
+
**Exit Code Behavior**:
744
+
PreCompact hooks **always exit with code 0**. The `continue` field is always `true` because compaction cannot be blocked.
745
+
746
+
Errors are logged to stderr as warnings, but cchook continues to output JSON and exits successfully. This ensures pre-compaction processing completes even on errors.
747
+
748
+
**Message Mapping**:
749
+
Output action `message` field is mapped to `systemMessage` (shown to user, not to Claude). This maintains backward compatibility with the old stdout-based implementation.
0 commit comments