Repository navigation
feat(hooks): honor Claude Code per-event hook types and add PreSkillShellCommand - #3994
Merged
Merged
Conversation
…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
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
Follow-up to the Claude Code upstream tracking issue #2664: two items that can be implemented within rulesync's existing hooks feature.
agenthook onpermissionRequestor aprompthook onnotificationwas written to.claude/settings.jsonand then skipped by Claude Code.PreSkillShellCommandevent (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 optionaleventHookTypes(canonical event -> allowed hook types) onToolHooksConverterConfig.describeExportSkipReasonreturns 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 newfailClosedEventHookTypeEvents(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 byclaudecode-pluginthroughgetConverterConfig). Events not listed keep all five types.src/types/hooks.ts: canonicalpreSkillShellCommand->PreSkillShellCommand(Claude only; matcher-capable, not in the no-matcher set).PreCompactoverride key, PreSkillShellCommand round-trip with matcher andonFailure, its prompt hook kept with a warning), converter-level tests foreventHookTypes(group fields from the remaining hooks, native override key lookup, fail-closed keep), plugin inheritance, event mapping.docs/reference/file-formats.md(typefield note on Claude's per-event limits;preSkillShellCommandmatcher/version note; regenerated hook matrix) andsrc/generated/docs-content.ts.Design decisions
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 existingskippedWhenFieldswarn-and-skip path.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 (PreToolUsedoes 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'sfailClosedEventHookTypeEventsoption. No other event documents this behaviour (PreModelSwitchwas checked: the docs only list it among the command/http/mcp_tool events), so the set holds onlypreSkillShellCommand.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)
.claude/workflows/and pluginworkflows/(gaps 1/3): a new feature dimension; the shape is a maintainer decision (asked on the issue).settings.json/ output styles /loop.md: new surfaces outside rulesync's current feature dimensions; maintainer decision.sandbox.enabledwarning: the text was corrected in fix(claudecode): follow mcp_tool onFailure, denyInsteadOfPrompting scope and new sandbox default #3930 and is still accurate (a user-scopeautoAllowBashIfSandboxed: truemakes it apply), so it is left as is.scheduled-task) was already resolved by fix(skills): skip claudecode scheduled-task skills at project scope #3003.Refs #2664
🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4