Repository navigation
fix(hooks): honor permissions.defaultMode in claude hook (closes #1771) - #1809
Closed
giulio-leone wants to merge 1 commit into
Closed
giulio-leone wants to merge 1 commit into
giulio-leone wants to merge 1 commit into
Conversation
…ai#1771) The Claude Code PreToolUse hook (`rtk hook claude`) read only `permissions.allow/deny/ask` from settings.json and ignored `permissions.defaultMode`. When users opted into a non-prompting mode (`bypassPermissions`, `acceptEdits`, `auto`, `dontAsk`), unmatched commands fell through to `Default` (= ask) instead of auto-allowing. Symptom: on the Claude Code Mac desktop app every Bash command triggered a permission prompt for `rtk <subcommand>` even with `defaultMode: "bypassPermissions"` set, defeating the transparent-rewrite design that opt-in via `rtk init -g` is meant to deliver. Root cause: `permissions::check_command_with_rules` had no awareness of `defaultMode`, so the rewrite path never emitted `hookSpecificOutput.permissionDecision: "allow"` unless the user had written explicit allow rules — duplicating the global mode at rule level. Fix: - New `DefaultMode` enum mirroring the schema at json.schemastore.org/claude-code-settings.json. - `load_permission_rules()` now also reads `permissions.defaultMode` with project-local files taking precedence over user-global. - `check_command_with_rules` takes `default_mode: DefaultMode`. When no rule matches and the mode is non-prompting (bypassPermissions, acceptEdits, auto, dontAsk), returns `Allow` instead of `Default`. - Deny and Ask rules still win — the security floor is preserved. - Plan/Default still fall through to `Default` (least-privilege). Test additions: 12 new tests covering each defaultMode value, the deny/ask precedence over auto-allow, compound commands, and from_str parsing. All 1828 existing tests still pass.
|
Got u |
Contributor
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
Contributor
|
Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you! |
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
rtk hook claude) read onlypermissions.allow/deny/askfromsettings.jsonand ignoredpermissions.defaultMode. When users opted into a non-prompting mode (bypassPermissions,acceptEdits,auto,dontAsk), unmatched commands fell through toDefault(= ask) instead of auto-allowing.rtk <subcommand>even withdefaultMode: "bypassPermissions"set — defeating the transparent-rewrite design that opt-in viartk init -gis meant to deliver.check_command_with_rulesmode-aware: when the user has chosen a non-prompting mode and no rule matches, it returnsAllow(so the hook emitspermissionDecision: "allow").Closes #1771.
Root cause
permissions::check_command_with_ruleshad no awareness ofdefaultMode. The rewrite path therefore never emittedhookSpecificOutput.permissionDecision: "allow"unless the user had written explicit allow rules — duplicating the global mode at rule level.Changes
DefaultModeenum insrc/hooks/permissions.rsmirroring the JSON schema (default | acceptEdits | auto | bypassPermissions | dontAsk | plan).load_permission_rules()now also readspermissions.defaultMode. Project-local files take precedence over user-global, matching Claude Code's settings layering.check_command_with_rulestakes a newdefault_mode: DefaultModeparameter. When no rule matches and the mode is non-prompting (bypassPermissions,acceptEdits,auto,dontAsk), it returnsAllowinstead ofDefault.DenyandAskrules still win regardless ofdefaultMode.PlanandDefaultstill fall through to least-privilege.check_command_with_rules(inhook_cmd.rs,rewrite_cmd.rs, and the test suite) now passes aDefaultMode. The public surface (check_command(cmd)) is unchanged — it loadsdefaultModefrom settings transparently.Behavior table
defaultModedefault(or unset)planbypassPermissionsacceptEditsautodontAskTest coverage
12 new unit tests in
src/hooks/permissions.rs:DefaultModevalue (bypassPermissions,acceptEdits,auto,dontAsk,default,plan) verifying the no-rule fallback.test_default_mode_does_not_override_denyandtest_default_mode_does_not_override_askverifying the security floor.test_default_mode_explicit_allow_still_returns_allowverifying allow rules + bypass don't conflict.test_default_mode_compound_command_with_bypassandtest_default_mode_compound_with_partial_deny_still_deniesverifying compound-command behavior.test_default_mode_from_strcovering parser correctness.Full suite: 1828 passed, 0 failed, 6 ignored (
cargo test).cargo clippyproduces no new warnings on touched files.Verification on the actual Claude Code Mac app
Before this fix, with
~/.claude/settings.json:{ "permissions": { "defaultMode": "bypassPermissions" } }After:
Backward compatibility
check_command(cmd)) signature unchanged.defaultModeset ordefaultMode: "default"is identical to before this PR.defaultModeget the new auto-allow — which is exactly what they asked for.Test plan
cargo build— cleancargo test— 1828 passed, 0 failedcargo clippy— no new warnings on touched filescargo fmt --check— cleanbypassPermissionsmode