[BUG] SSH fails with "No user exists for uid 501" in background/agent-view mode, but works fine in standalone CLI
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
## Summary
SSH (and any command calling getpwuid()) fails in the Bash tool with:
No user exists for uid 501
This ONLY happens in agent view / background job mode. Running the same SSH command in a standalone claude CLI session works fine.
## Reproduction
- macOS (Darwin 23.6.0)
- Launch Claude Code in agent view (background job / subagent)
- Run any SSH command via the Bash tool:
ssh user@host -i ~/.ssh/key "echo hello"
- Result:
No user exists for uid 501(exit code 255)
Works fine: The exact same command succeeds in a standalone claude session (not agent view).
## Root cause
The agent-view / background-job process appears to run in a more restricted environment where Directory Services is inaccessible. getpwuid(501) fails at the C library level, and SSH exits immediately on init.
Verified:
```python
import os, pwd
pwd.getpwuid(os.getuid()) # KeyError in agent view, succeeds in standalone
dangerouslyDisableSandbox: true does not help — the restriction is at the process environment level, not the sandbox layer.
Expected behavior
Agent view / background jobs should have the same system call access as standalone CLI sessions, or provide a way to opt out of the additional restrictions.
Environment
- macOS 14.x (Darwin 23.6.0)
- Claude Code (latest)
- Agent view / background job mode
What Should Happen?
need to allow it ssh <host> in agent view mode
Error Messages/Logs
Steps to Reproduce
macOS (Darwin 23.6.0)
- Launch Claude Code in agent view (background job / subagent)
- Run any SSH command via the Bash tool:
ssh user@host -i ~/.ssh/key "echo hello"
Result: No user exists for uid 501 (exit code 255)
- Works fine: The exact same command succeeds in a standalone claude session (not agent view).
Claude Model
_No response_
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.144
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
_No response_