Where does the bug appear (feature/product)?
Cursor IDE
Describe the Bug
In a Cursor workspace containing multiple Git repositories, the Shell tool’s working_directory parameter does not reliably re-root the command in the target repository. Commands — especially git — silently keep operating on the first repository listed in the workspace (the “primary” workspace root), even when an absolute path to a sibling repo is passed as working_directory.
This means that when the user asks the agent about a commit / branch / file that only exists in a non-primary repo, the agent gets fatal: bad object <sha>, “branch not found”, etc., and has no obvious feedback that its working_directory was effectively ignored. The agent then spends a lot of tokens hunting for something in a repo that can never contain it. The only reliable workaround is to avoid the working_directory parameter entirely and inline cd /absolute/path && <cmd> instead.
Bonus: the Shell tool’s post-amble cheerfully reports Current directory: /absolute/path/to/sibling-repo even when the spawned process clearly didn’t run there — so the agent has no signal that anything went wrong.
Steps to Reproduce
- Open a Cursor workspace whose
Workspace Pathslist contains at least two separate Git repos — e.g.repo-Alisted first,repo-Blisted second. (At Datadog this is normal: we routinely havedd-source,web-ui,browser-sdk, etc. all in one workspace.) - Make sure each repo has commits the other does not.
- Start a fresh chat. Ask the agent something only
repo-Bcan answer, e.g.:In
repo-B, what does commit<sha that only exists in repo-B>change? - (Optional, to make this even more egregious) Explicitly warn the agent in the prompt that the workspace root is
repo-Aand that it must navigate torepo-Bfirst. - Watch the agent call
Shellwithworking_directory: /abs/path/to/repo-Band agit show <sha>/git log …command. - Observe that the output is from
repo-A: wrong branch, wrong commits, wrong untracked files, orfatal: bad object. The post-amble still saysCurrent directory: /abs/path/to/repo-B. - Have the agent instead run
cd /abs/path/to/repo-B && git show <sha>inline (noworking_directoryparameter) — and observe it now works.
Expected Behavior
When working_directory is set on a Shell call:
- The spawned process’s CWD should actually be that directory, so
git(and any other CWD-sensitive tool) operates on the repo at that path. - If for any reason CWD can’t be set, the tool should fail loudly instead of silently running against the workspace root.
- The post-amble’s
Current directory:line should reflect the actual CWD of the executed command (e.g.pwdafter the command), not just echo back the requestedworking_directory.
Operating System
MacOS
Version Information
Version: 3.5.17 (Universal)
VSCode Version: 1.105.1
Commit: d5b2fc092e16007956c9e5047f76097b9e626ca0
Date: 2026-05-20T02:43:31.559Z
Layout: glass
Build Type: Stable
Release Track: Default
Electron: 39.8.1
Chromium: 142.0.7444.265
Node.js: 22.22.1
V8: 14.2.231.22-electron.0
OS: Darwin arm64 25.5.0
For AI issues: which model did you use?
claude-opus-4-7-thinking-xhigh
Additional Information
Observed evidence from a real session
Workspace (anonymized — real session had 7 sibling repos under one parent directory):
Workspace Paths:
- /Users/<me>/code/repo-A ← primary
- /Users/<me>/code/repo-B
- /Users/<me>/code/repo-C
- /Users/<me>/code/repo-D
- /Users/<me>/code/repo-E
- /Users/<me>/code/repo-F
- /Users/<me>/code/repo-G
User asked about commit <sha-in-repo-B> in repo-B and pre-warned the agent that the current working directory was misleading.
- Shell call:
git status && git branch --show-current && git log --oneline -10
working_directory: /Users/<me>/code/repo-B
→ Branch reported was the branch checked out inrepo-A, notrepo-B. Untracked files matched therepo-Agit_statusblock from the system prompt, notrepo-B’s. - Shell call:
git worktree listwith the sameworking_directory.
→ Returnedrepo-A’s worktrees. - Reading
/Users/<me>/code/repo-B/.git/HEADdirectly confirmed the repo was on a different branch than what the earliergit statusreported — i.e. those git calls clearly hadn’t run insiderepo-Bat all. - Shell post-amble said
Current directory: /Users/<me>/code/repo-B, but runningenvlater revealedPWD=/Users/<me>/code/repo-AandOLDPWD=/Users/<me>/code/repo-A. So the post-amble’s “Current directory” line is misleading — it appears to echo the requestedworking_directory, not the actual session CWD. - Once the agent switched to
cd /Users/<me>/code/repo-B && git show <sha>inline, the command immediately worked and resolved the commit.
So in this session: every git invocation that relied on working_directory ran against the wrong repo; every inline-cd version worked.
Why this matters
Multi-repo Cursor workspaces are common in monorepo-adjacent setups (frontend repo + backend repo + SDK + tooling, all open at once). When the user asks about anything in a non-primary repo, the agent:
- Gets
fatal: bad object, branch-not-found, or empty results. - Has no diagnostic signal that its
working_directorywas effectively ignored (the tool tells it the CWD is fine). - Spirals: tries
--all, walks worktrees, fetches, even doubts whether the user remembered the SHA correctly. - Burns a large number of tokens before stumbling onto inline
cdas a workaround.
Even when the user explicitly pre-warns the agent (as in this session), the agent still gets tricked because it trusts the Shell tool’s reported Current directory: line.
Suggested fixes
- Make
working_directoryactually change the spawned process’s CWD (or fail loudly if it can’t), so child processes —gitin particular — see the right repo. - Change the Shell post-amble’s
Current directory:line to be derived from a realpwdafter the command, not from the requestedworking_directory. - Optionally: when a workspace contains multiple git repos, document in the Shell tool description that
working_directoryis per-call only and that inlinecdis the safer pattern for chained git commands.
Does this stop you from using Cursor
No - Cursor works, but with this issue