Skip to content

fix(hooks): keep a hook's matcher and kind when installing to another agent - #204

Merged
RealZST merged 4 commits into
mainfrom
fix/hook-cross-agent-install
Dec 4, 2026
Merged

RealZST merged 4 commits into
mainfrom
fix/hook-cross-agent-install

Conversation

@RealZST

@RealZST RealZST commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Problems

Installing a hook from one agent to another could leave a hook that fires for the wrong tools, never fires, or runs the wrong thing.

Case Before Now
Claude Code Bash hook → Cursor No matcher written; fires for every tool Matcher Shell
Same hook → Gemini CLI Matcher Bash copied; never fires Matcher run_shell_command
Same hook → Copilot No matcher written Matcher Bash
Same hook → Hermes, Kiro Copied silently Copied, and the user is told to check it
Prompt hook → Codex, Gemini CLI, Copilot, Grok Build, Hermes, Kiro Prompt text written as a shell command Refused: "codex does not support prompt hooks"
Prompt hook → Cursor, Qoder CN Written as a shell command Written as a prompt hook
Agent hook ("type": "agent") → any agent but Claude Code Written as a shell command Refused
One install fails in the detail panel "Failed to install to X" The reason is included

Found on the way, all on main today:

  • A Cursor hook with extra fields such as timeout could not be disabled or deleted.
  • A Claude Code prompt hook could not be disabled or deleted.
  • A hook whose matcher is * or contains : (Cursor's MCP:create_issue) could not be disabled.
  • Disabling then enabling one hook of a Claude-shaped group that holds several duplicated the others, so they ran twice. A snapshot saved by an earlier version is trimmed the same way when it is restored.
  • A Copilot hook whose command sits under bash or a platform key (osx, linux, windows) was listed but could not be disabled or deleted.

Changes

  • adapter/hook_tools.rs (new): tool names per agent and translate_matcher. Plain names and | lists are rewritten. Anything else (a regex, an MCP tool pattern, a tool the target has no name for) is copied as written and reported back; the UI shows it as a warning.
  • HookEntry carries a kind: command, prompt or agent. Adapters say which kinds they run.
  • Cursor and Copilot readers and writers handle the matcher. Their write, remove and read arms are merged.
  • Disable and delete find the hook in its file by id instead of splitting the row name on :.
  • Codex and Gemini CLI use the shared Claude-shaped reader; their two copies are removed.
  • Docs (English and Chinese): installing a hook, the extensions guide, troubleshooting.

Behaviour changes to know about

  • Cursor and Copilot hooks that already have a matcher get a new id after upgrading, because the matcher is now part of what HarnessKit reads. Tags and pack on those rows are not carried over. Hooks without a matcher keep their id.
  • An unknown matcher is installed with a warning, not refused.

Not covered

  • Matchers going to Hermes and Kiro, and MCP tool patterns, are not translated.
  • Timeouts still do not travel with a hook.
  • The Install to Agent tiles do not grey out agents that will refuse a prompt hook.
  • Devin Desktop's writer still writes no matcher.

Testing

  • cargo fmt, cargo clippy -D warnings, cargo test --workspace (hk-core 818), tsc, biome, frontend tests (374), website tests (677).
  • Old and new binaries compared in an isolated home for each row of the table, plus disable, enable and delete for the three cases under "Found on the way".
  • New binary run against a copy of a real database with 24 hooks across six agents: ids, enabled state and tags unchanged.
  • On the same copy, each of the 20 global hooks was disabled and enabled again: no failures, and the six config files hold the same content afterwards.
  • Tool names come from each agent's documentation. Hooks were not fired in a real Cursor or Gemini CLI session. Windows: CI only.

🤖 Generated with Claude Code

… agent

Installing a hook to another agent now translates the tool names in its
matcher for Cursor and Gemini CLI, writes the matcher for Cursor and
Copilot (it was dropped), and reports a matcher it had to copy as
written. Prompt and agent hooks go only to agents that run them instead
of being written as shell commands. Install failures show the reason.

Disable and delete now find a hook in its file by id, so a matcher that
holds `:` or `*`, an entry with extra fields, and a prompt hook can all
be disabled and restored.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying harnesskit with  Cloudflare Pages  Cloudflare Pages

Latest commit: f472fa3
Status: ✅  Deploy successful!
Preview URL: https://96bc625a.harnesskit.pages.dev
Branch Preview URL: https://fix-hook-cross-agent-install.harnesskit.pages.dev

View logs

RealZST and others added 3 commits December 4, 2026 22:58
Disabling one handler of a Claude-shaped group saved the whole group, so
enabling it again pushed the group's other handlers back a second time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A Copilot hook whose command sits under `bash` or a platform key was
listed but could not be disabled or deleted, because only `command` was
matched. The reader and the matcher now share one lookup.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Match a Cursor or Copilot entry the way that agent's reader lists it,
  so an entry the reader skips is never saved or removed in its place.
- Entries that differ only in other keys are one row; save all of them,
  since disabling removes all of them.
- Trim a whole-group snapshot saved by an earlier version to the row's
  own handler before restoring it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@RealZST
RealZST merged commit 09a8746 into main Dec 4, 2026
5 checks passed
@RealZST
RealZST deleted the fix/hook-cross-agent-install branch December 4, 2026 15:56
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