[Bug] PWD randomly changes to sandbox temp directory after /add-dir
Bug Description
Updated claude cli today (to get the new spinner verbs!) and noticed two issues:
- /add-dir sometimes changes the PWD of claude commands, seems random and flakey.
- Claude running tools in our configured /tmp/claude path randomly also report missing PWD or wrong PWD even if the commands run successfully.
My hunch is that some race condition/bug in the CLI was introduced that causes the PWD to be set incorrectly. Full report generated by claude below ---
Bug Report: PWD randomly changes after /add-dir causing sandbox permission errors
Summary
After updating Claude Code CLI today (2026-01-29), the working directory (PWD) randomly changes to temporary sandbox directories (/tmp/claude-502/cwd-*) causing "operation not permitted" errors on every bash command execution, even though commands still produce output.
Environment
- Claude Code Version: 2.1.23
- OS: macOS Darwin 24.6.0 (ARM64)
- Shell: zsh
- Date Issue Started: 2026-01-29 (immediately after executable update)
Trigger
The issue appears to be triggered by the /add-dir command during the session.
Expected Behavior
- PWD should remain stable in the actual working directory
- Bash commands should execute without permission errors
- The sandbox temporary directory should not become the working directory
Actual Behavior
Every bash command shows an error like:
zsh:1: operation not permitted: /tmp/claude-502/cwd-XXXX
Where XXXX is a random hex string that changes with each command execution.
Despite the error, commands still execute and return output, but this causes significant issues:
makecommands fail- Error messages clutter output
- Commands that depend on stable PWD may behave incorrectly
Steps to Reproduce
- Start a new Claude Code session
- Run
/add-dircommand to add a directory to context - Execute any bash command
- Observe "operation not permitted" error on
/tmp/claude-502/cwd-*paths
Example Output
$ pwd
zsh:1: operation not permitted: /tmp/claude-502/cwd-4eb8
/Users/jlmiller/src/crusoeenergy/devx/claude/config
$ cat Makefile
zsh:1: operation not permitted: /tmp/claude-502/cwd-ea49
[Makefile contents still display correctly]
$ make sort
zsh:1: operation not permitted: /tmp/claude-502/cwd-3ea6
[make command fails]
Additional Context
This repository uses enterprise-managed sandbox settings with:
sandbox.enabled: trueautoAllowBashIfSandboxed: true- Various commands in
excludedCommandsincludingmake,git,uv, etc.
The issue appears to be related to how Claude Code manages the working directory in sandbox mode, particularly after /add-dir operations.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.23
- Feedback ID: f457ccaa-38b6-4291-b46d-c890612b8aa0
Errors
[]This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗