Where does the bug appear (feature/product)?
Cursor IDE
Describe the Bug
Environment
- macOS:
darwin 25.1.0 - Shell:
zsh - Cursor: using AI agents + git worktrees (but repro is not specific to worktrees)
- Agent commands are executed via something like
zsh -lc '…'inside a sandbox
Summary
When Cursor’s AI agent runs shell commands that include cd, they often fail with:
(eval):1: cd: function definition file not found
This happens even for simple, valid commands such as:
cd /some/dir && pnpm lint
The root cause appears to be how Cursor configures zsh inside the sandbox: cd is turned into an autoload stub function without a backing definition in $FPATH, so any cd call fails.
Steps to reproduce
In a Cursor AI agent task (or via the internal sandbox terminal), run:
cd / && pwd
or from a tool-like context (what I see in logs):
cd /Users/<user>/.cursor/worktrees/<repo>/<worktree>/functions && pnpm lint
Observed in sandbox:
- Inspect
cd:
functions cd 2>/dev/null | sed -n '1,5p'
type cd
Output:
cd () {
# traced
builtin autoload -XUz
}
cd is a shell function from zsh
cd is a shell builtin
cd is /usr/bin/cd
- Try to use
cd:
cd / && pwd
Output:
(eval):1: cd: function definition file not found
- But explicitly calling the builtin works:
builtin cd / && pwd
# → / (works correctly)
In a normal terminal on the same machine (outside Cursor), cd is just a builtin and works fine.
Expected behavior
-
cdshould work normally in the agent shell (as a builtin or a valid function wrapper), so commands like:cd <path> && pnpm lintdo not fail with
function definition file not found.
Actual behavior
-
Inside Cursor’s sandbox shell:
-
cdis a function stub:cd () { # traced builtin autoload -XUz } -
There is no corresponding function file for
cdin$FPATH(e.g. no/usr/share/zsh/5.9/functions/cd*), soautoload -XUzfails and everycdinvocation produces:cd: function definition file not found -
Workaround
builtin cd <dir>works, but standardcddoes not.
-
Notes / Analysis
-
My personal zsh config (
~/.zshenv,~/.zprofile,/etc/zsh*,~/.oh-my-zsh, etc.) does not definecdor autoload it. In a cleanzsh -lcoutside Cursor,type cdshows only the builtin and nofunctions[cd]entry. -
The autoload stub:
cd () { # traced builtin autoload -XUz }is typical of
functions -t cd(zsh tracing) or similar, so it looks like Cursor’s own sandbox setup is enabling function tracing forcd, but there is no actualcdfunction file in$FPATH. -
Because this setup happens after user dotfiles (
~/.zshenv) are processed, I cannot reliably override/fixcdfrom my config for the agent shell.
Suggested fixes
Any of these would resolve the issue:
-
Don’t trace
cd(avoid turning it into an autoload stub), or -
Provide a real
cdfunction file in$FPATHif you want to trace it, or -
After enabling tracing, explicitly restore
cdto a safe wrapper, e.g.:cd() { builtin cd "$@"; }
Until it’s fixed, a reliable workaround on the agent side is to always use builtin cd in commands, e.g.:
builtin cd /Users/<user>/.cursor/worktrees/<repo>/<worktree>/functions && pnpm lint
—but it would be much better if cd just worked normally inside the Cursor agent shell.
Steps to Reproduce
described in Describe the Bug section
Expected Behavior
described in Describe the Bug section
Operating System
MacOS
Current Cursor Version (Menu → About Cursor → Copy)
Version: 2.1.19
VSCode Version: 1.105.1
Commit: 39a966b4048ef6b8024b27d4812a50d88de29cc0
Date: 2025-11-21T22:59:02.376Z (14 hrs ago)
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Darwin arm64 25.1.0
For AI issues: which model did you use?
gpt 5.1, sonnet and maybe others
For AI issues: add Request ID with privacy disabled
Request ID: f96ad866-18cf-4338-8668-a5a416927388
Does this stop you from using Cursor
No - Cursor works, but with this issue