opencode-bash-background-process-survival
БесплатноБез исполняемых скриптовНе проверенDiagnose and fix backgrounded processes (dev servers, nohup'd jobs) that get KILLED when the bash tool's command terminates, completes, or times out — even…
от ericmjl★ 45 звёзд на GitHubОб этом скилле
Opencode Bash Background Process Survival
Diagnose and fix backgrounded processes (dev servers, nohup'd jobs, long-running commands) that get KILLED when the opencode bash tool's command terminates, completes, or times out — even though they were started with 'nohup ... & disown'. Use when: you backgrounded a server/process with 'nohup cmd >log 2>&1 & disown' and it died by the next turn or when the launching command timed out; the dev server you started last turn returns connection refused / curl 000; 'shell tool terminated command after exceeding timeout' appears and the backgrounded PID is gone; you need a process to survive across multiple bash-tool turns on macOS; or you are about to add more 'disown' / 'nohup' flags hoping to make a backgrounded job survive (disown alone is insufficient). ROOT CAUSE: 'disown' detaches a job from the shell's JOB TABLE but does NOT move it to a new process group/session; when the bash tool terminates its command (on normal completion OR timeout), SIGTERM/SIGKILL is delivered to the entire PROCESS GROUP, and the disowned child shares that group and dies with it. macOS does NOT ship 'setsid' (no easy 'setsid cmd &' like Linux). FIX (robust macOS pattern): the subshell double-fork — '( nohup cmd >log 2>&1 & )' — the parentheses spawn a subshell that backgrounds the child then EXITS immediately, orphaning the child which gets reparented to launchd (PID 1); combined with nohup (ignores SIGHUP) and redirected stdio, the child survives the parent shell's death AND the bash tool's process-group signal. Verify with 'ps -p
The failure, step by step
The opencode bash tool runs each command in a shell. When that command finishes (or the tool kills it on timeout), the tool terminates the process group, not just the lead process:
- You run
nohup my_server > /tmp/srv.log 2>&1 & disownand capture PID$!. disownremoves the job from the shell's job table (so the shell won't send it SIGHUP on exit, andjobswon't list it).- But
disowndoes NOT create a new process group or session. The backgrounded child still shares the shell's process group (PGID). - The bash tool terminates the command → SIGTERM/SIGKILL is delivered to the whole process group → your "detached" child dies with it.
- Next turn:
curl localhost:PORTreturns000(connection refused),ps -p <pid>shows nothing. Thedisowngave a false sense of safety.
The string shell tool terminated command after exceeding timeout in the tool output is the smoking gun: the timeout kill took the process group, and your server with it.
The fix: subshell double-fork
macOS does not ship setsid (the Linux one-liner setsid cmd &). The macOS-equivalent robust pattern is the subshell double-fork:
mkdir -p /tmp/srv-logs
( nohup my_server > /tmp/srv-logs/srv.log 2>&1 & echo $! > /tmp/srv-logs/srv.pid )
Why this works:
- The
( ... )runs the body in a subshell. - Inside,
nohup cmd &backgrounds the child in the subshell, and the subshell writes the PID to a file then exits immediately. - When the subshell exits, the child is orphaned and reparented to launchd (PID 1).
nohupmakes it ignore SIGHUP; the redirected stdio detach it from the tool's pipe.- Because the child is now a child of launchd in its own reparented state, it is outside the bash tool's process group and survives the tool's group-wide signal.
This is the pattern that makes a server survive across many turns. (setsid would also work if installed; brew install util-linux provides it — but the subshell pattern needs no extra install and is the portable macOS default.)
Verification (do this every time, on the NEXT turn)
PID=$(cat /tmp/srv-logs/srv.pid); ps -p "$PID" && echo "ALIVE" || echo "DEAD"
curl -sS -o /dev/null -w "%{http_code}\n" --max-time 5 http://localhost:PORT
If ps -p reports DEAD or curl returns 000, the detachment failed — re-launch with the subshell pattern.
Common variants
Lektor preview server (website repo, two worktrees, two ports):
mkdir -p /tmp/lektor-dev
( cd /Users/ericmjl/github/website/worktree-a && nohup /Users/ericmjl/github/website/.pixi/envs/default/bin/lektor server -p 5001 -h 0.0.0.0 > /tmp/lektor-dev/a.log 2>&1 & echo $! > /tmp/lektor-dev/a.pid )
Note /tmp/ is cleared on reboot — always mkdir -p the log dir
Установить opencode-bash-background-process-survival в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл opencode-bash-background-process-survival?
Diagnose and fix backgrounded processes (dev servers, nohup'd jobs) that get KILLED when the bash tool's command terminates, completes, or times out — even when started with nohup & disown. Use when: a backgrounded server died by the next turn or when the launching command timed out; the dev server started last turn returns connection refused / curl 000; 'shell tool terminated command after exceeding timeout' appears and the PID is gone; you need a process to survive across multiple bash-tool turns on macOS; or about to add more disown/nohup flags hoping to make a job survive (insufficient alone). ROOT CAUSE: disown detaches from the job table but NOT the process group; the bash tool signals the whole group on termination. FIX: the subshell double-fork '( nohup cmd >log 2>&1 & )' — the subshell exits immediately, orphaning the child to launchd (PID 1); verify with 'ps -p <pid>' next turn. Lookalike distinctions live in the body.
Как установить скилл opencode-bash-background-process-survival?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл opencode-bash-background-process-survival запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic