Skip to content

feat(hooks): honor Claude Code per-event hook types and add PreSkillShellCommand - #3994

Merged
dyoshikawa merged 5 commits into
mainfrom
resolve-issue-2664-claude-hook-type-limits
Nov 26, 2026
Merged

dyoshikawa merged 5 commits into
mainfrom
resolve-issue-2664-claude-hook-type-limits

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to the Claude Code upstream tracking issue #2664: two items that can be implemented within rulesync's existing hooks feature.

  1. Per-event hook-type limits. Claude Code's hooks reference (Prompt-based hooks) now documents which handler types each event runs. rulesync emitted all five types on every event, so e.g. an agent hook on permissionRequest or a prompt hook on notification was written to .claude/settings.json and then skipped by Claude Code.
  2. New PreSkillShellCommand event (Claude Code v2.1.332, CHANGELOG 2.1.332 and hooks#preskillshellcommand): runs before a skill's injected shell command and can block it. It could not be authored before.

Changes

  • src/features/hooks/tool-hooks-converter.ts: new optional eventHookTypes (canonical event -> allowed hook types) on ToolHooksConverterConfig. describeExportSkipReason returns a skip reason when a hook's type is not in its event's set, so the definition is warned about and not emitted, unless the event is listed in the new failClosedEventHookTypeEvents (then it is emitted with a warning); tool-native event keys from the override block are looked up under their canonical name. Group-level passthrough fields only consider the surviving definitions. Import is not filtered.
  • src/features/hooks/claudecode-hooks.ts: the Claude Code matrix from the docs (inherited by claudecode-plugin through getConverterConfig). Events not listed keep all five types.
  • src/types/hooks.ts: canonical preSkillShellCommand -> PreSkillShellCommand (Claude only; matcher-capable, not in the no-matcher set).
  • Tests: claudecode hooks (skips on permissionRequest/notification/sessionStart/setup, kept agent on preToolUse, event dropped when all hooks are skipped incl. a native PreCompact override key, PreSkillShellCommand round-trip with matcher and onFailure, its prompt hook kept with a warning), converter-level tests for eventHookTypes (group fields from the remaining hooks, native override key lookup, fail-closed keep), plugin inheritance, event mapping.
  • Docs: docs/reference/file-formats.md (type field note on Claude's per-event limits; preSkillShellCommand matcher/version note; regenerated hook matrix) and src/generated/docs-content.ts.

Design decisions

  • Warn and skip where Claude Code ignores the hook. On PermissionRequest (agent) and the command/http/mcp_tool-only events, Claude Code skips the hook with no effect, so rulesync drops it with a warning. This mirrors the existing skippedWhenFields warn-and-skip path.
  • Warn and keep where Claude Code fails closed. On PreSkillShellCommand, Claude Code "can't run" a prompt/agent hook and "blocks each command the hook matches" (hooks.md). Dropping it would turn that fail-closed guard into no guard at all (PreToolUse does not fire for injected commands), so it is emitted as authored, with a warning to switch it to command/http/mcp_tool. This is the converter's failClosedEventHookTypeEvents option. No other event documents this behaviour (PreModelSwitch was checked: the docs only list it among the command/http/mcp_tool events), so the set holds only preSkillShellCommand.
  • Generate only; import untouched. Import round-trips whatever is on disk, matching how other generate-side filters behave.
  • Generic converter option, Claude-only data. Other Claude-shaped targets (CodeBuddy, Qoder, ...) keep their own behavior; their docs were not checked for the same limits, so they get no matrix here.
  • No version gate for preSkillShellCommand. Like earlier additions (preModelSwitch, v2.1.251), the event is emitted only when authored; the docs note tells users that Claude Code < v2.1.332 shows an "Unknown hook event" dialog.

Skipped items (remain open on #2664)

Refs #2664

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 5 commits November 26, 2026 17:09
…hellCommand

Claude Code documents which handler types each hook event runs: agent
hooks are skipped on PermissionRequest, Setup runs only command hooks,
SessionStart only command and mcp_tool, and nineteen events run only
command, http and mcp_tool. Add an `eventHookTypes` converter option and
fill it for the claudecode and claudecode-plugin targets, so a hook of
another type is skipped on generate with a warning instead of being
written for Claude Code to ignore (or, on PreSkillShellCommand, to block
every matched command).

Also add the canonical `preSkillShellCommand` event (Claude Code
v2.1.332), mapped to `PreSkillShellCommand` with its Bash/PowerShell
matcher.

Refs #2664

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…annot run

On PreSkillShellCommand, Claude Code blocks every command a prompt or
agent hook matches, so skipping such a hook turned a fail-closed guard
into no guard. Emit it with a warning instead, via the new
failClosedEventHookTypeEvents converter option, and add converter-level
tests for eventHookTypes.

Refs #2664

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…aude-hook-type-limits

# Conflicts:
#	src/generated/docs-content.ts
…aude-hook-type-limits

# Conflicts:
#	docs/reference/file-formats.md
#	src/generated/docs-content.ts
…aude-hook-type-limits

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit e09e6b9 into main Nov 26, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-2664-claude-hook-type-limits branch November 26, 2026 09:51
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