[BUG] Parallel Task agents share working directory state instead of maintaining isolation
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.100
- Operating System: macOS
- Terminal: Terminal App
Bug Description
When multiple Task agents run in parallel, they share the same working directory state instead of maintaining isolated working directory contexts. When one Task agent executes a cd command, it affects the working directory for all other parallel Task agents, causing subsequent cd commands to fail and file operations to execute in wrong directories.
Technical Analysis: Task agents share the same working directory variable. When any Task agent changes the working directory via cd, all other parallel agents are affected and start from that new directory instead of their expected starting point.
Steps to Reproduce
Prerequisites: Disable filesystem MCP for clear testing (to ensure the issue is isolated to Task agent behavior).
- Clone the reproduction test case:
``bash``
git clone https://github.com/PAN-Chuwen/claude-code-parallel-task-agents-working-directory-test.git
cd claude-code-parallel-task-agents-working-directory-test
- Run Claude CLI:
``bash``
claude
- Execute this exact prompt:
````
Analyze multiple environment configurations in parallel
Expected Behavior
Each Task agent should:
- Start from the project root directory independently
- Successfully navigate to its assigned directory (
cd working_dir1/,cd working_dir2/,cd working_dir3/) - Maintain isolated working directory context throughout execution
- Process files only in its intended directory without interference from other agents
Actual Behavior
Task agents' working directories get affected by other Task agents' cd commands:
Evidence from test execution with markers (working_dir1.marker files for clarity):
Task Agent 1 (assigned to working_dir1):
⎿ Bash(cd working_dir1/)
(No content)
Bash(pwd && ls -la)
/Users/.../working_dir1 ✓ Successfully navigated to working_dir1
total 24
-rw-r--r-- 1 user staff 23 Sep 2 14:14 working_dir1.marker ✓ Correct directory
Task Agent 2 (assigned to working_dir2):
⎿ Bash(cd working_dir2/ && pwd)
Error: (eval):cd:1: no such file or directory: working_dir2/
Bash(ls -la)
total 24
-rw-r--r-- 1 user staff 23 Sep 2 14:14 working_dir1.marker ❌ Shows working_dir1.marker
# Agent 2 is in working_dir1/ due to Agent 1's cd command
Task Agent 3 (assigned to working_dir3):
⎿ Bash(cd working_dir3)
Error: (eval):cd:1: no such file or directory: working_dir3
Bash(ls -la)
-rw-r--r-- 1 user staff 23 Sep 2 14:14 working_dir1.marker ❌ Shows working_dir1.marker
Bash(pwd)
/Users/.../working_dir1 ❌ Agent 3 is also in working_dir1/
Observed Behavior:
- Task Agent 1 successfully executes
cd working_dir1/and works correctly - Task Agents 2 & 3 inherit Agent 1's working directory change
- Both Agents 2 & 3 try
cd working_dir2/andcd working_dir3/but fail because they're starting from/working_dir1/instead of the project root - Affected agents attempt navigation with
cd ..andpwdcommands to find correct directories - File operations fail because agents are looking in the wrong directories
Additional Context
Root Cause: Task agents share the same working directory state within the Claude CLI session instead of having isolated execution contexts. When one Task agent changes the working directory, all other parallel agents are affected.
Real-World Impact: This breaks legitimate parallel processing workflows such as:
- Multi-environment testing and deployment
- Batch file processing across directories
- Build system operations requiring directory isolation
- Any directory-based parallel workflow with shared processing logic
Why Parallel Task Agents Are Needed: These workflows require shared context (common parameters, coordinated results, consistent business logic) that cannot be achieved with separate Claude CLI sessions, making parallel Task agents the natural solution.
Test Repository: https://github.com/PAN-Chuwen/claude-code-parallel-task-agents-working-directory-test
- Contains clean reproduction scenario with neutral task instructions
- Simple prompt: "Analyze multiple environment configurations in parallel"
- Consistently reproduces the working directory sharing issue
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗