fix(hooks): always set permissionDecision so Claude Code applies rewrites#3020
Closed
Nitjsefnie wants to merge 1 commit into
Closed
fix(hooks): always set permissionDecision so Claude Code applies rewrites#3020Nitjsefnie wants to merge 1 commit into
Nitjsefnie wants to merge 1 commit into
Conversation
…ites Claude Code ignores updatedInput when hookSpecificOutput omits permissionDecision. The native Claude path (process_claude_payload) only inserted permissionDecision: "allow" for AllowRewrite, leaving AskRewrite without the field. AskRewrite is the default verdict, so rewrites were silently discarded. Mirror the existing correct path in handle_vscode: set permissionDecision to "allow" or "ask" for every rewrite. Co-Authored-By: Kimi K2.7 Code <noreply@kimi.com>
Author
|
Withdrawing this PR — I'm not in a position to sign the CLA, so it can't proceed. The diff stays available on the branch if anyone wants to pick it up. Thanks! |
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.
Problem
rtk hook claudeemits ahookSpecificOutputcontainingupdatedInputbut, on the default "ask" path, omitspermissionDecision. Per the Claude Code hooks schema,updatedInputis only applied whenpermissionDecisionis explicitly present, so Claude Code silently executes the original command and the rewrite has no effect.Root cause
src/hooks/hook_cmd.rshad two paths that build Claude-shapedhookSpecificOutputand they disagreed:handle_vscode, ~line 153) already mappedAllowRewrite→"allow"andAskRewrite→"ask"and always emittedpermissionDecision.process_claude_payload, ~line 342) reduced the decision to abool, only insertingpermissionDecision: "allow"whenallow == true. OnAskRewritethe field was omitted entirely.AskRewriteis the default verdict for rewritable commands when no explicit allow rule exists, so most Bash commands were rewritten in RTK's output but never actually changed in Claude Code.Fix
Make
process_claude_payloadsetpermissionDecisionunconditionally —"allow"forAllowRewriteand"ask"forAskRewrite— matching the existing correct path inhandle_vscode.Schema confirmation
The Claude Code hooks documentation states that for
PreToolUse,updatedInputallows modifying tool input parameters, and the example shows it paired with"permissionDecision": "allow". Valid values are"allow","deny", and"ask". See Claude Code hooks reference — PreToolUse Decision Control.Regression-test evidence
Added tests covering both rewrite verdicts:
test_claude_allow_rewrite_sets_permission_decision_allowtest_claude_ask_rewrite_sets_permission_decision_askI temporarily reverted the fix while keeping the new tests. The AskRewrite test failed with:
After restoring the fix, both new tests and the full suite pass.
Gates
cargo fmt --all --check✅cargo clippy --all-targets -- -D warnings✅cargo test✅ (2437 unit tests + integration tests)Closes #3018
Prepared with AI assistance (Kimi K2.7 Code), human-reviewed before submission.