I was fixing my wallpaper app late one evening, and every time I asked for a commit, the same approval screen appeared — even though Bash(git add *) and Bash(git commit *) were both in my allow rules. After about ten presses of "Yes," my hand stopped.
Looking closer, the prompt wasn't asking about git add or git commit. It was asking about cd.
What I'd like to say first is that this is often not a typo in your allow rules. I could only draw the line after rereading the official permissions page. Looking back, I'd been doubting my settings before I had actually read what the prompt said. I've written this up so that if you're stuck pressing "Yes" on the same screen, you leave knowing where to look and what to change.
How to recognize it
If all three of these are true, I'd suspect the same cause.
- Claude emits one chained line such as
cd /path/to/repo && git add ... && git commit .... - The prompt is about
cd, or asks about the whole command. - Choosing "Yes, and don't ask again" doesn't help: the next run shows the same screen.
There is a matching report on GitHub (anthropics/claude-code, issue 28240, "Permission prompt incorrectly triggers on cd instead of the actual command in compound bash statements"): on version 2.1.52, on Windows, cd /some/path && git add file && git commit kept asking for cd:*, and the approval couldn't be saved for the session. The reporter says earlier versions prompted for git add and git commit instead. A separate feature request (issue 32985) asks for a setting to auto-approve cd-plus-git chains.
What the official docs say (checked November 19, 2026)
The Permissions page on code.claude.com covers compound commands. Here are the parts that matter for this problem.
| Topic | What it says |
|---|---|
| Separators | Commands are split on &&, ||, ;, |, |&, & and newlines; every subcommand must be allowed for the whole thing to run without a prompt |
| "Don't ask again" | Saves a rule per subcommand that needed approval, not one rule for the whole string (up to 5 per compound command). A cd outside your working directories is saved as a Read rule for that path |
cd alone | cd is on the read-only list. A cd inside the working directory or an additional directory lets a chain like cd packages/api && ls run without a prompt if each part qualifies |
cd with git | If the cd changes into a different directory, it prompts even when each part is read-only, because running git in a new directory can execute that directory's hooks. A cd that resolves to the current working directory is a no-op and doesn't prompt |
cd with a redirect | Prompts when Claude Code can't tell which directory the redirect target resolves against after the cd. A target of only /dev/null is the exception |
| CLAUDE.md | Permission rules are enforced by Claude Code, not by the model. Instructions in your prompt or CLAUDE.md shape what Claude tries, but don't change what Claude Code allows |
So with cd /somewhere-else && git add ..., the combination itself is what gets the prompt, however complete your git rules are. What the issue reported as a bug is now described in the docs as intended behavior. Whether the behavior at the time of that report exactly matches today's, I haven't been able to confirm.
Why only cd plus git gets stopped
At first this struck me as oddly strict. git add and git status just read files and update the index. But when git starts, it reads that repository's .git/hooks and .git/config. git commit runs hooks like pre-commit, and depending on the config, other commands can be invoked too.
The real question is who wrote those hooks and that config. In a repository I created, I did. In something I cloned, or wherever Claude happened to cd, that's not guaranteed. The working directory is a place I chose when I started the session, so it sits inside my circle of trust; "move somewhere else, then run git" steps one pace outside it.
Read that way, it makes sense that my git add rule didn't help. The rule answers "may git add run?" It doesn't answer "may the hooks in an unfamiliar directory run?"
The order I check things in, and a diagnosis table
When a prompt appears, I go through these in order.
- Read which command is being asked about. If it's
cdrather thangit, the "cdwithgit" row above is the likely match. - Check whether the
cdtarget is the working directory itself. You can see the current working directory at the bottom of the Claude Code screen or with/status. If they differ, that's your cause. - If they're the same and you still get prompted, suspect the shape of the command.
- If nothing explains it, open
/permissionsand check the spelling of saved rules and which layer they come from.
These are the shapes that most often trip step 3.
| Symptom | Likely cause | How to check | Fix |
|---|---|---|---|
The prompt asks about cd | git runs after a cd into a directory other than the working directory | Compare the cd target with where you started the session | Change where you start, or move the session with /cd (fixes 1 and 2 below) |
| "Don't ask again" doesn't stick | Only per-subcommand rules are saved; the judgment about the combination remains | Look at the saved rules in /permissions | Change the command shape so it has no cd, rather than adding rules |
Prompts on something like git add *.kt | An unquoted glob on a command with write-capable flags (which includes git) | Look for a bare * | Name paths explicitly, or quote the pattern |
Prompts on cd app; grep -r foo . > out.txt | The redirect target can't be resolved after the cd | Check whether the redirect target is relative | Use an absolute path, or drop the cd |
| One very long line; unclear what's being asked | Commands over 10,000 characters are beyond the analysis and always prompt | Measure the length | Ask for the steps to run separately |
Switched to git -C and now the rule doesn't match | Rules match command text; git -C . push doesn't match Bash(git push *) | Compare against the docs' "what a Bash rule doesn't match" table | Write the rule in the same form you use |
Five ways to cut the prompts
1. Start Claude Code inside the repository you want to work in
This felt the most reliable. The directory you start in is the working directory, so a cd to that directory isn't a prompt trigger.
# Prompt-prone: start in a parent folder and let Claude cd around
cd ~/dev && claude
# Quieter: start inside the repository you'll touch
cd ~/dev/wallpaper-app && claudeStarted the second way, Claude tends to emit git add src/Main.kt && git commit -m "..." with no cd, and your git allow rules apply as written. If you work across several repositories, splitting sessions per repository is the plain answer.
2. If you move mid-session, move the session itself with /cd
When I want to switch repositories partway through, I don't let Claude cd; I type /cd <path> and move the session's working directory. Per the docs, /cd keeps the conversation, switches the primary working directory, and loads the new directory's CLAUDE.md, its project permission rules and hooks, its .mcp.json servers, and so on. If you haven't worked there before, you're asked to trust the workspace.
/cd ~/dev/healing-soundsI take on the trust check once, and from then on git runs inside the working directory, so the cd-plus-git judgment doesn't come up. The docs also note that before v2.1.246, /cd didn't apply the new directory's settings or hooks until you resumed the session. If you're on an older build, updating is probably the quickest first step.
3. If you need two places side by side, add a directory
When you truly need to touch two repositories at once, add the second with --add-dir or /add-dir first. A cd inside an additional directory counts as read-only.
Two cautions. First, the docs say cd with git prompts when it "changes into a different directory." Whether moving into an additional directory counts, I can't say for certain from the wording, so I'd test it once before relying on it. Second, a path listed in permissions.additionalDirectories in a settings file only grants file access; that directory's configuration isn't loaded. Directories added by flag or command are treated differently.
4. Have the commands run separately instead of chained
If you're already inside the repository, simply asking for git add and git commit as separate commands often does it. Swapping cd for git -C <path> add ..., on the other hand, may not match your rules: the docs show that a deny rule for Bash(git push *) doesn't catch git -C . push. A different form isn't guaranteed to match the same rule. If you switch forms, write your allow rules in that form. It's also worth remembering that running git elsewhere via -C is, from a hooks point of view, no different from cd-ing there first.
5. Allow it with a PreToolUse hook — paired with a deny
If you really want the cd form to go through, a PreToolUse hook can return allow for a short list of trusted repositories and a few git subcommands. The issue comments suggest this, and one comment adds a caution: if a hook auto-allows cd x && <read-only> chains, it should deny destructive chains like cd x && rm -rf ... as the mirror image, or the fast lane becomes a dangerous lane. That's the point I agreed with most.
Here's the script I wrote with that in mind. What it solves: it lets "cd into a trusted repository, then only status/diff/log/show/add/commit" through, and for anything else it returns nothing, handing the call back to the normal flow.
#!/usr/bin/env python3
# ~/.claude/hooks/cd_git_gate.py
# PreToolUse hook: allow only "cd <trusted repo> && git <limited subcommands>"
import json, os, re, shlex, sys
TRUSTED_REPOS = {os.path.realpath(os.path.expanduser(p)) for p in [
"~/dev/wallpaper-app",
"~/dev/healing-sounds",
]}
SAFE_GIT = {"status", "diff", "log", "show", "add", "commit"}
def decide(decision, reason):
print(json.dumps({"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": decision,
"permissionDecisionReason": reason,
}}))
sys.exit(0)
cmd = json.load(sys.stdin).get("tool_input", {}).get("command", "").strip()
m = re.fullmatch(r"cd\s+(\S+)\s*&&\s*(.+)", cmd, re.S)
if not m:
sys.exit(0) # different shape: say nothing, normal flow decides
rest = m.group(2)
if re.search(r"\brm\s+-[A-Za-z]*[rRf]", rest):
decide("deny", "cd chained with recursive delete is blocked by hook")
target = os.path.realpath(os.path.expanduser(m.group(1).strip("'\"")))
if target not in TRUSTED_REPOS:
sys.exit(0)
if re.search(r"[;|`$<>\n&]", rest.replace("&&", " ")):
sys.exit(0) # other separators or substitutions: don't judge
for part in rest.split("&&"):
try:
t = shlex.split(part)
except ValueError:
sys.exit(0)
if len(t) < 2 or t[0] != "git" or t[1] not in SAFE_GIT:
sys.exit(0)
decide("allow", f"git in trusted repository {target}")Register it with an if so it only spawns for commands that contain a cd.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"if": "Bash(cd *)",
"command": "python3 ~/.claude/hooks/cd_git_gate.py"
}
]
}
]
}
}Feeding sample inputs to the decision logic gives this (output from running it on Linux with Python 3):
cd ~/dev/wallpaper-app && git add src/Main.kt && git commit -m "..." → allow
cd ~/dev/wallpaper-app && git push origin main → nothing (normal prompt)
cd ~/dev/other && git status → nothing (not trusted)
cd ~/dev/wallpaper-app && rm -rf build → deny
cd ~/dev/wallpaper-app && git status; curl ... → nothing (other separator)
cd ~/dev/wallpaper-app && git -C /tmp status → nothing (-C isn't in SAFE_GIT)Three notes on why it's written this way. I left out push, because anything that reaches a shared remote is something I'd rather see every time. Every shape it can't judge falls through to "say nothing": as the hooks page puts it, a hook that exits 0 with no output has no decision, and the call continues through the normal permission flow — so when in doubt, you land back on the prompt, which is the safe side. And a hook's allow doesn't override deny or ask rules: the docs say a matching deny rule still blocks and a matching ask rule still prompts even when the hook returned allow. That means you can keep what you truly want stopped in deny rules alongside this hook.
Whether the prompt actually disappears with this hook in place may vary by version, so I'm leaving that as unconfirmed. After installing it, I'd try one chain that should prompt and one that shouldn't before relying on it.
Comparing the five fixes
| Fix | Effort | Safety | Best when |
|---|---|---|---|
| 1. Start inside the repo | Just change how you launch | High (no permissions widened) | The work stays in one repository |
2. Move with /cd | One line per move | High (you own the trust check) | One session visiting several repositories in turn |
| 3. Additional directory | Once, up front | Medium (file access widens) | Reading and writing two places at once |
| 4. Separate commands | Depends on how you ask Claude | High | You're already inside the repository |
| 5. Hook | A script to maintain | Depends on the script (needs the paired deny) | A fixed handful of repositories where you must keep the chained form |
If you're unsure: one repository, use 1; visiting several in turn, use 2; treat the hook as the last resort. Most of the time the prompts drop once the work happens in the right place, and keeping hooks for the cases placement can't solve is kinder to whoever reads the config six months later — usually me.
Common misreadings
"Writing 'don't use cd' in CLAUDE.md will stop it." Writing it can nudge the shape of commands Claude produces; one commenter on the issue wrote it in capitals and reported roughly half as many prompts. But the docs are explicit that rules are enforced by Claude Code, not the model, and CLAUDE.md doesn't change what's allowed. If you want the approval behavior to change, change settings and where the work happens, not instructions.
"Adding Bash(cd *) to allow will quiet it." cd is already on the read-only list, and a move inside the working directory doesn't prompt. What prompts is the cd-with-git combination, so allowing cd doesn't change that judgment, as far as I can read. And a broad allow rule is how you lose track of what you've permitted.
"'Don't ask again' remembers the whole chain." The docs say it saves per-subcommand rules, up to five, and a cd outside your working directories becomes a Read rule for that path. Neither removes the judgment that applies when cd and git are combined.
Where you're likely to get stuck next
Once the prompts drop, you may hit a different one: "I added an allow rule and this other command still prompts." Then it helps to start by reading, in /permissions, which layer (user, project, local, managed) a rule comes from. I walked through that in I Added the allow Rule and the Prompt Still Appears — Reading Six Layers from /permissions.
It's also worth auditing now and then whether pressing "don't ask again" has left overly broad rules behind. My notes from rereading my own settings file are in The Settings File I Kept Saying Yes To Had a Rule That Let Any Python Through. And if you'd rather Claude not commit at all, I wrote about stopping it with deny rules and a hook instead of stronger instructions in I Wrote "I'll Do the Commits" in CLAUDE.md. The Next Morning git log Had One More Line..
What I'd avoid
Besides Bash(cd *), the other thing I'd avoid is "adding every repository as an additional directory because prompts are tedious." The area Claude can read and write widens all at once, and wherever Claude cds becomes "inside." You'd see fewer prompts, but tracing what was touched after something goes wrong gets harder.
Don't widen permissions to reduce the number of prompts. I cut prompts by changing where the work happens and keep the permissions narrow — that's the line I hold as I move between my wallpaper and healing-sounds app repositories.
The next time the approval screen appears, read the command it names, character by character — is it git or cd? If it's cd, try changing where you start, or /cd, before you touch your settings.