[Bug] PWD randomly changes to sandbox temp directory after /add-dir

Resolved 💬 3 comments Opened Jan 30, 2026 by jlmiller-crusoe Closed Jan 30, 2026

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

  1. PWD should remain stable in the actual working directory
  2. Bash commands should execute without permission errors
  3. 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:

  • make commands fail
  • Error messages clutter output
  • Commands that depend on stable PWD may behave incorrectly

Steps to Reproduce

  1. Start a new Claude Code session
  2. Run /add-dir command to add a directory to context
  3. Execute any bash command
  4. 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: true
  • autoAllowBashIfSandboxed: true
  • Various commands in excludedCommands including make, 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

[]

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗