Skip to content

Commit 010ee04

Browse files
committed
docs: output_format: text の使い方をCLAUDE.mdに追記
PreToolUse, PostToolUse, SessionStart, SessionEnd の各セクションに output_format: text の設定方法と挙動の説明を追加。
1 parent 088feea commit 010ee04

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ SessionStart hooks **always exit with code 0**, even when:
297297

298298
Errors are logged to stderr as warnings, but cchook continues to output JSON and exits successfully. This ensures Claude Code always receives a response.
299299

300+
**Plain Text Output** (`output_format: text`):
301+
For commands that output plain text (not JSON), use `output_format: text` to treat the stdout as `additionalContext`:
302+
```yaml
303+
SessionStart:
304+
- actions:
305+
- type: command
306+
command: "get-project-info.sh" # Returns plain text, not JSON
307+
output_format: text # stdout treated as additionalContext
308+
```
309+
- Without `output_format: text`, non-JSON stdout causes `continue: false` (fail-safe)
310+
300311
**Example**:
301312
```yaml
302313
SessionStart:
@@ -433,6 +444,19 @@ PreToolUse hooks **always exit with code 0**. The `permissionDecision` field con
433444

434445
Errors are logged to stderr as warnings, but cchook continues to output JSON and exits successfully. On errors, `permissionDecision` defaults to `"deny"` for safety.
435446

447+
**Plain Text Output** (`output_format: text`):
448+
For commands that output plain text (not JSON), use `output_format: text` to treat the stdout as `permissionDecisionReason` with `permissionDecision: "allow"`:
449+
```yaml
450+
PreToolUse:
451+
- matcher: "Bash"
452+
actions:
453+
- type: command
454+
command: "shellcheck {.tool_input.command}"
455+
output_format: text # stdout treated as permissionDecisionReason, permissionDecision set to "allow"
456+
```
457+
- Non-zero exit code still causes fail-safe `permissionDecision: "deny"` behavior
458+
- Without `output_format: text`, non-JSON stdout causes `permissionDecision: "deny"` (fail-safe)
459+
436460
**Example**:
437461
```yaml
438462
PreToolUse:
@@ -641,6 +665,22 @@ After JSON migration:
641665
- Use `decision` field instead: omit for allow, `"block"` to prompt Claude
642666
- A stderr warning is emitted if `exit_status` is set (migration reminder)
643667

668+
**Plain Text Output** (`output_format: text`):
669+
For commands that output plain text (not JSON), use `output_format: text` to treat the stdout as `additionalContext`:
670+
```yaml
671+
PostToolUse:
672+
- matcher: "Write|Edit|MultiEdit"
673+
conditions:
674+
- type: file_extension
675+
value: ".go"
676+
actions:
677+
- type: command
678+
command: "gofmt -w {.tool_input.file_path}"
679+
output_format: text # stdout treated as additionalContext, not parsed as JSON
680+
```
681+
- Non-zero exit code still causes fail-safe `decision: "block"` behavior
682+
- Without `output_format: text`, non-JSON stdout causes `decision: "block"` (fail-safe)
683+
644684
**Example**:
645685
```yaml
646686
PostToolUse:
@@ -873,6 +913,17 @@ SessionEnd supports the `reason_is` condition to match session end reasons:
873913
- `"prompt_input_exit"`: User exited via prompt input
874914
- `"other"`: Other reasons
875915

916+
**Plain Text Output** (`output_format: text`):
917+
For commands that output plain text (not JSON), use `output_format: text` to treat the stdout as `systemMessage`:
918+
```yaml
919+
SessionEnd:
920+
- actions:
921+
- type: command
922+
command: "cleanup-session.sh" # Returns plain text, not JSON
923+
output_format: text # stdout treated as systemMessage
924+
```
925+
- Without `output_format: text`, non-JSON stdout causes systemMessage set to error message
926+
876927
**Example**:
877928
```yaml
878929
SessionEnd:

0 commit comments

Comments
 (0)