fix(hook): tolerate --hook-json flag from Claude Code harness - #180
Conversation
…son)
Claude Code appends `--hook-json <data>` to the hook command at invocation; both
CLIs rejected it as an unknown option and exited non-zero, breaking the hook.
Hook input comes from stdin, so the extra flag (and its value) is unused and
safe to discard.
- Node: `.allowUnknownOption()` + `.allowExcessArguments()` on BOTH the pretool
and posttool Commander subcommands (the `<data>` value lands as an excess arg,
so allowUnknownOption alone isn't enough).
- Python: `context_settings={allow_extra_args, ignore_unknown_options}` on the
pretool/posttool `@hook_app.command(...)` decorators. (Setting it on the
hook_app *group* — the prior approach — does NOT reach subcommand parsing, so
`--hook-json` was still rejected; verified the group-only fix fails.)
Declared options like `--format` are still parsed normally. Adds Node + Python
regression tests covering: --hook-json tolerated on pretool & posttool, --format
still honored (not swallowed), and unchanged no-flag behavior. CLI_SPEC.md
documents the tolerance.
Supersedes the original #180 branch (which had no merge-base with main and
bundled an unrelated docs/vitest-upgrade history); re-applied cleanly on main.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c386497 to
a82f4d5
Compare
|
Rebuilt this branch so it's mergeable and the fix actually works. Why a rebuild: the branch had no merge-base with Fixed a real bug in the Python side: the original change set Also:
Verified the original repro end-to-end in both languages (exit 0, correct decision). All hook suites green (Node 110, Python 76). |
Patch release bundling the unreleased changes on main since 0.8.9: - Claude Code PostToolUse matcher narrowed .* -> Bash|Write|Edit|MultiEdit (#183) - Hooks tolerate harness-appended flags, e.g. --hook-json (#180) - Dependency CVE re-lock (axios, hono, tar, js-yaml, +transitives) and remote-skill tarball extraction hardening (#184) Bumps node/package.json + python/pyproject.toml to 0.8.10 (parity), the rafter-security skill resource version (node + python), and finalizes the CHANGELOG 0.8.10 section. Refs sable-ehb1 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Summary
--hook-json <data>to hook commands at invocation; both CLIs were rejecting it as an unknown flag.allowUnknownOption()to thepretoolCommander subcommandcontext_settings={"allow_extra_args": True, "ignore_unknown_options": True}tohook_appTest plan
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | rafter hook pretool --hook-json '{}'— no error, returns allow decisionpython -m rafter_cli hook pretool --hook-json '{}' <<< '{"tool_name":"Bash","tool_input":{"command":"ls"}}'— no error🤖 Generated with Claude Code