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
SessionEnd hooks support JSON output format for Claude Code integration. Actions can return structured output for session cleanup:
660
+
661
+
**Output Action** (type: `output`):
662
+
```yaml
663
+
SessionEnd:
664
+
- actions:
665
+
- type: output
666
+
message: "Session cleanup message"
667
+
```
668
+
669
+
**Command Action** (type: `command`):
670
+
Commands must output JSON with the following structure:
671
+
```json
672
+
{
673
+
"continue": true,
674
+
"stopReason": "Optional stop reason",
675
+
"suppressOutput": false,
676
+
"systemMessage": "Optional system message"
677
+
}
678
+
```
679
+
680
+
**Important**: SessionEnd uses **Common JSON Fields only**. Unlike other events, it has no `decision`, `reason`, or `hookSpecificOutput` fields. SessionEnd is a cleanup-only hook and **cannot block** session termination.
681
+
682
+
**Field Merging**:
683
+
When multiple actions execute:
684
+
- `continue`: Always `true` (session end cannot be blocked)
685
+
- `systemMessage`: Concatenated with newline separator
686
+
- `stopReason` and `suppressOutput`: Last value wins
687
+
688
+
**Exit Code Behavior**:
689
+
SessionEnd hooks **always exit with code 0**. The `continue` field is always `true` because session termination cannot be blocked.
690
+
691
+
Errors are logged to stderr as warnings, but cchook continues to output JSON and exits successfully. This ensures cleanup actions complete even on errors.
692
+
693
+
**Message Mapping**:
694
+
Output action `message` field is mapped to `systemMessage` (shown to user, not to Claude). This maintains backward compatibility with the old stdout-based implementation.
695
+
696
+
**Condition Types**:
697
+
SessionEnd supports the `reason_is` condition to match session end reasons:
698
+
- `"clear"`: User cleared the session
699
+
- `"logout"`: User logged out
700
+
- `"prompt_input_exit"`: User exited via prompt input
0 commit comments