feat: Claude Code hooks仕様への追従 - 既存イベントの不足フィールド追加#78
Merged
Conversation
…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内に統合して残す。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Claude Code hooks仕様の拡張に追従し、既存11イベントの不足フィールドを追加する。
背景
公式Claude Codeフック仕様( https://code.claude.com/docs/en/hooks )は日々拡張されており、cchookの既存実装との間に入力フィールド・出力フィールド・matcher機能の差分が生じていた。本PRで既存イベントのフィールドを公式仕様に合わせる。
変更内容
入力フィールドの追加
tool_use_id,agent_id,agent_typeを追加tool_use_id,permission_suggestionsを追加。専用パーサーparsePermissionRequestInputを新設last_assistant_messageを追加agent_id,agent_type,agent_transcript_path,last_assistant_messageを追加出力フィールドの追加
reasonフィールドを追加(decision: "block"時のブロック理由)updatedPermissionsフィールドを追加(allow時のパーミッション設定動的変更)Hook構造体のmatcher拡張
matcherフィールドを追加(agent_typeフィルタリング)matcherフィールドを追加(reason値の完全一致フィルタリング)その他
ToolResponseにUnmarshalJSONを追加し direct unmarshal を可能にした関連情報