Repository navigation
Description
Problem. With zsh as the shell OpenCode uses (SHELL=…/zsh), a Cursor background shell (Shell with block_until_ms: 0) runs in the foreground under OpenCode 2.2.7 and later. The tool call blocks until the command ends, or until OpenCode's tool timeout kills it (signal: SIGTERM, timeout: true), and no terminals/<id>.txt record and no background-shell note is written. bash is not affected.
Cause. OpenCode 2.2.7+ starts zsh as zsh +o nomatch -c <command> (ShellSelect.args; other POSIX shells get -c <command>). The adapter prepareCursorShellCreate writes (src/shell-timeout.ts, on main 2ea6994 line 550) wraps the command only when "$1" = -c && "$2" = <command>, so for zsh it falls through and the host shell runs the launcher itself.
Repro. OpenCode 2.3.0 with this provider, SHELL pointing at zsh, any model. Prompt: "Use your Shell tool with block_until_ms set to 0 to start this exact command in the background: sleep 15; echo cp13-done. Then wait for it to finish (AwaitShell), and report its exit code and its output." CURSOR_PROVIDER_DEBUG=1:
bash (detaches within a second):
[05:39:17.707Z] exec: id=0 … toolName=shell resultField=background_shell_spawn_result
[05:39:18.112Z] background shell: watching shell=961180 pid=… file="…/terminals/961180.txt"
[05:39:18.183Z] continuation: wrote exec result execId=0 field=background_shell_spawn_result frames=2 outLen=177
zsh (the spawn call runs the whole command):
[05:39:17.557Z] exec: id=0 … toolName=shell resultField=background_shell_spawn_result
[05:39:18.458Z] exec heartbeat: id=0 tool=shell n=1
… n=2 … n=5
[05:39:32.939Z] continuation: wrote exec result execId=0 field=background_shell_spawn_result frames=2 outLen=10
With OpenCode 2.2.6 and the same zsh setup the call detaches. On a machine whose login shell is zsh, after moving OpenCode 2.2.6 → 2.3.0: 12 background shells in 13 h, 8 killed by the tool timeout, 4 run to the end in the foreground, 0 terminal records, 0 notes (25 detached before the move).
Fix (happy to open a PR): match -c <command> as the adapter's last two arguments, and pass the options before it (+o nomatch) on to the detached payload, so a background command keeps the same zsh semantics as a foreground one. One commit on your main 2ea6994, with tests: main...nkoynov:cursor-opencode-provider:pr/zsh-background-shell. Checked with OpenCode 2.3.0 and the stub, one background sleep 20: on main, zsh blocks for the whole sleep and then fails with "OpenCode did not return a valid background shell process id"; with the fix it detaches in about 0.5 s. bash detaches in about 0.4 s on both. bun test has the same 90 failures as main (review harness and sandbox tests); the new tests fail on main.
Model and harness: Claude Opus 5.5 through OpenCode 2.3.0, on NixOS.
Activity
fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…
fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…
fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…