[BUG] bash shell snapshot replays disabled `monitor`/`onecmd` options (`grep "on"` matches option names)

Status Open
Reported on v2.1.286
Maintainer reply None cached
Activity 0 comments · opened Oct 1, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

With CLAUDE_CODE_SHELL pointing at bash, the shell snapshot always contains set -o monitor and set -o onecmd, even though both options are off in the shell being captured.

The snapshot script collects options with:

set -o | grep "on" | awk '{print "set -o " $1}'

grep "on" matches any line containing the substring on, not lines whose value is on. The option names monitor and onecmd contain on, so their off lines pass the filter:

$ bash -c 'set -o | grep -E "^(monitor|onecmd)"'
monitor        	off
onecmd         	off
$ bash -c 'set -o | grep "on" | awk "{print \$1}"' | grep -E '^(monitor|onecmd)$'
monitor
onecmd

Because the snapshot is sourced before every Bash tool command, each non-interactive bash -c runs with job control enabled ($- is hmtBc inside the tool). bash then calls setpgid for children, and when that fails the warning below is mixed into the tool result. The commands themselves still complete correctly, but the noise appears in tool output that the model reads. Changing ~/.bashrc (e.g. set +m) cannot help, since the captured option list does not depend on the actual state.

What Should Happen?

Only options that are actually enabled should be replayed, e.g.:

set -o | awk '$2 == "on" {print "set -o " $1}'

(or set +o, which prints a restorable command list for every option).

Error Messages/Logs

/opt/homebrew/bin/bash: child setpgid (15871 to 15871): Operation not permitted

Steps to Reproduce

  1. Set "env": { "CLAUDE_CODE_SHELL": "/opt/homebrew/bin/bash" } in ~/.claude/settings.json (bash 5.3).
  2. Start a new session and run via the Bash tool: echo "$-" (shows m and t).
  3. Inspect the newest ~/.claude/shell-snapshots/snapshot-bash-*.sh: the # Shell Options section contains set -o monitor and set -o onecmd.
  4. Run ordinary commands (pipelines, command substitutions in loops); intermittently the child setpgid ... Operation not permitted warning appears in the tool result.

Claude Model

Not model-specific.

Is this a regression?

I don't know

Claude Code Version

2.1.286 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Additional Information

bash 5.3.20 (Homebrew), macOS 27.0. The zsh branch of the same script uses setopt, which is not affected.

View original on GitHub ↗