refactor: extract hook protocol into coding-agent-hooks crate#452
Merged
eliothedeman merged 1 commit intomainfrom Apr 16, 2026
Merged
refactor: extract hook protocol into coding-agent-hooks crate#452eliothedeman merged 1 commit intomainfrom
eliothedeman merged 1 commit intomainfrom
Conversation
Move the agent-agnostic hook handling logic into a new workspace crate called `coding-agent-hooks`. The name `agent-hooks` was taken on crates.io. The new crate provides: - AgentKind enum with optional clap::ValueEnum (behind `clap` feature) - HookProtocol trait abstracting agent-specific JSON formats - Hook input/output types with an Effect enum (Allow/Ask/Deny) - Protocol implementations for all 6 agents - Tool name normalization and permission mode resolution tables The clash crate now depends on coding-agent-hooks and re-exports its types through crate::hooks and crate::agents. Clash-specific extensions (typed_tool_input via ToolUseHookInputExt trait, is_interactive_tool, SelectItem impl) remain in the clash crate. Replaces claude_settings::PermissionRule in hook output types with the new coding_agent_hooks::output::Effect enum, which serializes identically (allow/ask/deny).
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.
Summary
coding-agent-hooks(agent-hookswas already taken on crates.io)HookProtocoltrait, hook I/O types,AgentKindenum, all 6 agent protocol implementations, and tool/mode name normalizationclashcrate now depends oncoding-agent-hooksand re-exports its types, keeping clash-specific extensions (typed tool input, interactive tool classification,SelectItemimpl) localDetails
New crate:
coding-agent-hooksAgentKindenum with optionalclap::ValueEnumderive behind aclapfeature flagHookProtocoltrait — only 2 methods required to add a new agentEffectenum (Allow/Ask/Deny) replacingclaude_settings::PermissionRulein hook output types (serializes identically)Changes to clash crate
crate::hooksnow re-exports fromcoding-agent-hooks+ addsToolUseHookInputExtextension trait fortyped_tool_input()crate::agentsnow re-exports fromcoding-agent-hooks+ addsSelectItemimplhandlers.rsandcmd/hooks.rsupdated to useEffectfrom new crate instead ofPermissionRuleclash/src/agents/(moved to new crate)Test plan
cargo test -p coding-agent-hooks— 50 tests pass (all agent protocols, I/O types, normalization)cargo test -p clash— 389 tests pass (no regressions)cargo test --workspace— full workspace greencargo fmt --all -- --check— cleancargo check --workspace— compiles without warnings