[BUG] Bash tool intermittently emits child setpgid (...): Operation not permitted on macOS
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?
Description
Claude Code 2.1.258 intermittently emits the following warning during Bash tool execution on macOS:
child setpgid (...): Operation not permitted
The warning appears to be caused by Claude Code restoring interactive shell job-control settings into non-interactive Bash executions.
The issue has been reproduced independently of Claude Code.
Steps to reproduce
On macOS, run:
for i in {1..1000}; do
bash -c 'set -o monitor; yq -n ".a=1" >/dev/null'
done
The warning occurs intermittently, approximately once every 300 iterations in the tested environment.
Root cause
Investigation indicates the following sequence:
- Claude Code captures the interactive shell state in
~/.claude/shell-snapshots/snapshot-bash-*.sh. - The snapshot includes
set -o monitor(job control), inherited from the interactive terminal. - The Bash tool restores this option when executing non-interactive
bash -ccommands. - With monitor mode enabled, Bash performs process-group management using
setpgid()when launching external commands. - On macOS, this can produce an intermittent
EPERMerror, apparently due to a race involving the child process. - Bash prints the diagnostic to stderr.
The standalone reproduction establishes that enabling monitor mode is sufficient to trigger the warning without Claude Code being involved. The precise cause of EPERM has not been independently verified through system-call tracing.
Expected behavior
The Bash tool should not inherit interactive job-control settings that are inappropriate for non-interactive command execution.
Ordinary commands should execute without unrelated process-group diagnostics.
Actual behavior
The Bash tool intermittently emits child setpgid (...): Operation not permitted during otherwise successful command execution.
In the observed reproductions, commands completed successfully despite the warning. No functional failure has been demonstrated, although effects on process-group management and signal handling have not been ruled out.
Workaround
Disabling monitor mode prevents the warning:
set +m
This can be applied at the beginning of an affected Bash invocation.
Suggested fix
When restoring shell-state snapshots for non-interactive Bash tool execution, exclude or explicitly disable interactive job-control mode (monitor).
This should be handled centrally by Claude Code rather than requiring users to add set +m to individual commands.
Environment
- Claude Code: 2.1.258
- OS: macOS
- Shell: Bash
- Reproduction: Intermittent, approximately 1 in 300 iterations
Related issue
- https://github.com/anthropics/claude-code/issues/19057 — Related shell-snapshot restoration problem involving
monitor, but not this macOSsetpgid()diagnostic.
What Should Happen?
-
Error Messages/Logs
Steps to Reproduce
-
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.299
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_