Skip to content

feat: Claude Code hooks仕様への追従 - 既存イベントの不足フィールド追加#78

Merged
syou6162 merged 14 commits intomainfrom
additional_field
Mar 19, 2026
Merged

feat: Claude Code hooks仕様への追従 - 既存イベントの不足フィールド追加#78
syou6162 merged 14 commits intomainfrom
additional_field

Conversation

@syou6162
Copy link
Copy Markdown
Owner

概要

Claude Code hooks仕様の拡張に追従し、既存11イベントの不足フィールドを追加する。

背景

公式Claude Codeフック仕様( https://code.claude.com/docs/en/hooks )は日々拡張されており、cchookの既存実装との間に入力フィールド・出力フィールド・matcher機能の差分が生じていた。本PRで既存イベントのフィールドを公式仕様に合わせる。

変更内容

入力フィールドの追加

  • PreToolUseInput / PostToolUseInput: tool_use_id, agent_id, agent_type を追加
  • PermissionRequestInput: 型エイリアスから独立構造体に変更し、tool_use_id, permission_suggestions を追加。専用パーサー parsePermissionRequestInput を新設
  • StopInput: last_assistant_message を追加
  • SubagentStopInput: agent_id, agent_type, agent_transcript_path, last_assistant_message を追加

出力フィールドの追加

  • UserPromptSubmitOutput: reason フィールドを追加(decision: "block" 時のブロック理由)
  • PermissionRequestDecision: updatedPermissions フィールドを追加(allow時のパーミッション設定動的変更)

Hook構造体のmatcher拡張

  • SubagentStopHook: matcher フィールドを追加(agent_typeフィルタリング)
  • SessionEndHook: matcher フィールドを追加(reason値の完全一致フィルタリング)

その他

  • ToolResponseUnmarshalJSON を追加し direct unmarshal を可能にした
  • SessionStartHookのmatcherコメントに "compact" を追加
  • CLAUDE.mdに追加フィールドの説明を追記

関連情報

syou6162 added 14 commits March 13, 2026 20:52
…nt_type を追加

Claude Code hooks仕様への追従。ツール呼び出し固有のユニークID (tool_use_id)、
サブエージェントID (agent_id)、エージェント種別 (agent_type) を入力フィールドに追加。
ToolResponse に UnmarshalJSON を追加し direct unmarshal を可能にした。
…ions を追加

型エイリアス `= PreToolUseInput` から独立した構造体に変更。
tool_use_id とパーミッション提案リスト permission_suggestions (json.RawMessage) を追加。
parser.go に parsePermissionRequestInput 専用パーサーを追加し
parseInput の case を PreToolUse と PermissionRequest に分離。
StopInput に last_assistant_message を追加。
SubagentStopInput に agent_id, agent_type, agent_transcript_path,
last_assistant_message を追加。Claude Code hooks仕様への追従。
agent_type でフィルタリングできるよう Matcher フィールドを追加。
hooks_execute.go と hooks_dryrun.go に checkMatcher ロジックを追加。
SubagentStart と同じパターン(部分一致・パイプ区切りOR)で動作する。
reason 値でフィルタリングできるよう Matcher フィールドを追加。
reason は有限セット(clear/logout/prompt_input_exit/bypass_permissions_disabled/other)
なので checkNotificationMatcher(完全一致)を使用。
hooks_execute.go と hooks_dryrun.go に matcherチェックを追加。
decision: "block" 時のブロック理由を伝える reason フィールドを追加。
hooks_execute.go にマージロジックを追加(decision変更時はリセット、
同一decision内は改行連結)。executor.go で command/output 両ケースに
対応。checkUnsupportedFieldsUserPromptSubmit に "reason" を追加。
allow時のパーミッション設定を動的変更する updatedPermissions を json.RawMessage
として追加。ActionOutput にも対応フィールドを追加。
executor_tool_permission.go でコマンド出力からの読み取りを追加。
hooks_tool_permission.go でマージロジック(last non-null wins)と
deny時のクリア処理、最終出力への反映を追加。
今回追加した全フィールド・機能の説明をCLAUDE.mdのRecent Extensions
セクションに追記。SessionStartHook の matcher コメントに "compact" を追加。
updatedPermissions は allow 時のみ有効な仕様であるため、
behavior が deny だけでなく ask に切り替わった際もクリアする。
Codexレビューで指摘された潜在的なバグを修正。
条件/アクションエラーによるfail-safe(deny化)で updatedPermissions を
クリアしていなかった。allow時のみ有効な仕様に違反した deny + updatedPermissions
の不正な組み合わせが出力される可能性があったため修正。
Codexレビュー(2回目)で指摘。
複数アクションを持つフックで後のアクションの UpdatedPermissions が破棄される
バグを修正。updatedInput と同様に last non-null wins のロジックを追加。
合わせて deny/ask への切り替わり時に UpdatedPermissions もクリアする。
Codexレビュー(3回目)で指摘。
追加フィールドの説明を各JSON Outputセクションに直接記載し、
Recent Hook Type Extensions内の重複サブセクションを削除。
PermissionRequest関連のみRecent Extensions内に統合して残す。
@syou6162 syou6162 self-assigned this Mar 19, 2026
@syou6162 syou6162 marked this pull request as ready for review March 19, 2026 15:32
@syou6162 syou6162 merged commit 65d805c into main Mar 19, 2026
2 checks passed
@syou6162 syou6162 deleted the additional_field branch March 19, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant