symcc

OpenCode spike: can a small symcc plugin refuse edits, start a worker in a worktree, wake the lead and show a panel? #

This note keeps the answer of task T-370. The spike files were scratch work and are not committed.

Question #

Can a small symcc plugin for OpenCode (a) refuse edits outside the allowed files, (b) start a worker in a git worktree, (c) wake the lead, and (d) show a panel, plus the other points listed below?

Answer #

Short answer: Yes. Running OpenCode 2.3.0 with a 161-line plugin, I got all 7 points working. Only 3 things need care. A worker started with parentID ignores the folder you give it, so you must move it afterwards. Plugin tools are hidden inside OpenCode's "Code Mode" unless you turn that off. And the plugin starts again for every folder a session works in. The "Claude Agent" provider works with your Claude login, and under the hood it runs the real Claude Code through Anthropic's Agent SDK. Whether that use of a subscription login is allowed is not settled.

How I ran it #

The 7 points #

#WhatResultExact API (2.3.0) and what I saw
1Refuse editsWorksFirst way: throw an error in ctx.tool.hook("execute.before", e => …). The edit fails with {"type":"unknown","message":"symcc: README.md is outside the allowed files src/"}. Writes to src/b.ts still go through.<br>Second way: in ctx.permission.hook("evaluate", e => { e.effect = "deny"; e.message = … }). The edit fails with {"type":"permission.rejected", …}.<br>Both ways also caught calls made from inside Code Mode execute, and calls from a Claude Agent worker.
1bRefuse shell commandsWorks, but only by matching the command textBoth hooks refused shell commands (cat README.md, rm -f …).<br>permission.evaluate gets the command already split into parts, e.g. "sleep 60 && echo done" arrives as ["sleep 60","echo done"].<br>ctx.shell.hook("create.before") shows the command and the folder it runs in (cwd).<br>OpenCode cannot tell which files a shell command writes, so echo x > file can only be caught by pattern-matching the text. Absolute paths outside the folder also raise an external_directory permission check.
2Start a worker in a worktreePartly: it works, with one trapThe trap: session.create({parentID, location:{directory: wt1}, model, permissions}) ignores location when parentID is set. The child gets the parent's folder: pwd printed …/proj, and the worker wrote proj/src/w.ts. I checked this with direct API calls too: without parentID the folder is wt1, with parentID it is proj.<br>The fix: call session.move({sessionID, directory: wt1}) right after. The move takes effect a moment later (session.get right after it still showed proj). After that, pwd = wt1, files land in wt1, and an absolute-path write into proj/ was refused by the hook.<br>Waiting: session.wait works.<br>Results: session.get gives outcome ("succeeded" or "interrupted"), tokens {input, output, reasoning, cache} and cost. session.context gives the messages, so you can read the final text.<br>Interrupt: session.interrupt returned {interrupted:true} after 12 s of a sleep 90, and the outcome was "interrupted".<br>Cost: it was 0 for both the free model and Claude Agent, so it is not useful for cost stats there.
3Wake the leadWorkssession.prompt({sessionID, text, delivery:"queue"}) from a timer, 8 s after the lead went idle: the lead woke and answered "AWAKE".<br>delivery:"steer" while the lead was busy: the text was taken in mid-turn, between two shell commands ("echo steered" ran before "echo two").<br>Also, a child made with parentID sends an automatic message to the parent when it finishes (type:"synthetic", metadata.source:"subagent", state:"completed").
4Panel and strip above the promptWorksIn tui.tsx, ctx.ui.slot({append:"session.panel", render}) draws the panel. It is opened with ctx.ui.panel.open("symcc.board"), from a ctx.keymap.layer command that also gives a /board slash command.<br>ctx.ui.slot({append:"session.composer.top"}) draws the strip above the prompt.<br>Both refreshed on their own every second, from a Solid signal plus setInterval (the tick count went 13 → 16 in the screen captures).
5Lead tool and slash commandWorksctx.tool.transform(t => t.add({name, description, input, execute})) adds a tool.<br>But: by default a plugin tool is only reachable inside Code Mode. The model has to call execute with code like tools.symcc_spawn(...). Adding options:{codemode:false} made symcc_wake_later a normal tool (the model listed it next to edit, shell and the rest).<br>ctx.command.transform(c => c.add({name, execute})) adds a slash command. /symcc-board ran with inv.delivery = "steer" and posted into the chat.
6Git, files, timersWorksPlugins run inside the server under Bun (globalThis.Bun exists, process.version v26.3.0).<br>node:child_process (git worktree list) and node:fs work, and setInterval / setTimeout work in setup.<br>Editing the plugin file reloads it on the fly.
7ModelsWorksLead and workers can use any model OpenCode knows (/api/integration lists hundreds of providers). The model is set per session through model:{providerID,id}.<br>Claude Agent (claude-agent): the only sign-in it offers is "Claude Code login (claude auth login)", meaning your existing login. After POST /api/integration/claude-agent/connect/external, the models opus, fable, sonnet and haiku showed up. A haiku worker in wt1 ran fine. It used OpenCode's tools as mcp__opencode__*, and symcc's hooks still refused its README write.<br>Under the hood (from text inside the binary) it runs the installed claude program through @anthropic-ai/claude-agent-sdk, with settingSources:[] and disableAllHooks:true. So Claude Code's own plugins and hooks are off, and OpenCode's hooks do the guarding.<br>The other way also works: the plugin starts real processes itself. claude -p … --output-format json --model haiku returned PONG, with tokens and costUSD 0.0043. codex exec --json -s read-only returned PONG with usage, but only after closing its stdin. Without that it waits on "Reading additional input from stdin" until it is stopped.

What surprised me #

  1. A worker made with parentID ignores location. You have to call session.move after creating it.
  2. Plugin tools are hidden in Code Mode unless you set options:{codemode:false}.
  3. The plugin runs once per folder. When a worker moved to wt1, a second copy of the plugin started there, with its own setup and its own timers. Its ctx.location.directory is wt1. That is handy for "allowed files are relative to the worktree". But it means symcc's board state can't simply live in plugin memory, and timers would run twice. Guess: the state would need one owner, such as a file lock or a separate symcc daemon.
  4. Claude Agent is the real Claude Code engine with Claude Code's own hooks turned off and OpenCode's tools plugged in. So "real Claude" and "OpenCode's guards" can be had together.
  5. OpenCode has its own built-in schedule_create tool (seen as text inside the binary) and an experimental.idle session hook. I did not try either.
  6. On cost: 0 is reported for subscription and free models.

Is the Claude login allowed? (not settled) #

How symcc's planned Host would map onto OpenCode (docs/research/host-independence.md:175-215) #

Today's hooks

The Host members

MemberOpenCode
agents.startsession.create({model, permissions}) → session.move(worktree) → session.prompt. Or, for real Claude/Codex, child_process running claude -p or codex exec with stdin closed
agents.listsession.list({parentID}) / /api/session/active
agents.stopsession.interrupt (or kill the process)
Results and tokenssession.get, session.context
lead.tellsession.prompt({delivery:"queue"}), and "steer" for urgent things
ui.refresh / openBoardSolid signals in the session.panel slot, and ui.panel.open
ui.statusthe session.composer.top slot
ui.toasttoasts exist according to the docs; not tested
tools() / commands()tool.transform with codemode:false, and command.transform (or TUI keymap slash commands)
fs, run, clocknode:fs, node:child_process, timers. They work in the plugin
leadUsagesession.get on the lead gives tokens (guess: that is enough)

What I could not check #

First OpenCode adapter: build tasks, in order #

  1. Plugin skeleton for 2.3, with a server part and a TUI part. Add a lock so only one plugin copy runs symcc's engine and timers, and the copies in worker folders only enforce refusals (needs designing).
  2. A hooks/opencode/host.ts that builds Host from ctx, with fs, run and clock from Node and Bun.
  3. Edit refusal through permission.hook("evaluate"), using each session's worktree and allowed files. Shell commands checked by text. Stopped agents refused.
  4. host.agents with two runners: OpenCode sessions (create → move → prompt → wait/interrupt, with tokens) and external claude -p / codex exec (stdin closed). The model is chosen per role.
  5. host.lead.tell through session.prompt queue/steer, and the parent wake-up when a worker finishes.
  6. Lead tools (codemode:false) and slash commands, mapped onto Symcc.tools() and Symcc.commands().
  7. TUI: a board in session.panel and the status strip in session.composer.top, fed from the board file and refreshed on a timer or a signal.
  8. A decision from you on the Claude Agent provider versus symcc running claude -p itself, for Claude workers.

Wait until the Host refactor (T-240..T-246) has settled the member names. Then make task 1+2+3 a single first adapter task, starting from the spike's server.ts. Pick the Claude worker path (task 8) before task 4.

Leftovers: