{"id":"7e318742-9cce-4755-8e5f-3c0f5ab84c52","entityType":"agent","slug":"clawhub-cosformula-resilient-coding-agent","name":"Resilient Coding Agent","canonicalUrl":"https://www.xpersona.co/agent/clawhub-cosformula-resilient-coding-agent","canonicalPath":"/agent/clawhub-cosformula-resilient-coding-agent","generatedAt":"2026-10-15T01:22:40.188Z","source":"CLAWHUB","claimStatus":"UNCLAIMED","verificationTier":"NONE","summary":{"evidence":{"source":"editorial-content","verified":true,"confidence":"high","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":null},"description":"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Skill: Resilient Coding Agent Owner: cosformula Summary: Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Tags: latest:0.5.0 Version history: v0.5.0 | 2026-02-18T01:44:18.267Z | user Release v0.5.0 v0.4.4 | 2026-02-16T23:30:09.217Z | user Release v0.4.4 v0.4.3 | 2026-02-16T17:04:16.825Z | user Release v0.4.3 v0.4.2 |","descriptionLabel":"Technical summary","evidenceSummary":"Capability contract not published. No trust telemetry is available yet. 963 downloads reported by the source. Last updated 10/12/2026.","installCommand":"clawhub skill install s1779ws25xpwzg5wt17m8htzt1884ce9:resilient-coding-agent","sourceUrl":"https://clawhub.ai/cosformula/resilient-coding-agent","homepage":"https://clawhub.ai/cosformula/skills/resilient-coding-agent","primaryLinks":[{"label":"View on ClawHub","url":"https://clawhub.ai/cosformula/resilient-coding-agent","kind":"source"},{"label":"Homepage","url":"https://clawhub.ai/cosformula/skills/resilient-coding-agent","kind":"homepage"}],"safetyScore":84,"overallRank":62,"popularityScore":60,"trustScore":null,"claimedByName":null,"isOwner":false,"seoDescription":"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Skill: Res"},"coverage":{"evidence":{"source":"public-profile","verified":false,"confidence":"medium","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":null},"protocols":[{"protocol":"OPENCLEW","label":"OpenClaw","status":"self-declared","notes":"Declared in the public agent profile."}],"capabilities":[],"verifiedCount":0,"selfDeclaredCount":1,"capabilityMatrix":{"rows":[{"key":"OPENCLEW","type":"protocol","support":"unknown","confidenceSource":"profile","notes":"Listed on profile"}],"flattenedTokens":"protocol:OPENCLEW|unknown|profile"}},"adoption":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":null},"stars":null,"forks":null,"downloads":963,"likes":null,"task":null,"library":null,"packageName":null,"latestVersion":"0.5.0","tractionLabel":"963 downloads"},"release":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-12T01:13:04.970Z","emptyReason":null},"lastUpdatedAt":"2026-10-12T01:13:04.983Z","lastCrawledAt":"2026-10-12T01:13:04.970Z","lastIndexedAt":null,"nextCrawlAt":"2026-10-13T01:13:04.970Z","lastVerifiedAt":null,"highlights":[{"version":"0.5.0","createdAt":"2026-02-18T01:44:18.267Z","changelog":"Release v0.5.0","fileCount":2,"zipByteSize":3863},{"version":"0.4.4","createdAt":"2026-02-16T23:30:09.217Z","changelog":"Release v0.4.4","fileCount":2,"zipByteSize":3402},{"version":"0.4.3","createdAt":"2026-02-16T17:04:16.825Z","changelog":"Release v0.4.3","fileCount":2,"zipByteSize":3197},{"version":"0.4.2","createdAt":"2026-02-16T11:12:10.627Z","changelog":"Exclude scripts from package","fileCount":2,"zipByteSize":3113},{"version":"0.4.1","createdAt":"2026-02-16T02:53:15.249Z","changelog":"Release v0.4.1","fileCount":3,"zipByteSize":5050},{"version":"0.4.0","createdAt":"2026-02-16T02:28:04.862Z","changelog":"Fix crash detection false positives, timeout overshoot, race conditions, Pi loop, notification marker dependency","fileCount":3,"zipByteSize":4927},{"version":"0.3.1","createdAt":"2026-02-16T02:20:18.414Z","changelog":"Extract monitor loop to scripts/monitor.sh","fileCount":3,"zipByteSize":4498},{"version":"0.3.0","createdAt":"2026-02-16T02:05:32.838Z","changelog":"Release v0.3.0","fileCount":2,"zipByteSize":3970}]},"execution":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No published capability contract is available yet."},"installCommand":"clawhub skill install s1779ws25xpwzg5wt17m8htzt1884ce9:resilient-coding-agent","setupComplexity":"low","setupSteps":["Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.","Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data."],"contract":{"contractStatus":"missing","authModes":[],"requires":[],"forbidden":[],"supportsMcp":false,"supportsA2a":false,"supportsStreaming":false,"inputSchemaRef":null,"outputSchemaRef":null,"dataRegion":null,"contractUpdatedAt":null,"sourceUpdatedAt":null,"freshnessSeconds":null},"invocationGuide":{"preferredApi":{"snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/trust"},"curlExamples":["curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/snapshot\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/contract\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/trust\""],"jsonRequestTemplate":{"query":"summarize this repo","constraints":{"maxLatencyMs":2000,"protocolPreference":["OPENCLEW"]}},"jsonResponseTemplate":{"ok":true,"result":{"summary":"...","confidence":0.9},"meta":{"source":"CLAWHUB","generatedAt":"2026-10-15T01:22:40.187Z"}},"retryPolicy":{"maxAttempts":3,"backoffMs":[500,1500,3500],"retryableConditions":["HTTP_429","HTTP_503","NETWORK_TIMEOUT"]}},"endpoints":{"dossierUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/dossier","snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-cosformula-resilient-coding-agent/trust"}},"reliability":{"evidence":{"source":"runtime-metrics","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No trust, reliability, or runtime telemetry is available."},"trust":{"status":"unavailable","handshakeStatus":"UNKNOWN","verificationFreshnessHours":null,"reputationScore":null,"p95LatencyMs":null,"successRate30d":null,"fallbackRate":null,"attempts30d":null,"trustUpdatedAt":null,"trustConfidence":"unknown","sourceUpdatedAt":null,"freshnessSeconds":null},"decisionGuardrails":{"doNotUseIf":["Contract metadata is missing or unavailable for deterministic execution."],"safeUseWhen":[],"riskFlags":["missing_or_unavailable_contract","trust_data_unavailable","schema_references_missing"],"operationalConfidence":"low"},"executionMetrics":{"observedLatencyMsP50":null,"observedLatencyMsP95":null,"estimatedCostUsd":null,"uptime30d":null,"rateLimitRpm":null,"rateLimitBurst":null,"lastVerifiedAt":null,"verificationSource":null},"runtimeMetrics":{"successRate":null,"avgLatencyMs":null,"avgCostUsd":null,"hallucinationRate":null,"retryRate":null,"disputeRate":null,"p50Latency":null,"p95Latency":null,"lastUpdated":null}},"benchmarks":{"evidence":{"source":"no-benchmark-data","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No benchmark suites or observed failure patterns are available."},"suites":[],"failurePatterns":[]},"artifacts":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"high","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":null},"readme":"Skill: Resilient Coding Agent\n\nOwner: cosformula\n\nSummary: Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\n\nTags: latest:0.5.0\n\nVersion history:\n\nv0.5.0 | 2026-02-18T01:44:18.267Z | user\n\nRelease v0.5.0\n\nv0.4.4 | 2026-02-16T23:30:09.217Z | user\n\nRelease v0.4.4\n\nv0.4.3 | 2026-02-16T17:04:16.825Z | user\n\nRelease v0.4.3\n\nv0.4.2 | 2026-02-16T11:12:10.627Z | user\n\nExclude scripts from package\n\nv0.4.1 | 2026-02-16T02:53:15.249Z | user\n\nRelease v0.4.1\n\nv0.4.0 | 2026-02-16T02:28:04.862Z | user\n\nFix crash detection false positives, timeout overshoot, race conditions, Pi loop, notification marker dependency\n\nv0.3.1 | 2026-02-16T02:20:18.414Z | user\n\nExtract monitor loop to scripts/monitor.sh\n\nv0.3.0 | 2026-02-16T02:05:32.838Z | user\n\nRelease v0.3.0\n\nv0.2.0 | 2026-02-16T01:41:27.199Z | user\n\nRelease v0.2.0\n\nv0.1.1 | 2026-02-16T01:02:03.864Z | user\n\nMake completion notification generic, not OpenClaw-specific\n\nv0.1.0 | 2026-02-16T00:10:07.204Z | user\n\nInitial release: tmux-based resilient execution for long-running coding agents (Codex, Claude Code, OpenCode, Pi)\n\nArchive index:\n\nArchive v0.5.0: 2 files, 3863 bytes\n\nFiles: SKILL.md (9059b), _meta.json (141b)\n\nFile v0.5.0:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n**Placeholders:** `<task-name>` and `<project-dir>` are filled in by the orchestrator. `<task-name>` must match `[a-z0-9-]` only. `<project-dir>` must be a valid existing directory.\n\n**Temp directory:** Each task uses a secure temp directory created with `mktemp -d`. Store this path as `<tmpdir>` and use it for all task files (prompt, events, session ID, done marker). This avoids predictable filenames and symlink/race conditions. Example: `TMPDIR=$(mktemp -d)` produces something like `/var/folders/xx/.../T/tmp.aBcDeFgH`.\n\n**Prompt safety:** Task prompts are never interpolated into shell commands. Instead, write the prompt to a temp file using the orchestrator's `write` tool (no shell involved), then reference it with `\"$(cat $TMPDIR/prompt)\"` inside the tmux command. The shell treats command substitution output inside double quotes as a single literal argument, preventing injection. This depends on the orchestrator's `write` tool not invoking a shell; OpenClaw's built-in `write` tool meets this requirement.\n\n**Sensitive output:** tmux scrollback and event log files may contain secrets or API keys from agent output. On shared machines, restrict file permissions (`chmod 600`) and clean up temp directories after task completion.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\n# Step 1: Create secure temp directory\nTMPDIR=$(mktemp -d)\nchmod 700 \"$TMPDIR\"\n\n# Step 2: Write prompt to file (use orchestrator's write tool, not echo/shell)\n# File: $TMPDIR/prompt\n\n# Step 3: Launch in tmux (pass TMPDIR via env)\ntmux new-session -d -s codex-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"$(cat $TASK_TMPDIR/prompt)\" | tee $TASK_TMPDIR/events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Step 4: Capture this task's Codex session ID; resume --last is unsafe with concurrent tasks.\n# Uses jq for reliable JSON parsing (falls back to grep if jq unavailable).\nuntil [ -s \"$TMPDIR/codex-session-id\" ]; do\n  if command -v jq &>/dev/null; then\n    jq -r 'select(.thread_id) | .thread_id' \"$TMPDIR/events.jsonl\" 2>/dev/null | head -n 1 > \"$TMPDIR/codex-session-id\"\n  else\n    grep -oE '\"thread_id\":\"[^\"]+\"' \"$TMPDIR/events.jsonl\" 2>/dev/null | head -n 1 | cut -d'\"' -f4 > \"$TMPDIR/codex-session-id\"\n  fi\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\n# Create secure temp directory and write prompt to $TMPDIR/prompt first\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\ntmux new-session -d -s claude-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\n# Create secure temp directory and write prompt to $TMPDIR/prompt first\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\n\n# OpenCode\ntmux new-session -d -s opencode-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter\n\n# Pi (separate temp dir)\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\ntmux new-session -d -s pi-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && touch $TASK_TMPDIR/done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && openclaw system event --text \"Codex done: <task-name>\" --mode now; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `$TMPDIR/codex-session-id` when the task starts (see **Codex CLI** above). The monitor reads that file to resume the exact task session.\n\nThe orchestrator should run this check loop periodically (every 3-5 minutes, via cron or a background timer). On consecutive failures, double the interval (3m, 6m, 12m, ...) and reset when the agent is running normally. Stop after 5 hours wall-clock.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from $TMPDIR/codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.5.0:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.5.0\",\n  \"publishedAt\": 1771379058267\n}\n\nArchive v0.4.4: 2 files, 3402 bytes\n\nFiles: SKILL.md (7951b), _meta.json (141b)\n\nFile v0.4.4:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n**Placeholders:** `<task-name>` and `<project-dir>` are filled in by the orchestrator. `<task-name>` must match `[a-z0-9-]` only. `<project-dir>` must be a valid existing directory.\n\n**Prompt safety:** Task prompts are never interpolated into shell commands. Instead, write the prompt to a temp file using the orchestrator's `write` tool (no shell involved), then reference it with `\"$(cat /tmp/<agent>-<task-name>.prompt)\"` inside the tmux command. The shell treats command substitution output inside double quotes as a single literal argument, preventing injection.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\n# Step 1: Write prompt to file (use orchestrator's write tool, not echo/shell)\n# File: /tmp/codex-<task-name>.prompt\n\n# Step 2: Launch in tmux\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"$(cat /tmp/codex-<task-name>.prompt)\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\n# Write prompt to /tmp/claude-<task-name>.prompt first\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"$(cat /tmp/claude-<task-name>.prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\n# Write prompt to /tmp/opencode-<task-name>.prompt first\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"$(cat /tmp/opencode-<task-name>.prompt)\" && echo \"__TASK_DONE__\"' Enter\n\n# Write prompt to /tmp/pi-<task-name>.prompt first\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"$(cat /tmp/pi-<task-name>.prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat /tmp/codex-<task-name>.prompt)\" && touch /tmp/codex-<task-name>.done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat /tmp/codex-<task-name>.prompt)\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat /tmp/codex-<task-name>.prompt)\" && openclaw system event --text \"Codex done: <task-name>\" --mode now; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat /tmp/codex-<task-name>.prompt)\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor reads that file to resume the exact task session.\n\nThe orchestrator should run this check loop periodically (every 3-5 minutes, via cron or a background timer). On consecutive failures, double the interval (3m, 6m, 12m, ...) and reset when the agent is running normally. Stop after 5 hours wall-clock.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.4.4:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.4.4\",\n  \"publishedAt\": 1771284609217\n}\n\nArchive v0.4.3: 2 files, 3197 bytes\n\nFiles: SKILL.md (7187b), _meta.json (141b)\n\nFile v0.4.3:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n**Note on placeholders:** All `<task-name>`, `<project-dir>`, and `<task prompt>` values in this document are templates for the orchestrator to fill in. The orchestrator must sanitize these values before interpolation (e.g., restrict to `[A-Za-z0-9._-]` for session names, shell-escape prompts) to prevent injection.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor reads that file to resume the exact task session.\n\nThe orchestrator should run this check loop periodically (every 3-5 minutes, via cron or a background timer). On consecutive failures, double the interval (3m, 6m, 12m, ...) and reset when the agent is running normally. Stop after 5 hours wall-clock.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.4.3:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.4.3\",\n  \"publishedAt\": 1771261456825\n}\n\nArchive v0.4.2: 2 files, 3113 bytes\n\nFiles: SKILL.md (7100b), _meta.json (141b)\n\nFile v0.4.2:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor script reads that file to resume the exact task session.\n\nRun the monitor script in the background:\n\n```bash\n./scripts/monitor.sh codex-<task-name> codex\n# or: ./scripts/monitor.sh claude-<task-name> claude\n```\n\nThe script checks every 3 minutes. On consecutive failures the interval doubles (3m, 6m, 12m, ...) and resets when the agent is running normally. Stops after 5 hours wall-clock.\n\nWhen starting long tasks, run the monitor in the background (via `&`, `nohup`, or the orchestrator's cron) so recovery happens automatically.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.4.2:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.4.2\",\n  \"publishedAt\": 1771240330627\n}\n\nArchive v0.4.1: 3 files, 5050 bytes\n\nFiles: scripts/monitor.sh (4400b), SKILL.md (7100b), _meta.json (141b)\n\nFile v0.4.1:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor script reads that file to resume the exact task session.\n\nRun the monitor script in the background:\n\n```bash\n./scripts/monitor.sh codex-<task-name> codex\n# or: ./scripts/monitor.sh claude-<task-name> claude\n```\n\nThe script checks every 3 minutes. On consecutive failures the interval doubles (3m, 6m, 12m, ...) and resets when the agent is running normally. Stops after 5 hours wall-clock.\n\nWhen starting long tasks, run the monitor in the background (via `&`, `nohup`, or the orchestrator's cron) so recovery happens automatically.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.4.1:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.4.1\",\n  \"publishedAt\": 1771210395249\n}\n\nArchive v0.4.0: 3 files, 4927 bytes\n\nFiles: scripts/monitor.sh (3886b), SKILL.md (7286b), _meta.json (141b)\n\nFile v0.4.0:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes. Use `;` before `echo \"__TASK_DONE__\"` so the marker prints even if the notification command fails:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now; echo \"__TASK_DONE__\"' Enter\n\n# Webhook / curl\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && curl -s -X POST <webhook-url> -d \"task=done\"; echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor script reads that file to resume the exact task session.\n\nRun the monitor script in the background:\n\n```bash\n./scripts/monitor.sh codex-<task-name> codex\n# or: ./scripts/monitor.sh claude-<task-name> claude\n```\n\nThe script checks every 3 minutes. On consecutive failures the interval doubles (3m, 6m, 12m, ...) and resets when the agent is running normally. Stops after 5 hours wall-clock.\n\nWhen starting long tasks, run the monitor in the background (via `&`, `nohup`, or the orchestrator's cron) so recovery happens automatically.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.4.0:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.4.0\",\n  \"publishedAt\": 1771208884862\n}\n\nArchive v0.3.1: 3 files, 4498 bytes\n\nFiles: scripts/monitor.sh (2958b), SKILL.md (7179b), _meta.json (141b)\n\nFile v0.3.1:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive host restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: host restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done && echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\" && echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now && echo \"__TASK_DONE__\"' Enter\n\n# Webhook / curl\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && curl -s -X POST <webhook-url> -d \"task=done\" && echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor script reads that file to resume the exact task session.\n\nRun the monitor script in the background:\n\n```bash\n./scripts/monitor.sh codex-<task-name> codex\n# or: ./scripts/monitor.sh claude-<task-name> claude\n```\n\nThe script checks every 3 minutes. On consecutive failures the interval doubles (3m, 6m, 12m, ...) and resets when the agent is running normally. Stops after 5 hours wall-clock.\n\nWhen starting long tasks, run the monitor in the background (via `&`, `nohup`, or the orchestrator's cron) so recovery happens automatically.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.3.1:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.3.1\",\n  \"publishedAt\": 1771208418414\n}\n\nArchive v0.3.0: 2 files, 3970 bytes\n\nFiles: SKILL.md (9498b), _meta.json (141b)\n\nFile v0.3.0:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive host restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: host restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"<task prompt>\" | tee /tmp/codex-<task-name>.events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Capture this task's Codex session ID at start; resume --last is unsafe with concurrent tasks.\nuntil [ -s /tmp/codex-<task-name>.codex-session-id ]; do\n  sed -nE 's/.*\"thread_id\":\"([^\"]+)\".*/\\1/p' /tmp/codex-<task-name>.events.jsonl 2>/dev/null | head -n 1 > /tmp/codex-<task-name>.codex-session-id\n  sleep 1\ndone\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### OpenCode / Pi\n\n```bash\ntmux new-session -d -s opencode-<task-name>\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n\ntmux new-session -d -s pi-<task-name>\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"<task prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done && echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\" && echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now && echo \"__TASK_DONE__\"' Enter\n\n# Webhook / curl\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && curl -s -X POST <webhook-url> -d \"task=done\" && echo \"__TASK_DONE__\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ `, `% `, or `> `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nFor Codex tasks, save the session ID to `/tmp/<session>.codex-session-id` when the task starts (see **Codex CLI** above). The monitor below reads that file to resume the exact task session.\n\nConcrete periodic monitor with exponential backoff (Bash required):\n\n```bash\n#!/usr/bin/env bash\nSESSION=\"codex-<task-name>\"                     # or claude-/opencode-/pi-<task-name>\nAGENT=\"codex\"                                   # codex | claude | opencode | pi\nCODEX_SESSION_FILE=\"/tmp/${SESSION}.codex-session-id\"\nRETRY_COUNT=0\nSTART_TS=\"$(date +%s)\"\nDEADLINE_TS=$(( START_TS + 18000 ))             # 5 hours wall-clock\n\nwhile true; do\n  NOW_TS=\"$(date +%s)\"\n  if [ \"$NOW_TS\" -ge \"$DEADLINE_TS\" ]; then\n    echo \"Retry timeout reached (5h wall-clock). Stopping monitor.\"\n    break\n  fi\n\n  INTERVAL=$(( 180 * (2 ** RETRY_COUNT) ))\n\n  if tmux has-session -t \"$SESSION\" 2>/dev/null; then\n    OUTPUT=\"$(tmux capture-pane -t \"$SESSION\" -p -S -120)\"\n    RECENT=\"$(printf '%s\\n' \"$OUTPUT\" | tail -n 40)\"\n\n    if printf '%s\\n' \"$RECENT\" | grep -q \"__TASK_DONE__\"; then\n      break  # task completed normally\n    fi\n\n    PROMPT_BACK=0\n    EXIT_HINT=0\n    printf '%s\\n' \"$RECENT\" | grep -Eq '([$%] $|> $)' && PROMPT_BACK=1\n    printf '%s\\n' \"$RECENT\" | grep -Eiq '(exit code|exited|status [1-9][0-9]*)' && EXIT_HINT=1\n\n    if [ \"$PROMPT_BACK\" -eq 1 ] || [ \"$EXIT_HINT\" -eq 1 ]; then\n      RETRY_COUNT=$(( RETRY_COUNT + 1 ))\n\n      case \"$AGENT\" in\n        codex)\n          # Use the session ID captured for this task. --last can target a different concurrent task.\n          if [ -s \"$CODEX_SESSION_FILE\" ]; then\n            CODEX_SESSION_ID=\"$(cat \"$CODEX_SESSION_FILE\")\"\n            tmux send-keys -t \"$SESSION\" \"codex exec resume $CODEX_SESSION_ID \\\"Continue the previous task\\\"\" Enter\n          else\n            echo \"Missing Codex session ID file: $CODEX_SESSION_FILE\"\n            break\n          fi\n          ;;\n        claude)\n          tmux send-keys -t \"$SESSION\" 'claude --resume' Enter\n          ;;\n        opencode)\n          tmux send-keys -t \"$SESSION\" 'opencode run \"Continue\"' Enter\n          ;;\n        pi)\n          # Pi CLI has no native resume command; manual restart is required.\n          echo \"Pi has no resume command. Manual restart required.\"\n          ;;\n        *)\n          echo \"Unsupported agent: $AGENT\"\n          break\n          ;;\n      esac\n    else\n      RETRY_COUNT=0  # agent is running normally, reset backoff\n      INTERVAL=180\n    fi\n  else\n    echo \"tmux session $SESSION no longer exists. Stopping monitor.\"\n    break\n  fi\n  sleep \"$INTERVAL\"\ndone\n```\n\nRetry interval starts at 3 minutes and doubles on each consecutive failure (3m → 6m → 12m → ...). Resets when the agent is running normally. The monitor stops after 5 hours of real wall-clock elapsed time from monitor start.\n\nWhen starting long tasks, configure this monitor loop in the orchestrator (background shell loop, supervisor, or cron) so recovery runs automatically without manual checks.\n\n## Recovery After Interruption\n\nFor automated crash detection and retries, use **Health Monitoring** above.\nKeep this section as a manual fallback when you need to intervene directly:\n\n```bash\n# Codex (prefer explicit session ID from /tmp/<session>.codex-session-id)\ntmux send-keys -t codex-<task-name> 'codex exec resume <session-id> \"Continue the previous task\"' Enter\n\n# Claude Code\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n\n# OpenCode\ntmux send-keys -t opencode-<task-name> 'opencode run \"Continue\"' Enter\n\n# Pi: no native resume; re-run the task prompt manually\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume <session-id>`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.3.0:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.3.0\",\n  \"publishedAt\": 1771207532838\n}\n\nArchive v0.2.0: 2 files, 3220 bytes\n\nFiles: SKILL.md (7149b), _meta.json (141b)\n\nFile v0.2.0:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive host restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: host restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<task prompt>\"' Enter\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\"' Enter\n```\n\n### OpenCode / Pi\n\nSame pattern. Replace the command with `opencode run \"<prompt>\"` or `pi -p \"<prompt>\"`.\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now' Enter\n\n# Webhook / curl\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && curl -s -X POST <webhook-url> -d \"task=done\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Health Monitoring\n\nFor long-running tasks, use an active monitor loop instead of only checking on demand.\n\nPeriodic check flow:\n1. Run `tmux has-session -t <agent-task>` to confirm the tmux session still exists.\n2. Run `tmux capture-pane -t <agent-task> -p -S -<N>` to capture recent output.\n3. Detect likely agent exit by checking the last `N` lines for:\n   - Shell prompt returned (for example, a line ending in `$ ` or `% `)\n   - Exit indicators (`exit code`, `status <non-zero>`, `exited`)\n   - No completion marker (`__TASK_DONE__`)\n4. If crash is detected, run the agent-native resume command in the same tmux session.\n\nUse a done marker in your start command so the monitor can distinguish normal completion from crashes:\n\n```bash\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && echo \"__TASK_DONE__\"' Enter\n```\n\nConcrete periodic monitor (run every 2-3 minutes):\n\n```bash\nSESSION=\"codex-<task-name>\"   # or claude-<task-name>\nAGENT=\"codex\"                 # codex | claude\nLINES=120\nDONE_MARKER=\"__TASK_DONE__\"\n\nwhile true; do\n  if tmux has-session -t \"$SESSION\" 2>/dev/null; then\n    OUTPUT=\"$(tmux capture-pane -t \"$SESSION\" -p -S -\"${LINES}\")\"\n    RECENT=\"$(printf '%s\\n' \"$OUTPUT\" | tail -n 40)\"\n\n    if ! printf '%s\\n' \"$RECENT\" | grep -q \"$DONE_MARKER\"; then\n      PROMPT_BACK=0\n      EXIT_HINT=0\n      printf '%s\\n' \"$RECENT\" | grep -Eq '[$%] $' && PROMPT_BACK=1\n      printf '%s\\n' \"$RECENT\" | grep -Eiq '(exit code|exited|status [1-9][0-9]*)' && EXIT_HINT=1\n\n      if [ \"$PROMPT_BACK\" -eq 1 ] || [ \"$EXIT_HINT\" -eq 1 ]; then\n        case \"$AGENT\" in\n          codex)\n            tmux send-keys -t \"$SESSION\" 'codex exec resume --last \"Continue the previous task\"' Enter\n            ;;\n          claude)\n            tmux send-keys -t \"$SESSION\" 'claude --resume' Enter\n            ;;\n        esac\n      fi\n    fi\n  fi\n  sleep 180\ndone\n```\n\nWhen starting long tasks, configure this monitor loop in the orchestrator (background shell loop, supervisor, or cron) so recovery runs automatically without manual checks.\n\n## Recovery After Interruption\n\nIf the coding agent process dies (network drop, crash, OOM), the tmux session may still exist but the agent has exited. Use the agent's native resume to continue.\n\n### Codex Resume\n\nCodex persists sessions in `~/.codex/sessions/`. Resume the last interrupted session:\n\n```bash\n# Resume in the same tmux session\ntmux send-keys -t codex-<task-name> 'codex exec resume --last \"Continue the previous task\"' Enter\n```\n\nOr target a specific session ID:\n\n```bash\n# List recent sessions\nls -lt ~/.codex/sessions/ | head -5\n\n# Resume by ID\ncodex exec resume <session-id> \"Continue where you left off\"\n```\n\n### Claude Code Resume\n\nClaude Code supports `--resume` to continue the last conversation:\n\n```bash\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume --last`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.2.0:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.2.0\",\n  \"publishedAt\": 1771206087199\n}\n\nArchive v0.1.1: 2 files, 2293 bytes\n\nFiles: SKILL.md (4708b), _meta.json (141b)\n\nFile v0.1.1:SKILL.md\n\n---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive host restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: host restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\ntmux new-session -d -s codex-<task-name>\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<task prompt>\"' Enter\n```\n\n### Claude Code\n\n```bash\ntmux new-session -d -s claude-<task-name>\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"<task prompt>\"' Enter\n```\n\n### OpenCode / Pi\n\nSame pattern. Replace the command with `opencode run \"<prompt>\"` or `pi -p \"<prompt>\"`.\n\n### Completion Notification (Optional)\n\nChain a notification command after the agent so you know when it finishes:\n\n```bash\n# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && touch /tmp/codex-<task-name>.done' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && openclaw system event --text \"Codex done: <summary>\" --mode now' Enter\n\n# Webhook / curl\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"<prompt>\" && curl -s -X POST <webhook-url> -d \"task=done\"' Enter\n```\n\n## Monitor Progress\n\n```bash\n# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -\n```\n\nCheck progress when:\n- The user asks for a status update\n- You want to proactively report milestones\n\n## Recovery After Interruption\n\nIf the coding agent process dies (network drop, crash, OOM), the tmux session may still exist but the agent has exited. Use the agent's native resume to continue.\n\n### Codex Resume\n\nCodex persists sessions in `~/.codex/sessions/`. Resume the last interrupted session:\n\n```bash\n# Resume in the same tmux session\ntmux send-keys -t codex-<task-name> 'codex exec resume --last \"Continue the previous task\"' Enter\n```\n\nOr target a specific session ID:\n\n```bash\n# List recent sessions\nls -lt ~/.codex/sessions/ | head -5\n\n# Resume by ID\ncodex exec resume <session-id> \"Continue where you left off\"\n```\n\n### Claude Code Resume\n\nClaude Code supports `--resume` to continue the last conversation:\n\n```bash\ntmux send-keys -t claude-<task-name> 'claude --resume' Enter\n```\n\n## Cleanup\n\nAfter a task completes, kill the tmux session:\n\n```bash\ntmux kill-session -t codex-<task-name>\n```\n\nList all coding agent tmux sessions:\n\n```bash\ntmux list-sessions 2>/dev/null | grep -E '^(codex|claude|opencode|pi)-'\n```\n\n## Naming Convention\n\nTmux sessions use the pattern `<agent>-<task-name>`:\n\n- `codex-refactor-auth`\n- `claude-review-pr-42`\n- `codex-bus-sim-physics`\n\nKeep names short, lowercase, hyphen-separated.\n\n## Checklist\n\nBefore starting a long task:\n\n1. Pick tmux over direct execution (if task > 5 min)\n2. Name the tmux session with the agent prefix\n3. Optionally chain a completion notification\n4. Tell the user: task content, tmux session name, estimated duration\n5. Monitor via `tmux capture-pane` on request\n\n## Limitations\n\n- tmux sessions do not survive a **machine reboot** (tmux itself is killed). For reboot-resilient tasks, the coding agent's native resume (`codex exec resume --last`, `claude --resume`) is the recovery path.\n- Interactive approval prompts inside tmux require manual `tmux attach` or `tmux send-keys`. Use `--full-auto` / `--yolo` / `-p` flags when possible.\n\nFile v0.1.1:_meta.json\n\n{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.1.1\",\n  \"publishedAt\": 1771203723864\n}","readmeExcerpt":"Skill: Resilient Coding Agent Owner: cosformula Summary: Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Tags: latest:0.5.0 Version history: v0.5.0 | 2026-02-18T01:44:18.267Z | user Release v0.5.0 v0.4.4 | 2026-02-16T23:30:09.217Z | user Release v0.4.4 v0.4.3 | 2026-02-16T17:04:16.825Z | user Release v0.4.3 v0.4.2 | ","codeSnippets":[],"executableExamples":[{"language":"bash","snippet":"# Step 1: Create secure temp directory\nTMPDIR=$(mktemp -d)\nchmod 700 \"$TMPDIR\"\n\n# Step 2: Write prompt to file (use orchestrator's write tool, not echo/shell)\n# File: $TMPDIR/prompt\n\n# Step 3: Launch in tmux (pass TMPDIR via env)\ntmux new-session -d -s codex-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && set -o pipefail && codex exec --full-auto --json \"$(cat $TASK_TMPDIR/prompt)\" | tee $TASK_TMPDIR/events.jsonl && echo \"__TASK_DONE__\"' Enter\n\n# Step 4: Capture this task's Codex session ID; resume --last is unsafe with concurrent tasks.\n# Uses jq for reliable JSON parsing (falls back to grep if jq unavailable).\nuntil [ -s \"$TMPDIR/codex-session-id\" ]; do\n  if command -v jq &>/dev/null; then\n    jq -r 'select(.thread_id) | .thread_id' \"$TMPDIR/events.jsonl\" 2>/dev/null | head -n 1 > \"$TMPDIR/codex-session-id\"\n  else\n    grep -oE '\"thread_id\":\"[^\"]+\"' \"$TMPDIR/events.jsonl\" 2>/dev/null | head -n 1 | cut -d'\"' -f4 > \"$TMPDIR/codex-session-id\"\n  fi\n  sleep 1\ndone"},{"language":"bash","snippet":"# Create secure temp directory and write prompt to $TMPDIR/prompt first\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\ntmux new-session -d -s claude-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t claude-<task-name> 'cd <project-dir> && claude -p \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter"},{"language":"bash","snippet":"# Create secure temp directory and write prompt to $TMPDIR/prompt first\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\n\n# OpenCode\ntmux new-session -d -s opencode-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t opencode-<task-name> 'cd <project-dir> && opencode run \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter\n\n# Pi (separate temp dir)\nTMPDIR=$(mktemp -d) && chmod 700 \"$TMPDIR\"\ntmux new-session -d -s pi-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux send-keys -t pi-<task-name> 'cd <project-dir> && pi -p \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter"},{"language":"bash","snippet":"# Generic: touch a marker file\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && touch $TASK_TMPDIR/done; echo \"__TASK_DONE__\"' Enter\n\n# macOS: system notification\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && osascript -e \"display notification \\\"Task done\\\" with title \\\"Codex\\\"\"; echo \"__TASK_DONE__\"' Enter\n\n# OpenClaw: system event (immediate wake)\ntmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && openclaw system event --text \"Codex done: <task-name>\" --mode now; echo \"__TASK_DONE__\"' Enter"},{"language":"bash","snippet":"# Check if the session is still running\ntmux has-session -t codex-<task-name> 2>/dev/null && echo \"running\" || echo \"finished/gone\"\n\n# Read recent output (last 200 lines)\ntmux capture-pane -t codex-<task-name> -p -S -200\n\n# Read the full scrollback\ntmux capture-pane -t codex-<task-name> -p -S -"},{"language":"bash","snippet":"tmux send-keys -t codex-<task-name> 'cd <project-dir> && codex exec --full-auto \"$(cat $TASK_TMPDIR/prompt)\" && echo \"__TASK_DONE__\"' Enter"}],"parameters":null,"dependencies":[],"permissions":[],"extractedFiles":[{"path":"SKILL.md","content":"---\nname: resilient-coding-agent\ndescription: \"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption.\"\nmetadata:\n  openclaw:\n    emoji: \"🛡️\"\n    requires:\n      bins: [tmux]\n      anyBins: [codex, claude, opencode, pi]\n---\n\n# Resilient Coding Agent\n\nLong-running coding agent tasks (Codex CLI, Claude Code, OpenCode, Pi) are vulnerable to interruption: orchestrator restarts, process crashes, network drops. This skill decouples the coding agent process from the orchestrator using tmux, and leverages agent-native session resume for recovery.\n\n**Placeholders:** `<task-name>` and `<project-dir>` are filled in by the orchestrator. `<task-name>` must match `[a-z0-9-]` only. `<project-dir>` must be a valid existing directory.\n\n**Temp directory:** Each task uses a secure temp directory created with `mktemp -d`. Store this path as `<tmpdir>` and use it for all task files (prompt, events, session ID, done marker). This avoids predictable filenames and symlink/race conditions. Example: `TMPDIR=$(mktemp -d)` produces something like `/var/folders/xx/.../T/tmp.aBcDeFgH`.\n\n**Prompt safety:** Task prompts are never interpolated into shell commands. Instead, write the prompt to a temp file using the orchestrator's `write` tool (no shell involved), then reference it with `\"$(cat $TMPDIR/prompt)\"` inside the tmux command. The shell treats command substitution output inside double quotes as a single literal argument, preventing injection. This depends on the orchestrator's `write` tool not invoking a shell; OpenClaw's built-in `write` tool meets this requirement.\n\n**Sensitive output:** tmux scrollback and event log files may contain secrets or API keys from agent output. On shared machines, restrict file permissions (`chmod 600`) and clean up temp directories after task completion.\n\n## Prerequisites\n\nThis skill assumes the orchestrator is already configured to use coding agent CLIs (Codex, Claude Code, etc.) for coding tasks instead of native sessions. If the orchestrator is still using `sessions_spawn` for coding work, configure it to prefer coding agents first (e.g., via AGENTS.md or equivalent). See the `coding-agent` skill for setup.\n\n## When to Use This\n\nUse this pattern when:\n- The task is expected to take **more than 5 minutes**\n- The orchestrator might restart during execution\n- You want fire-and-forget execution with completion notification\n\nFor quick tasks under 5 minutes, running the agent directly is fine.\n\n## Start a Task\n\nCreate a tmux session with a descriptive name. Use the agent prefix (`codex-`, `claude-`, etc.) for easy identification.\n\n### Codex CLI\n\n```bash\n# Step 1: Create secure temp directory\nTMPDIR=$(mktemp -d)\nchmod 700 \"$TMPDIR\"\n\n# Step 2: Write prompt to file (use orchestrator's write tool, not echo/shell)\n# File: $TMPDIR/prompt\n\n# Step 3: Launch in tmux (pass TMPDIR via env)\ntmux new-session -d -s codex-<task-name> -e \"TASK_TMPDIR=$TMPDIR\"\ntmux "},{"path":"_meta.json","content":"{\n  \"ownerId\": \"kn7fkvq6nnaw1sjg9z2fvjxwb1812041\",\n  \"slug\": \"resilient-coding-agent\",\n  \"version\": \"0.5.0\",\n  \"publishedAt\": 1771379058267\n}"}],"languages":[],"docsSourceLabel":"CLAWHUB","editorialOverview":"Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Skill: Resilient Coding Agent Owner: cosformula Summary: Run long-running coding agents (Codex, Claude Code, etc.) in tmux sessions that survive orchestrator restarts, with automatic resume on interruption. Tags: latest:0.5.0 Version history: v0.5.0 | 2026-02-18T01:44:18.267Z | user Release v0.5.0 v0.4.4 | 2026-02-16T23:30:09.217Z | user Release v0.4.4 v0.4.3 | 2026-02-16T17:04:16.825Z | user Release v0.4.3 v0.4.2 |","editorialQuality":{"score":100,"threshold":65,"status":"ready","wordCount":869,"uniquenessScore":55,"reasons":[]}},"media":{"evidence":{"source":"no-media","verified":false,"confidence":"low","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":"No screenshots, media assets, or demo links are available."},"primaryImageUrl":null,"mediaAssetCount":0,"assets":[],"demoUrl":null},"ownerResources":{"evidence":{"source":"unclaimed","verified":false,"confidence":"low","updatedAt":"2026-10-12T01:13:04.983Z","emptyReason":"This page has not been claimed by the agent owner."},"hasCustomPage":false,"customPageUpdatedAt":null,"customLinks":[],"structuredLinks":{"docsUrl":null,"demoUrl":null,"supportUrl":null,"pricingUrl":null,"statusUrl":null},"customPage":null},"relatedAgents":{"evidence":{"source":"protocol-neighbors","verified":false,"confidence":"medium","updatedAt":"2026-10-15T01:22:40.188Z","emptyReason":null},"items":[{"id":"8ebccd8e-3863-4187-8355-c3f14e1f9edf","entityType":"agent","canonicalPath":"/agent/iofficeai-aionui","slug":"iofficeai-aionui","name":"AionUi","description":"Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!","url":"https://github.com/iOfficeAI/AionUi","homepage":"https://www.aionui.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-10-09T19:11:12.944Z","createdAt":"2026-02-25T03:38:16.584Z","downloads":null},{"id":"b917f68a-ebff-438e-84f8-3f4b2494c0bc","entityType":"agent","canonicalPath":"/agent/activepieces-activepieces","slug":"activepieces-activepieces","name":"activepieces","description":"AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents","url":"https://github.com/activepieces/activepieces","homepage":"https://www.activepieces.com","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-15T02:22:12.426Z","createdAt":"2026-02-25T03:38:12.412Z","downloads":null},{"id":"5cb26759-3a39-483f-94cf-276a98c13bb8","entityType":"agent","canonicalPath":"/agent/cherryhq-cherry-studio","slug":"cherryhq-cherry-studio","name":"cherry-studio","description":"AI productivity studio with smart chat, autonomous agents, and 300+ assistants. Unified access to frontier LLMs","url":"https://github.com/CherryHQ/cherry-studio","homepage":"https://cherry-ai.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-11T14:38:40.986Z","createdAt":"2026-02-25T03:38:19.379Z","downloads":null},{"id":"6f6582d0-5d76-4f0f-b81d-86520247950b","entityType":"agent","canonicalPath":"/agent/copilotkit-copilotkit","slug":"copilotkit-copilotkit","name":"CopilotKit","description":"The Frontend for Agents & Generative UI. React + Angular","url":"https://github.com/CopilotKit/CopilotKit","homepage":"https://docs.copilotkit.ai","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-03-25T09:50:57.846Z","createdAt":"2026-02-25T03:39:14.617Z","downloads":null}],"links":{"hub":"/agent","source":"/agent/source/clawhub","protocols":[{"label":"OpenClaw","href":"/agent/protocol/openclew"}]}}}