Allow configuring auto-approval for cd+git compound commands
Feature Request
Claude Code currently shows an approval prompt for compound shell commands that chain \cd\ with \git\ operations, with the message: "Compound commands with cd and git require approval to prevent bare repository attacks."
This safety check is valuable, but there is no way to configure it as auto-approved for trusted project directories or globally.
Desired Behavior
Add a setting (e.g., in \.claude/settings.json\) to whitelist or auto-approve \cd\ + \git\ compound commands, similar to how other tool permissions can be pre-approved:
\\\json\
{
"permissions": {
"allow": ["Bash(cd * && git *)"]
}
}
\\
Workaround
Use absolute paths and \git -C <path>\ instead of \cd\ + command chains, but this is less ergonomic and requires changing habits.
Context
Came up during a multi-step build session where many commands ran in a subdirectory alongside git operations. Having to approve each one interrupts the flow significantly.
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
I highly support this request; chained commands are so painful, not only in
cd && gitcase, but many other safe things are hit, likecat- an absolutely legitimate command in my settings, but...I always have to allow manually such constructions:
Agreed, this is a major PITA..
Please fix!
Workaround with a PreToolUse hook: auto-approve
cd+gitcompounds when the git operation is read-only (log, diff, status, branch, show, etc.), while keeping manual approval for destructive operations (push, reset, clean).Or standalone: cd-git-allow.sh
Returns
permissionDecision: allowfor safe git operations, passes through for everything else.I'm a solo developer building a CRM, I can't walk away and come back to a finished task because this prompt blocks every session
This is exactly what the
cd-git-allowhook was built for:This auto-approves
cd /path && git status,cd /path && git log,cd /path && git add && git commitetc., while still requiring manual approval for destructive operations likegit push,git reset --hard,git clean.The hook runs before the "bare repository attack" check, so the compound command safety prompt is bypassed for trusted operations.
why is this still an issue????
it's making me nutty
I've used this approach for weeks, but it's not really any better, because the claude permission system doesn't seem to have a great way to say "allow -C with any git subcommand I generally marked as safe". I've since switched back to letting claude try
cd ... & git ...Either way, this is a real pain for any case where you're asking claude to do any multi-repo work, e.g. do a similar refactor/dep-upgrade/whatever across many repos ("I've cloned N repos into the CWD: update them all in this way!"), or edit one repo while consulting git history in other repos ("this behavior broke in the CWD repo, and it's probably due to some change in this other dependency repo: please investigate!").
---
It seems like it'd be trivial for the claude harness do any or all of:
cdpath, and only ask when there is such a bare repo (ideally also checking for the presence of any local hooks within, and perhaps permitting if there are no such hooks).git --versionandgit config --global safe.bareRepositoryfor safe values. Mine is set toexplicitalongside a new enough version, so afaict, I'm completely insulated from this attack, thus this claude heuristic is a complete nuisance in my case.cdpath. Ideally this would be based on configured git remote(s), so that if I have the same repo checked out in multiple places, in effect, I only really need to approve a given remote, rather than needing to re-approve every separate clone.With any of those, it should cut down on these annoying permission prompts considerably.