Repository navigation
Description
Summary
exclude_commands is matched as a prefix of the raw command string, while the hook rewriter normalises git -C <path> away before routing. The two disagree, so an entry that excludes git worktree does not exclude git -C /path worktree.
This matters because exclude_commands is the documented way to opt out of a broken handler, and the form it misses is the one Claude Code users are told to prefer. #2303 asked for git -C <path> <sub> to be routed like git <sub>; that landed, but the exclusion path was not updated with it. The net effect is that implementing #2303 silently re-exposed #3710 for anyone who had worked around it in config.
Reproduce
rtk 0.45.0, macOS, homebrew. Config:
[hooks]
exclude_commands = ["git worktree"]$ rtk hook check "git worktree prune --dry-run --verbose"
No rewrite for: git worktree prune --dry-run --verbose
$ rtk hook check "git -C /path/to/repo worktree prune --dry-run --verbose"
rtk git -C /path/to/repo worktree prune --dry-run --verboseSame subcommand, same intent, opposite outcome.
Substring matching is not the answer either, and does not work today: setting exclude_commands = ["worktree"] excludes neither form.
Why it bites
git worktree is in exclude_commands here because of #3710. With the exclusion apparently in place, the -C form still reaches the handler. prune is not misrouted the way repair was, but its output is discarded:
$ rtk git -C /path/to/repo worktree prune --dry-run --verbose
ok
$ git -C /path/to/repo worktree prune --dry-run --verbose
Removing worktrees/gone: gitdir file points to non-existent locationVerified on a throwaway repo that the rewritten --dry-run does not mutate state, so this is output fidelity rather than a second repair. The report is the entire point of a dry run, and ok reads as "nothing to prune". I concluded exactly that, wrongly, and only caught it by rerunning through rtk run.
Suggested fix
Apply the same -C <path> normalisation to exclude_commands matching that the rewriter already applies to routing, so an exclusion is expressed against the git subcommand rather than against the literal invocation. Leading global options other than -C presumably have the same problem.
The workaround in the meantime is exclude_commands = ["git worktree", "git -C"], which is far broader than intended: it drops every git -C invocation, and that is the recommended form.
Activity
PascalThuet commentedon Sep 2, 2026
#3752 is open and routes every non-list worktree subcommand to git unchanged, so it should make the "Why it bites" section here obsolete:
prune --dry-runwould return its native report instead ofok. Treat that half as superseded once it lands.The report above is not affected by it. #3752 touches
src/cmds/git/git.rsonly, and the mismatch is inexclude_commandsmatching, which runs before routing. It reproduces withrtk hook checkalone, without executing any git command:Worth keeping separate for a second reason: once #3752 makes
worktreesafe, the exclusion is no longer needed for that handler, and the matching gap stays for whichever handler someone needs to opt out of next.KuSh commentedon Sep 12, 2026
Same gap, second command family — noting it here rather than opening a duplicate.
#3275 adds
strip_pnpm_global_opts, mirroringstrip_git_global_opts, sopnpm -r installstarts being rewritten. It inherits this issue along with the shape. With
exclude_commands = ["pnpm install", "git status"], on that PR's head:So the fix wanted here is the general one this issue already describes — match
exclude_commandsagainst the same normalized formclassify_commanduses, rather than theraw text — and it should cover every
strip_*_global_optshelper, not just git.wcruz-br commentedon Sep 26, 2026
Same gap with
git diff, and here the cost is corrupted output rather than a lost report. It still reproduces on 0.47.0 (Linux, WSL2).Config, using the multi-word entries that #1919 confirmed work since 0.37.2:
The rewritten
--name-onlyoutput ends with an extraChanges:line after the file list. Anything that parses the list gets a spurious entry and no error. Piping the rewritten diff togit applyfails with "No valid patches in input". The hunks themselves are preserved.As in the report above, the
-Cform is the one agents are told to prefer, because it avoidscd. In our setup it is effectively the only form in use, so the exclusion covers almost nothing in practice. Runningexclude_commandsmatching on the same normalised command that routing uses (afterstrip_git_global_opts) would fix bothgit worktreeandgit diff.KuSh commentedon Nov 10, 2026
The cargo spellings that #5056 routes escape
exclude_commandsthe same waygit -Cdoes. Withrtk rewrite "cargo test"exits 1, but on #5056's headcargo +nightly testandcargo --locked testare rewritten tortk cargo …(exit 3). Develop does not rewrite those spellings at all, so the gap only shows once they are routed. Whatever normalisation decides that a command is supported should also be what the exclude list is matched against.KuSh commentedon Nov 17, 2026
#5056 now matches
exclude_commandsagainst the canonical cargo command at top level, so withexclude_commands = ["cargo test"],cargo +stable testandcargo --locked testare left alone. The wrapper paths still compare the raw text of the inner command, so the same commands are filtered once they sit under a routable wrapper:rtk rewriteuv run cargo testuv run cargo +stable testrtk uv run cargo +stable testuv run cargo --locked testrtk uv run cargo --locked testuv run bash -c 'cargo test'uv run bash -c 'cargo +stable test'rtk uv run bash -c 'cargo +stable test'Develop gives the same results (it does not normalise the cargo prefix anywhere). The checks involved are the routable-wrapper fallthrough and
shell_wrapper_script_opts_outinsrc/discover/registry.rs, both callingis_excludedon the raw segment. One predicate meaning "excluded as written or in its normalised tool form", used by every exclusion check, would close this for cargo and for thegit -Ccase above.