Skip to content

Commit 2d79aa2

Browse files
committed
docs: SubagentStop JSON出力のドキュメント追加(Step 7完了)
CLAUDE.mdとREADME.mdにSubagentStop JSON出力の説明を追加。 - CLAUDE.md: SubagentStop JSON Outputセクション追加(Stopと同じパターン) - Output/Command action形式 - Field merging、Exit code behavior、Exampleを記載 - README.md: Exit Status Controlセクション更新 - JSON Output EventsにSubagentStopを追加 - Legacy Exit Code EventsからSubagentStopを除外 - exit_statusデフォルト一覧を更新 Step 1-6完了。ドキュメント整備完了。
1 parent abc450c commit 2d79aa2

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

CLAUDE.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,66 @@ Stop:
521521
decision: "block"
522522
reason: "Stopping Claude in this directory may lose work context"
523523
```
524+
525+
### SubagentStop JSON Output
526+
527+
SubagentStop hooks support JSON output format for Claude Code integration. Actions can return structured output with decision control to block or allow subagent stopping:
528+
529+
**Output Action** (type: `output`):
530+
```yaml
531+
SubagentStop:
532+
- actions:
533+
- type: output
534+
message: "SubagentStop reason message"
535+
decision: "block" # optional: "block" only; omit to allow stop
536+
reason: "Detailed reason for blocking" # required when decision is "block"
537+
```
538+
539+
**Command Action** (type: `command`):
540+
Commands must output JSON with the following structure:
541+
```json
542+
{
543+
"continue": true,
544+
"decision": "block",
545+
"reason": "Detailed reason for blocking",
546+
"stopReason": "Optional stop reason",
547+
"suppressOutput": false,
548+
"systemMessage": "Optional system message"
549+
}
550+
```
551+
552+
Note: To allow the subagent stop, omit the `decision` field entirely.
553+
554+
**Important**: SubagentStop uses the same decision control format as Stop hooks. It does NOT use `hookSpecificOutput`. All fields are at the top level.
555+
556+
**Field Merging**:
557+
When multiple actions execute:
558+
- `continue`: Always `true` (cannot be changed for SubagentStop)
559+
- `decision`: Last value wins (early return on `"block"`)
560+
- `reason`: Reset when decision changes; concatenated with newline within same decision
561+
- `systemMessage`: Concatenated with newline separator
562+
- `stopReason` and `suppressOutput`: Last value wins
563+
564+
**Exit Code Behavior**:
565+
SubagentStop hooks **always exit with code 0**. The `decision` field controls whether the subagent stopping is blocked:
566+
- `decision` field omitted: SubagentStop proceeds normally
567+
- `"block"`: SubagentStop is blocked (early return)
568+
569+
Errors are logged to stderr as warnings, but cchook continues to output JSON and exits successfully. On errors, `decision` defaults to `"block"` for safety (fail-safe).
570+
571+
**Example**:
572+
```yaml
573+
SubagentStop:
574+
- conditions:
575+
- type: cwd_contains
576+
value: "/important-project"
577+
actions:
578+
- type: output
579+
message: "Cannot stop subagent in important project directory"
580+
decision: "block"
581+
reason: "Stopping subagent in this directory may lose work context"
582+
```
583+
524584
### PostToolUse JSON Output
525585

526586
PostToolUse hooks support JSON output format for Claude Code integration. Actions can return structured output with decision control and additional context:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,18 +627,18 @@ All conditions return proper error messages for unknown condition types, ensurin
627627
- Print message
628628
- Default `exit_status`:
629629
- 0 for SessionStart, SessionEnd, UserPromptSubmit (non-blocking events)
630-
- 2 for PostToolUse, SubagentStop, Notification, PreCompact
631-
- Note: PreToolUse and Stop use JSON output (exit_status ignored)
630+
- 2 for Notification, PreCompact
631+
- Note: PreToolUse, Stop, PostToolUse, and SubagentStop use JSON output (exit_status ignored)
632632

633633
### Exit Status Control
634634

635-
**JSON Output Events** (SessionStart, UserPromptSubmit, PreToolUse, Stop, PostToolUse):
635+
**JSON Output Events** (SessionStart, UserPromptSubmit, PreToolUse, Stop, SubagentStop, PostToolUse):
636636
- Always exit with code 0
637637
- Control behavior via JSON fields (`decision`, `permissionDecision`, etc.)
638638
- Errors logged to stderr as warnings
639639
- See CLAUDE.md for detailed JSON output format
640640

641-
**Legacy Exit Code Events** (SubagentStop, Notification, PreCompact, SessionEnd):
641+
**Legacy Exit Code Events** (Notification, PreCompact, SessionEnd):
642642
- 0
643643
- Success, allow execution, output to stdout
644644
- 2

0 commit comments

Comments
 (0)