Skip to content

feat(hook): warn when a Bash(rtk:*) allow rule is present - #4716

Open
xiaozou-second wants to merge 1 commit into
rtk-ai:developfrom
xiaozou-second:feat/init-warn-broad-rtk-allow-rule
Open

xiaozou-second wants to merge 1 commit into
rtk-ai:developfrom
xiaozou-second:feat/init-warn-broad-rtk-allow-rule

Conversation

@xiaozou-second

Copy link
Copy Markdown

Summary

  • rtk init (install and upgrade) and rtk verify now print a stderr warning
    for any Bash(...) allow rule that grants every rtk … command — e.g.
    Bash(rtk:*) reads as "rtk's own commands" but also auto-allows
    rtk git push, which the user never allowed on its own. Closes Warn when a Bash(rtk:*) allow rule is present #4649.
  • The predicate asks the existing matcher (command_matches_pattern) against
    rtk gain, rtk git push and rtk cargo test rather than re-deriving
    wildcard semantics, so Bash(rtk), Bash(rtk*:*) and Bash(*rtk*) are
    caught while Bash(rtk git:*) and Bash(rtk git push) are not. Bash(*)
    stays unflagged: not rtk-specific, and the "narrow it" advice would mislead.
  • Fires from the end of the Commands::Init arm, so the per-agent branches
    warn too; the hook path and rtk verify --filter stay silent.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test

  • Manual testing: rtk <command> output inspected

  • New tests/broad_rtk_allow_warning_test.rs: init / init -g --gemini /
    verify warn; Bash(rtk git push), Bash(rtk git:*), Bash(*rtk),
    Bash(*) stay silent; Bash(rtk) warns; hook path and verify --filter
    silent with a positive control and exit-status check; repeated rule warns
    once.

  • Manual, temp CLAUDE_CONFIG_DIR: verify, init -g and init -g --gemini
    each warn for Bash(rtk:*) and Bash(rtk), silent for Bash(rtk git push),
    Read(rtk:*) and Bash(*); --dry-run, --show, verify --filter cargo
    and hook claude warn nothing.

`Bash(rtk:*)` reads as "rtk's own commands" but also auto-allows every
command rtk filters, including ones the user never allowed on its own —
`rtk git push` runs without a prompt. `rtk init` (install and upgrade)
and `rtk verify` now say so on stderr, once per broad rule per settings
file; the hook path stays silent because its stdout is the host protocol.

The predicate asks the existing matcher against three unrelated
subcommands rather than re-deriving wildcard semantics, so `Bash(rtk)`
(a word-boundary prefix, not an exact match) and `Bash(rtk*:*)` are
caught while `Bash(rtk git:*)` and `Bash(rtk git push)` are not.
`Bash(*)` stays unflagged: it is not rtk-specific, and narrowing it to
an rtk rule would misdescribe what the user allowed.

The call sits at the end of the `Commands::Init` arm, so the per-agent
branches (gemini, pi, trae, …) warn too, not only the shared Claude
path. `--dry-run`, `--show`, uninstall and `verify --filter` stay
silent.

Also fixes `read_json` reporting a parse failure for an existing empty
settings file, and spells both parse-failure paths with `display_path`
so one run cannot name the same file two ways.

Closes rtk-ai#4649.
@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

✨ Type feature
🟢 Risk low

Summary

Adds a stderr warning emitted during rtk init and rtk verify when a Claude Code settings file contains a Bash allow rule that broadly matches every 'rtk ...' command (e.g. Bash(rtk:*)), since such rules also auto-allow underlying commands like rtk git push that the user never explicitly allowed. The check reuses the existing command_matches_pattern matcher against three probe commands to distinguish broad rules from legitimately narrow ones, and excludes the hook execution path and verify --fil…

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4649


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when a Bash(rtk:*) allow rule is present

2 participants