opencode-goal-plugin
A persistent /goal command for OpenCode 2. Set a standing goal and the agent keeps
working on it across turns — no re-typing "keep going" — until the goal is achieved, judged
unachievable, stalled, or out of turns.
/goal Fix every failing test in tests/api and make sure scripts/run-tests.sh passes for that directory
Targets OpenCode 2.0.18 and the V2 plugin API (@opencode/plugin ^2.0.18).
It does not work on OpenCode 1.x.
Why a plugin and not a custom command?
OpenCode custom commands (.opencode/commands/*.md) are prompt templates. They can expand
arguments and shell blocks, but they cannot react to a turn finishing, call a model outside
the conversation, or feed a prompt back into a session. A goal loop needs all three, so this
is a V2 server plugin.
How it works
/goal <text> stores the goal against the current session and submits the first turn.
- When the turn settles, a judge model reads the goal and the agent's last reply and
returns strict JSON:
{"verdict": "done" | "blocked" | "continue", "reason": "…"}, plus a
met list of satisfied subgoals when the goal has any.
continue posts a continuation prompt straight back into the same session, and the loop
repeats. The judge sees the loop's own history (turn number, tool calls last turn,
consecutive no-change turns, its previous verdict), so it can recognise a loop it is
inside of.
- Anything other than
continue stops the loop and reports why.
The judge is called through ctx.generate.text, which creates no session and adds nothing to
the transcript. By default it runs on the same model as the session; point judgeModel at a
small fast model to cut cost (the call is ~200 output tokens, once per turn).
Features
- Standing goals that survive across turns, stored per session in durable plugin storage.
An active goal also survives an OpenCode restart and picks the loop back up on your next
message.
- Subgoals — append acceptance criteria mid-goal with
/subgoal. Every criterion must be
met before the judge may say done, and the list survives /goal resume.
- Plan progress — when the agent keeps a todo list (
todowrite) or a markdown checklist,
every placement shows 37/245 (15%): the panel, footer, composer and sidebar.
- Completion contracts — attach
verify:, constraints:, scope: and stop when:
lines to a goal so the judge knows what "done" actually means instead of guessing. A field
may be a fence when it needs more than one paragraph. verify-cmd: is a cheap re-read the
plugin actually runs.
- Five independent stop conditions, three of them deterministic (see below), so a runaway
loop cannot burn a budget unattended.
- Per-session state — goals are keyed by session ID, so several projects can have
unrelated goals running at once.
- User messages always win — interrupting or a failing turn pauses the loop instead of
being retried forever.
- Status control —
/goal status, pause, resume, clear.
Install
Globally (recommended, all projects)
git clone https://github.com/zignd/opencode-goal-plugin.git ~/.config/opencode/plugins/goal
cd ~/.config/opencode/plugins/goal
npm install
~/.config/opencode/plugins/ is auto-discovered, so the clone is all you need. To confirm,
type / in the TUI — /goal should be in the list.
Do not use opencode plugin list to verify a discovery install. That command reports
plugins declared in the plugins array of your config, so a plugin installed purely by
directory discovery will not appear in it even while working perfectly.
As a configured package plugin
opencode plugin add github:zignd/opencode-goal-plugin
Per project only
git clone https://github.com/zignd/opencode-goal-plugin.git .opencode/plugins/goal
cd .opencode/plugins/goal && npm install
Options
The plugins array is also the only way to pass configuration, so add it to
~/.config/opencode/opencode.json (or a project opencode.json) if you want to change the
defaults:
{
"$schema": "https://opencode.ai/config.json",
"plugins": [
{
"package": "./plugins/goal",
"options": {
"maxTurns": 20,
"stallLimit": 2,
"pollLimit": 3,
"judgeModel": { "providerID": "openrouter", "id": "google/gemini-3-flash-preview" }
}
}
]
}
| Option |
Default |
Meaning |
maxTurns |
20 |
Automatic continuation turns before the loop auto-pauses. A whole number, or "unlimited" / null for no ceiling. The initial /goal turn is not counted, so 20 allows 21 agent executions in total. See below. |
stallLimit |
2 |
Consecutive turns that ran no tools before the loop is declared stalled. |
pollLimit |
3 |
Consecutive turns that re-read an unchanged result before the loop is called polling. Distinct from stallLimit: a polling turn does use tools, it just learns nothing. |
judgeModel |
session model |
Model used for the done / continue / blocked verdict. |
quiet |
false |
Stop posting the loop's turn banner and completion notices into the transcript while the panel is open. |
verifyTimeoutMs |
120000 |
Timeout for one verify-cmd re-read. Capped at 5 minutes. A five-gate is the wrong command for this field. |
What a "turn" is
A turn is one complete run of the agent loop. One prompt goes in, the model works —
calling as many tools as it needs — and produces a final reply. That reply ends the turn,
and OpenCode emits session.execution.succeeded, which is the event this plugin waits for
before asking the judge anything.
A turn is not a tool call, and not a message. A single turn can contain a dozen tool
calls and a long final answer, and it still counts once.
maxTurns counts only the continuation turns that the plugin injects after the judge
answers continue. The original /goal <text> turn is turn zero and is not counted, so the
default budget looks like this:
1 the /goal prompt itself
+ 20 automatic continuations, numbered 1/20 … 20/20
─────
21 agent executions before the loop pauses
The judge is consulted once per settled turn, including the last one, so a full budget is 21
agent executions and 21 judge calls.
Session settings
Four settings, each with a default in the plugin options and an override for the current
session. The override applies at once, including to a goal that is already running, and lasts
until the session ends — it never rewrites your config.
| Subcommand |
Option |
Notes |
/goal budget <n|inf|default> |
maxTurns |
See Removing the turn limit |
/goal stall <n|default> |
stallLimit |
Turns with no tool calls before giving up |
/goal poll <n|default> |
pollLimit |
Turns reading the same unchanged result before calling it polling |
/goal quiet <on|off|default> |
quiet |
When on, the panel replaces the loop's transcript notices |
/goal judge <provider/model[#variant]|default> |
judgeModel |
Cheaper and sharper models judge better and cost less |
/goal settings |
— |
Change any of them in a window, and see whether each is a session override or the config default |
What a subcommand reply costs
A synthetic session message is a real prompt: it starts an execution and costs a model call, and
the agent then repeats the confirmation back at you. For a one-line "stall limit is now 5" that
is pure waste.
So the settings subcommands answer through the TUI as a toast when one is attached, and fall back
to the transcript only when there is no TUI to show it — desktop, the web client,
opencode run. /goal settings uses a dialog the same way, and /goal panel and
/goal display already worked this way.
| Subcommand |
Reply |
/goal stall, /goal quiet, /goal judge, /goal budget <n> |
toast, no model call |
/goal settings |
dialog, no model call |
/goal panel, /goal display |
toast, no model call |
/subgoal <text>, /subgoal remove <n>, /subgoal clear |
toast, no model call |
/subgoal |
in the transcript, so the full list can be read |
/goal status, /goal pause, /goal resume, /goal clear |
in the transcript, a model call each |
The last row is deliberate. Those are direct answers to something you typed, and /goal status
returning nothing is exactly the bug this table's siblings were built to avoid — a silent command
reads as a broken one. They also print more than fits in a toast. Set quiet: true if the
transcript notices are the part you want gone, though that covers the loop's own reporting rather
than these replies.
/goal settings opens a window in the TUI. Each row is the current value, where it came from, and
clickable controls ([-], [+], presets, [unlimited], [on] / [off], [default]). [type…]
opens a prompt for a number or a model, because that window does not take keys. The command lines
stay at the bottom of the window. With no TUI it prints to the transcript:
Turn budget 20 (config default)
Stall limit 5 turns with no tools (this session)
Quiet mode on (this session)
Judge model openrouter/perceptron/perceptron-mk1.5 (this session)
A model is written provider/model, and the model half may itself contain slashes —
openrouter/perceptron/perceptron-mk1.5 is valid. #variant selects a variant if the model
has one.
Removing the turn limit
The budget is the loop's hard ceiling on cost and wall-clock time. You can lift it per session:
/goal budget inf no turn limit
/goal budget 60 a specific limit
/goal budget default back to the configured maxTurns
/goal budget report the current one
inf is the short spelling. unlim, unlimited, unbounded, infinite, inf., none,
no-limit and ∞ all work too.
It applies to the running goal immediately and to every goal set afterwards in that session.
maxTurns: "unlimited" in the plugin options does the same thing as the default.
What you give up. With no ceiling, the only things that stop the loop are:
| Still stops it |
|
The judge says done |
the goal is met, with evidence |
The judge says blocked |
the goal is unreachable, on goal-level evidence |
| Stall guard |
stallLimit consecutive turns with no tool calls |
| Polling guard |
pollLimit consecutive turns with an unchanged result |
| Repetition guard |
the same reply twice running |
| Polling guard |
3 turns that re-read an unchanged result |
| You |
/goal pause, /goal clear, or esc |
So an agent that keeps making small, genuine-looking progress can now run indefinitely. Nothing
caps total spend. If you want a middle ground, /goal budget 500 gives most of the headroom
with a real ceiling. The panel shows turn 7/∞ and says so explicitly while unlimited.
You can watch the counter in the transcript:
↻ [continuing toward your standing goal — turn 3/20]
and in /goal status as 3/20 turns used. /goal resume resets it to zero, which hands you
another full budget.
Treat the budget as a ceiling, not a target. Every turn is a real agent execution plus a
judge call, so in practice the done, stall and repetition guards fire long before it does.
If you are content with the defaults, omit this block entirely — the directory is still
discovered. Declaring it here is not a second copy: the command registry is keyed by name, so
/goal resolves to one command either way, and only the instance owning a session's directory
drives that session's loop.
Usage
| Command |
Effect |
/goal <text> |
Set or replace the goal and immediately start the first turn. |
/goal status |
Show the goal, its state, turns used, and the last judge reason. |
/goal pause |
Stop auto-continuation but keep the goal. |
/goal resume |
Resume the loop with a fresh turn budget. |
/goal clear |
Drop the goal entirely. |
/subgoal <text> |
Add an acceptance criterion to the active goal. |
/subgoal |
List the criteria and which ones are met. |
/subgoal remove <n> |
Remove criterion n, 1-based. |
/subgoal clear |
Drop every criterion but keep the goal. |