Skip to content

fix(hooks): honor permissions.defaultMode in claude hook (closes #1771) - #1809

Closed
giulio-leone wants to merge 1 commit into
rtk-ai:developfrom
giulio-leone:fix/honor-default-mode-bypass-permissions
Closed

giulio-leone wants to merge 1 commit into
rtk-ai:developfrom
giulio-leone:fix/honor-default-mode-bypass-permissions

Conversation

@giulio-leone

Copy link
Copy Markdown

Summary

  • 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.
  • This PR makes check_command_with_rules mode-aware: when the user has chosen a non-prompting mode and no rule matches, it returns Allow (so the hook emits permissionDecision: "allow").

Closes #1771.

Root cause

permissions::check_command_with_rules had no awareness of defaultMode. The rewrite path therefore never emitted hookSpecificOutput.permissionDecision: "allow" unless the user had written explicit allow rules — duplicating the global mode at rule level.

Changes

  • New DefaultMode enum in src/hooks/permissions.rs mirroring the JSON schema (default | acceptEdits | auto | bypassPermissions | dontAsk | plan).
  • load_permission_rules() now also reads permissions.defaultMode. Project-local files take precedence over user-global, matching Claude Code's settings layering.
  • check_command_with_rules takes a new default_mode: DefaultMode parameter. When no rule matches and the mode is non-prompting (bypassPermissions, acceptEdits, auto, dontAsk), it returns Allow instead of Default.
  • Security floor preserved: Deny and Ask rules still win regardless of defaultMode. Plan and Default still fall through to least-privilege.
  • Callsite updates: every internal caller of check_command_with_rules (in hook_cmd.rs, rewrite_cmd.rs, and the test suite) now passes a DefaultMode. The public surface (check_command(cmd)) is unchanged — it loads defaultMode from settings transparently.

Behavior table

Settings defaultMode No rule matches Deny matches Ask matches Allow matches
default (or unset) Default (ask) Deny Ask Allow
plan Default (ask) Deny Ask Allow
bypassPermissions Allow ← fix Deny Ask Allow
acceptEdits Allow ← fix Deny Ask Allow
auto Allow ← fix Deny Ask Allow
dontAsk Allow ← fix Deny Ask Allow

Test coverage

12 new unit tests in src/hooks/permissions.rs:

  • One per DefaultMode value (bypassPermissions, acceptEdits, auto, dontAsk, default, plan) verifying the no-rule fallback.
  • test_default_mode_does_not_override_deny and test_default_mode_does_not_override_ask verifying the security floor.
  • test_default_mode_explicit_allow_still_returns_allow verifying allow rules + bypass don't conflict.
  • test_default_mode_compound_command_with_bypass and test_default_mode_compound_with_partial_deny_still_denies verifying compound-command behavior.
  • test_default_mode_from_str covering parser correctness.

Full suite: 1828 passed, 0 failed, 6 ignored (cargo test).
cargo clippy produces no new warnings on touched files.

Verification on the actual Claude Code Mac app

Before this fix, with ~/.claude/settings.json:

{ "permissions": { "defaultMode": "bypassPermissions" } }
$ echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"}}}
# ← no permissionDecision field, Mac app prompts the user

After:

$ echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"},"permissionDecision":"allow"}}
# ← permissionDecision: "allow" present, Mac app skips the prompt

Backward compatibility

  • Public API (check_command(cmd)) signature unchanged.
  • Default behavior with no defaultMode set or defaultMode: "default" is identical to before this PR.
  • Users with explicit allow rules see no behavior change.
  • Only users who explicitly opted into a non-prompting defaultMode get the new auto-allow — which is exactly what they asked for.

Test plan

  • cargo build — clean
  • cargo test — 1828 passed, 0 failed
  • cargo clippy — no new warnings on touched files
  • cargo fmt --check — clean
  • Manual verification on Claude Code Mac app with bypassPermissions mode

Note: this PR supersedes the closed #1808 (which was opened from a different account and against master instead of develop).

…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.
@CLAassistant

CLAassistant commented May 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Lukas13124

Copy link
Copy Markdown

Got u ♥️

@rtk-release-bot

Copy link
Copy Markdown
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.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@rtk-release-bot

Copy link
Copy Markdown
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!

@rtk-release-bot rtk-release-bot Bot closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook output should include permissionDecision: "allow" so rewritten commands don't trigger Claude Code permission prompts (Mac desktop app)

3 participants