Fix: Tool Execution Failed with Exit Code 127
Error Message:
"Tool execution failed with exit code 127." "zsh: command not found: git" "zsh: command not found: python3" "zsh: permission denied: claude"
What This Error Means
In Unix-based operating systems, Exit Code 127 is the standard exit status for "command not found". It means the shell tried to run a tool (such as git, npm, python3, or node), but that tool either:
- Is not installed on your system at all, or
- Is installed, but its path is not available in the
PATHenvironment variable when Claude Cowork's execution sandbox starts.
This is one of the most common errors for users who recently set up Claude Cowork on a fresh machine, or who use version managers like nvm, pyenv, or rbenv — because these tools add binaries to your shell PATH via .zshrc or .bashrc, which may not be sourced inside a sandboxed sub-shell.
Root Cause Analysis
Cause 1: The tool is not installed.
If you ask Claude to run git commit but Git is not installed on your machine, you will get exit code 127. This is the simplest case — the tool simply doesn't exist.
Cause 2: Version manager PATH not loaded.
Tools installed via nvm (Node.js), pyenv (Python), rbenv (Ruby), or volta live in paths like ~/.nvm/versions/node/v20.0.0/bin/. These paths are only added to your $PATH when your shell sources .zshrc. Claude's execution environment may not source that file, so it can't find the binary even though it's installed.
Cause 3: Tool installed with sudo into /usr/local.
On Apple Silicon Macs, Homebrew installs to /opt/homebrew/bin/ — not /usr/local/bin/. If Claude's PATH only includes /usr/local/bin/, it won't find Homebrew-installed tools.
Cause 4: Permission denied on the CLI binary.
The binary exists and is on PATH, but it does not have executable permissions set (chmod +x). This shows up as zsh: permission denied: claude rather than exit code 127, but the fix is similar.
Real-World Example
A developer asked Claude Cowork to run their project's build script: "Run npm install && npm run build and fix any TypeScript errors." Claude started, then immediately failed with exit code 127 on npm. The developer had installed Node.js via nvm, which adds npm to PATH via .zshrc. Claude's sandbox didn't source .zshrc, so it had no idea where npm was. The fix: provide the absolute path.
Step-by-Step Fix
Step 1: Verify the Tool Is Actually Installed
Open your system terminal (not inside Claude) and run:
which git
which npm
which python3
which node
If a command returns nothing (blank output), that tool is not installed. Install it first:
- Git:
brew install git(macOS) or download from git-scm.com - Node.js / npm: Download from nodejs.org or
brew install node - Python: Download from python.org or
brew install python
Step 2: Find the Absolute Path
Once you confirm the tool is installed, get its exact absolute path:
which git
# → /usr/bin/git (or /opt/homebrew/bin/git, or /usr/local/bin/git)
which npm
# → /Users/you/.nvm/versions/node/v20.11.0/bin/npm
Copy this full path — you will use it in the next step.
Step 3: Pass the Absolute Path in Your Prompt
In your Claude Cowork brief, explicitly tell Claude the location of the tool:
Run the build script. My local npm binary is at /Users/yourname/.nvm/versions/node/v20.11.0/bin/npm.
Please invoke it using the absolute path: /Users/yourname/.nvm/versions/node/v20.11.0/bin/npm install
This bypasses the PATH problem entirely by using a hardcoded path.
Step 4: Fix Executable Permissions (if "permission denied")
If you see zsh: permission denied (rather than exit code 127), the binary is missing the executable flag:
chmod +x /path/to/the/binary
For Claude's own CLI, if it's a wrapper script:
chmod +x /usr/local/bin/claude
Step 5: Fix npm Global Permission Issues
If you installed a CLI tool globally with npm and see permission errors, avoid using sudo. Instead, take ownership of the npm directories:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This lets npm install global packages without elevation, which avoids the permission/PATH split.
Step 6: Verify PATH in a Sub-Shell (Advanced)
To see exactly what PATH Claude's sandbox inherits, ask Claude to run:
echo $PATH
Compare the output with what you get in your own terminal. Any directories missing from Claude's output (e.g., ~/.nvm/versions/...) contain tools that Claude can't find by name. Use absolute paths for those tools.
Common Pitfalls
- Using
nvm,pyenv, orrbenv: These version managers rely on shell initialization files to setPATH. Claude's sandbox often doesn't run those scripts. Always use absolute paths for tools installed by version managers. - Apple Silicon Mac + Homebrew: Homebrew on Apple Silicon installs to
/opt/homebrew/bin/, not/usr/local/bin/. If Claude uses/usr/local/bin/, it won't find Homebrew tools. Use/opt/homebrew/bin/your-toolexplicitly. - Assuming
python=python3: On modern macOS,pythonmay not exist — onlypython3. Usepython3in your prompts, or use the absolute path. - Sudo-installed tools with different owners: Tools installed with
sudo npm install -grun under root and may not be on your user PATH.
Prevention Checklist
- Before starting a Cowork session involving CLI tools, run
which <toolname>to get its absolute path. - Keep a note of your commonly used absolute paths (Node, Python, Git) to paste into briefs quickly.
- If using
nvmorpyenv, find the stable version path and use absolute paths in briefs. - On Apple Silicon Mac, check if tools are in
/opt/homebrew/bin/(not/usr/local/bin/). - Avoid installing global tools with
sudo npm install -g. Usenpm config set prefixto a user-owned directory instead.