{"data":{"slug":"discovered-728e18ae315b6c76cd4e35623b34650ed71ed3b0b217c811","title":"Rjv Opencode Agents","summary":"Launch and watch opencode runs using `scripts\/opencode-watch.sh` for DeepSeek v4.1 Flash with one retry, liveness heartbeat, stall\/cap kill, git-tree fingerprint, and empty-dir text mode.","url":"https:\/\/skillshunter.net\/skills\/discovered-728e18ae315b6c76cd4e35623b34650ed71ed3b0b217c811","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-728e18ae315b6c76cd4e35623b34650ed71ed3b0b217c811","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-728e18ae315b6c76cd4e35623b34650ed71ed3b0b217c811.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-728e18ae315b6c76cd4e35623b34650ed71ed3b0b217c811\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Use `text` mode for tasks requiring only prompt text and `repo` mode for repository reviews, ensuring read-only access unless edits are explicitly requested. Always write the brief to a file and start the watcher; never launch the same brief a third time on opencode.","instructions":"---\nname: rjv-opencode-agents\ndescription: \"Mechanism: launch and watch an opencode run via opencode-watch.sh (DeepSeek v4.1 Flash, one retry, liveness heartbeat, stall\/cap kill, tree fingerprint, optional local Ollama models). Delegation policy lives in rjv-delegate; host rungs and boxes in rjv-subagents-claude \/ rjv-subagents-codex. Triggers: opencode, opencode-watch, opencode stall, opencode retry.\"\n---\n\n# opencode agents: launch, watch, recover\n\nopencode is the cheapest worker (DeepSeek v4.1 Flash, one retry on\nDeepSeek v4.1 Flash again; DeepSeek only, per the user 2026-11-23). It is also the one most likely to run long or die\nsilently. The launcher never waits on it in the foreground: every run\ngoes through the **watcher**, and you keep working while it reports.\n\nDelegation policy and watching background work live in `rjv-delegate`\n(\u00a78); which tasks go to opencode and the 2 \/ 5 minute boxes live in\n`rjv-subagents-claude` \/ `rjv-subagents-codex`. This skill owns what\nhappens after you decide.\n\n## 1. Pick the mode\n\n| The task needs... | Mode | Where opencode runs |\n|---|---|---|\n| only the text in the prompt | `text` | a fresh empty directory the script makes |\n| to read a repo (review, recon) | `repo` | the repo, with `--auto` |\n\n**opencode reads files and runs shell commands in its working\ndirectory even without `--auto`** (probe, 2026-11-04: it read a file\nand wrote another with no approval). So `text` mode always runs in an\nempty directory, and anything that touches secrets, customer data or\nproduction stays on host cloud models, as `rjv-delegate` \u00a73 says.\n\nIn `repo` mode the brief says read-only unless edits are the task. The\nwatcher fingerprints the git tree before and after. `tree=CHANGED` on a\nread-only brief: discard the result, list the paths from `git status\n--porcelain` in your report, and never commit them. Revert only when the\nuser says so.\n\n## 2. Launch through the watcher\n\nWrite the brief to a file, then start the watcher. It runs on its own;\nyou never sit in a foreground wait for it.\n\n```sh\nS=<this skill's dir>\/scripts\/opencode-watch.sh\n$S <dir> <brief-file> <result-file> <cap-minutes> text|repo\n```\n\n- `<result-file>`: absolute path. In `repo` mode the brief tells\n  opencode to write its answer there. In `text` mode the script fills it\n  from the run's final text.\n- `<cap-minutes>`: the hard ceiling per model attempt. Set it to 3x the\n  box (box 2 \u2192 cap 6, box 5 \u2192 cap 15). The box sizes the task; the cap\n  only catches a run that will never finish.\n\n**Claude Code**: start it with the Monitor tool, `timeout_ms` above the\ncap times two (both models may run), so each event line arrives as a\nnotification. **Codex**: run it as a background command and read its\nstdout when it exits.\n\n## 3. React to the events\n\nThe watcher prints one line per event.\n\n| Event | Meaning | You do |\n|---|---|---|\n| `START` | an attempt began | keep working |\n| `ALIVE` | heartbeat every 2 min, still producing | keep working |\n| `STALL silent=N` | one check saw no change in log, result, database or CPU | nothing yet; 4 in a row is a kill |\n| `KILL reason=silent` | dead: 4 silent checks (2 min at 30 s) | the watcher retries once on DeepSeek by itself |\n| `KILL reason=cap` | alive but over the cap | the watcher retries; the task is too big, so split it next time |\n| `EXIT code=N` | one attempt ended; a retry may follow | wait for `DONE` |\n| `DONE status=ok` | result file is non-empty | check it (\u00a74) |\n| `DONE status=failed` | both models failed | \u00a75 |\n\nA run that is alive is never killed early. Time past the box means\nthe task was too big or the brief too thin; let it finish under the\ncap, then split the next one smaller.\n\n## 4. Check the result yourself\n\n- Read the result file. opencode's own \"done\" is a claim.\n- Mechanical output (a list, a lint pass): spot-check three items\n  against the source.\n- `repo` mode: `tree=unchanged` on a read-only brief. `tree=CHANGED` on a\n  read-only brief: discard the result, list the paths from `git status\n  --porcelain` in your report, and never commit them. Revert only when the\n  user says so.\n- Report what came back and which model produced it (the `DONE` line\n  names it).\n\n## 5. When both models fail\n\nWalk this in order and stop at the first that applies:\n\n1. The brief asked for too much: split it in two and launch both.\n2. The brief was unclear (the log shows it asking questions or\n   wandering): rewrite the brief and launch once more.\n3. Otherwise hand the task to a Haiku subagent (Sonnet if it needs\n   judgment), with the same brief.\n\nNever launch the same brief a third time on opencode.\n\n## 6. Tuning and spend\n\nEnvironment knobs, all optional: `OPENCODE_CHECK_SEC` (30),\n`OPENCODE_SILENT_MAX` (4), `OPENCODE_HEARTBEAT_MIN` (2),\n`OPENCODE_MODELS` (the two-model list). The JSON event log only grows\nat step boundaries, which is why CPU time and the database WAL also\ncount as signs of life.\n\nAfter a batch of runs, check spend with\n`opencode stats --days 0 --models --cost`.\n\nThe per-run log sits beside the result as `<result-file>.log`.\n\nTested 2026-11-04: a short text task returned in 5 s; a bad model name\nfell through to the second model; a 3,000-word essay under a 1 min cap\nstayed alive (no STALL) and was killed at the cap; a fake opencode that\nhangs with no output was killed after 2 silent checks on both models,\nwith no orphan processes left.\n\n## 7. Local models (Ollama)\n\nThe same watcher runs a local model: set `OPENCODE_MODELS=\"ollama\/<name>\"`.\nThe model must be listed under `provider.ollama.models` in\n`~\/.config\/opencode\/opencode.jsonc`. Local models are owned by\n`rjv-codex-ollama-subagents`; this section is only what the watcher does.\n\n- **Liveness.** The work runs in Ollama's `llama-server`, so the watcher\n  counts its CPU time as a sign of life.\n- **Memory.** It refuses to start an `ollama\/*` model below\n  `OPENCODE_MIN_FREE_PCT` (25) free memory. The event is `SKIP reason=memory`.\n- **Kill.** On a kill or a failed exit it runs `ollama stop <name>`, which\n  stops generation and frees the memory. Tested: a 1-minute cap killed a\n  long essay at 64 s and left no model loaded.\n- **Load.** A cold start of a 52 GB model takes about 20 to 40 s. Keep\n  the cap at 3x the box anyway.\n\nHow to brief and judge a local model (context size, narrow questions,\ntext mode with code pasted, never the gate): `rjv-codex-ollama-subagents`,\nwhich owns local models.\n\n## Related\n\n- `rjv-delegate`: delegation policy and watching slow work off the main thread.\n- `rjv-subagents-claude` \/ `rjv-subagents-codex`: host ladders, rungs and boxes.\n- `rjv-codex-ollama-subagents`: Codex's local runners (`ollama-chat.sh`\n  for one-shot text through the API, `local-codex-agent.sh`).\n","use_cases":["Launching opencode runs for text-based tasks in an empty directory","Watching and managing opencode runs for repository reviews with read-only access","Handling stalled or capped runs with automatic retries and result checks"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/rjvim\/ai-skills\/blob\/9a942086adef21dbd0c061d9d9e8fd5f43328bf6\/skills\/rjv-opencode-agents\/SKILL.md","source_commit":"9a942086adef21dbd0c061d9d9e8fd5f43328bf6","license":null,"version":null,"listing_approved_at":"2026-12-03","created_at":"2026-12-02T09:09:53.000000Z","updated_at":"2026-12-03T16:19:55.000000Z","seo_title":"Rjv Opencode Agents - Launch and Watch DeepSeek Runs","seo_description":"Mechanism for launching and watching opencode runs using DeepSeek v4.1 Flash with one retry, liveness heartbeat, stall\/cap kill, and git-tree fingerprinting.","seo_keywords":["opencode agents","DeepSeek v4.1 Flash","opencode-watch.sh","git-tree fingerprint","empty-dir text mode"]}}