Autonomous Opencode Harness because I hate having to babysit.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-25 23:12:27 -05:00
examples Add first-party opencode steps, memory and sub-agent logs 2026-10-25 23:12:27 -05:00
src/orchestrator Add first-party opencode steps, memory and sub-agent logs 2026-10-25 23:12:27 -05:00
tests Add first-party opencode steps, memory and sub-agent logs 2026-10-25 23:12:27 -05:00
.gitignore init 2026-10-21 22:15:48 -05:00
.python-version init 2026-10-21 22:15:48 -05:00
pyproject.toml init 2026-10-21 22:15:48 -05:00
README.md Add first-party opencode steps, memory and sub-agent logs 2026-10-25 23:12:27 -05:00
uv.lock init 2026-10-21 22:15:48 -05:00

orchestrator

Runs long-horizon agent loops (opencode, claude, codex, aider, anything with a CLI) for as long as you let it. Each iteration runs a list of steps from a YAML recipe. A typical recipe plans the next bounded step, does it, audits now and then, and commits. Failed iterations back off exponentially, so a broken setup doesn't spin forever.

opencode is a first-party agent: steps can be prompts instead of shell commands, steps can share one opencode session so each one remembers the last, and sub-agent transcripts are followed into their own tabs and log files.

Install

Requires uv and access to the repository, over either:

  • SSH: ssh://[email protected]:2222/7S/Orchestrator.git (your key must be loaded, e.g. in ssh-agent)
  • HTTPS: https://code.cthulhub.net/7S/Orchestrator.git (uses your git credential helper if the repo is private)

The examples below use SSH. To use HTTPS, swap in git+https://code.cthulhub.net/7S/Orchestrator.git anywhere you see git+ssh://….

From the git server

# Global `orchestrator` command (SSH)
uv tool install git+ssh://git@direct.cthulhub.net:2222/7S/Orchestrator.git

# ...or over HTTPS
uv tool install git+https://code.cthulhub.net/7S/Orchestrator.git

# A specific branch, tag or commit
uv tool install "git+ssh://[email protected]:2222/7S/Orchestrator.git@main"

If orchestrator isn't found afterwards, run uv tool update-shell and open a new terminal.

To call it as uv run orchestrator from inside another uv project, add it as a dev dependency there instead:

uv add --dev git+ssh://git@direct.cthulhub.net:2222/7S/Orchestrator.git

From a local checkout

git clone ssh://git@direct.cthulhub.net:2222/7S/Orchestrator.git
# or: git clone https://code.cthulhub.net/7S/Orchestrator.git
uv tool install --editable .\Orchestrator   # local changes apply immediately

# ...or run from the checkout without installing
cd Orchestrator
uv run orchestrator --help

Updating

Use the method that matches how you installed it. orchestrator --version shows what you're running.

# Installed from the git server with `uv tool install git+...`
uv tool upgrade oc-orchestrator        # pulls the latest commit of the branch you installed

# Installed with a pinned tag/commit (`[email protected]`): reinstall with the new ref
uv tool install --force "git+ssh://[email protected]:2222/7S/[email protected]"

# Editable install from a local checkout
git -C .\Orchestrator pull             # code changes apply immediately...
uv tool install --editable .\Orchestrator --reinstall   # ...but rerun this if dependencies changed

# Running from the checkout with `uv run`
git pull                               # uv run re-syncs dependencies automatically

# Dev dependency of another uv project
uv lock --upgrade-package oc-orchestrator
uv sync

Updating never touches your data. Remembered recipes, progress and logs live in %LOCALAPPDATA%\orchestrator, and recipes stay wherever you saved them (e.g. a project's .recipes\). Stop any running loop before updating, since Windows locks the orchestrator.exe shim while it's in use.

Usage

From the project you want the agents to work on:

orchestrator path\to\recipe.yaml   # run a recipe (and remember it for this directory)
orchestrator                       # re-run the remembered recipe, resuming where it stopped
orchestrator my_recipe             # shorthand for .\.recipes\my_recipe.yaml
orchestrator --pick                # open the recipe picker / editor instead
Option
-C, --working-dir DIR Directory steps run in (default: the recipe's working_dir, else the current directory)
--restart / --start-iteration N Ignore the remembered progress
--max-iterations N Stop after N iterations
--log [DIR] Log iterations and step output to DIR (default: %LOCALAPPDATA%\orchestrator\Logs). See below
--olog [DIR] Like --log, and new_window steps also open their own console window
--no-log Turn logging off even if the recipe enables it
--go Start the TUI run immediately. By default it opens paused (press p to start)
--headless Plain console output instead of the TUI (automatic when not attached to a terminal). Always starts immediately
--plan [N] Print which steps run on each of the first N iterations, plus the expanded commands, then exit
--forget, --where Forget this directory's recipe / show where memory and logs live

The TUI

  • Dashboard: current iteration, per-step status and timers, iteration history, agent-memory turns, live step output, and an event log. A run opens paused, so you can check the recipe and settings first. Press p to start, or launch with --go.
    • Step output is tabbed: one tab for the step itself, plus a tab for every sub-agent an opencode step starts. Sub-agent tabs are added as the sessions appear; [ and ] cycle through them. A finished sub-agent's tab is marked ✔.
    • Keys: p start / pause between iterations / resume, k skip the running step (it counts as skipped, not failed, and the iteration carries on), s skip the current wait/backoff, a stop after this iteration, o open the log folder, f toggle output auto-scroll, [ / ] previous / next log tab, q quit (asks whether to stop now or after the iteration).
  • Recipe picker: lists recipes in ./.recipes and recently used ones, or loads a typed path. The Max iterations box next to Run defaults to endless (blank or 0). It shows the highlighted recipe's own max_iterations (or --max-iterations if you passed it) until you type in it, and the value shown is what the run uses.
  • Recipe editor: assemble or edit a recipe as a form. It has tabs for general settings, OpenCode defaults, steps, variables and a live YAML preview, and saves to ./.recipes/ by default. Ctrl+S saves; Ctrl+R saves and runs. A step with a Prompt and no Command is a first-party opencode agent step.

Memory

The last recipe used in each directory, the next iteration number, and (when enabled) the opencode session shared by remembered steps are stored in %LOCALAPPDATA%\orchestrator\directories.json. You only pick or assemble a recipe once per project. After that, a bare orchestrator resumes it. --restart starts the iteration count over and forgets the remembered opencode session.

Logging

By default, every step runs as a silent background process with no window, and its output streams into the dashboard's Step output pane (or the console with --headless). Nothing is written to disk.

  • --log [DIR] also writes everything to DIR. A bare --log, or log: true in the recipe, uses %LOCALAPPDATA%\orchestrator\Logs. That is outside the workspace, so agents won't read or commit the logs. You'll get a warning if you point DIR inside the workspace.
  • --olog [DIR] logs the same way. In addition, steps with new_window: true (the default) open in their own console window, so you can watch them there as well as in the dashboard.

Since DIR is optional, write the recipe before the flag (orchestrator my_recipe --log D:\logs), or use --log=DIR. Otherwise the recipe name is read as the directory.

<DIR>\<project>-<hash>\<timestamp>\
    recipe.yaml                  snapshot of what ran
    run.log                      orchestrator events
    iter-0007\02-execute.log     full output of each step
    iter-0007\02-execute.subagents\
        audit-entity-pages-1a2b3c4d.log

With --olog, each window is wrapped in a small tee that copies its output into the step log, and the dashboard tails that log. Programs often stop colouring their output when it's captured like this.

Sub-agent logs

When a step runs opencode (a prompt: step, or a command: step whose program is opencode), the orchestrator also follows the sub-agents that step starts. opencode records each child session in its own SQLite database (%USERPROFILE%\.local\share\opencode\opencode.db, or $XDG_DATA_HOME/opencode/opencode.db), with parent_id pointing at the step's root session. The orchestrator waits for that root session to appear, then tails every descendant session and streams its text, reasoning and tool output into its own dashboard tab and its own log file. Nested sub-agents are followed too.

  • The step's root session is matched by the prompt text passed to opencode run; if a wrapper rewrites the prompt, it falls back to the only new session started in the working directory.
  • Set OPENCODE_DB to use a different database path.
  • This is opencode-specific. Other CLI agents still stream their own stdout normally; they just won't have sub-agent tabs.

Recipes

name: Long-horizon loop
description: optional
working_dir: ../project      # optional; relative to this file. Default: where you launch orchestrator
log: false                   # enable logging by default

loop:
  delay: 1                   # seconds between successful iterations
  backoff_base: 30           # wait after the 1st failed iteration; doubles each time...
  max_backoff: 900           # ...up to this cap
  max_iterations: 0          # 0 = forever

vars:                        # reusable text, referenced as ${name}
  agent: opencode
  plan_prompt: >-
    Read GOAL.md, then write one bounded next step to NOTES/next_step.md.

steps:
  - name: Plan
    command: ["${agent}", run, "${plan_prompt}"]   # list of arguments, no shell involved

  - name: Review
    command: ["${agent}", run, "Audit NOTES/ (iteration ${iteration})"]
    every: 3                 # only on iterations divisible by 3...
    also_first: true         # ...and on iteration 1
    critical: false          # a failure here doesn't abort the remaining steps

  - name: Commit
    command: [commit.bat]    # looked up in the working dir first, then on PATH
    new_window: false        # never give this one a window, even with --olog
    skip_if_missing: commit.bat

  - name: Experimental
    command: ["${agent}", run, "try something"]
    skip: true               # keep the step in the recipe, but don't run it
  • Step defaults: new_window: true (only matters with --olog, Windows only), critical: true (a failure aborts the rest of the iteration), every: 1.
  • Placeholders: ${iteration}, ${working_dir} and ${recipe_dir} are built in. Unknown ${...} and plain {braces} are left untouched.
  • Examples: examples/long_horizon.yaml is a generic starting point; examples/opencode_memory.yaml shows the first-party opencode prompt form with memory. Personal recipes go in .recipes/, which is gitignored.

OpenCode steps and memory

opencode is a first-party agent: a step can be a prompt: instead of a command:. The orchestrator builds the command, can keep one opencode session alive across steps, and follows that session's sub-agents.

name: Continuous paper
loop:
  delay: 1

opencode:
  command: opencode     # executable for prompt steps (default)
  agent: build          # optional default --agent
  model: deepseek/deepseek-flash   # optional default -m
  remember: true        # continue one session across remembered steps
  clear_after: 8        # start a clean session after 8 remembered turns (0 = never)
  follow_subagents: true

vars:
  plan_prompt: >-
    Read GOAL.md, then write one bounded next step to NOTES/next_step.md.

steps:
  - name: Plan
    prompt: "${plan_prompt}"      # first-party opencode step

  - name: Execute
    prompt: "Implement the plan in NOTES/next_step.md, then verify the build."
    remember: true                # per-step override (null = the recipe default)
    agent: build                  # per-step override
    model: deepseek/deepseek-flash

  - name: Commit
    command: [git, commit, -am, "orchestrator: iteration ${iteration}"]
    new_window: false
    critical: false
  • A remembered step runs opencode run --session <id> <prompt>, so the agent sees the earlier steps' conversation. The session id and turn count are remembered per directory, so stopping and resuming orchestrator picks up where it left off.
  • clear_after: N counts remembered agent turns, not iterations. When the count reaches N, the next turn starts a new session; the old session is left in opencode's history.
  • remember: false on a step runs it in a fresh session without changing the shared one. --restart forgets the shared session; switching this directory to a different recipe does too.
  • Existing command: steps named opencode participate automatically when opencode.remember is on; the orchestrator inserts --session after run. If a command already has --session, the recipe's choice wins.
  • follow_subagents: false disables the sub-agent tabs and transcripts but still lets remembered steps discover and store their root session.

Development

uv sync
uv run pytest

The code lives in src/orchestrator/:

File Purpose
recipe.py Recipe model and YAML I/O
runner.py Iteration loop
opencode.py First-party opencode settings, commands and sessions
subagents.py opencode sub-agent session follower
session.py CLI options → runner
memory.py, runlog.py App-data storage
_tee.py Window output tee
console.py Headless front end
tui/ Textual front end