@brianlan/opencode-loop
v0.3.0
Published
OpenCode plugin for session-scoped recurring loops
Maintainers
Readme
opencode-loop
An OpenCode plugin that lets you create, list, and delete session-scoped recurring loops (like cron jobs, but temporary).
Key difference from system cron
These loops live only in memory. They automatically disappear when:
- The OpenCode TUI / process exits
- The session is deleted
This is by design — perfect for temporary automation within a coding session without leaving background tasks behind.
Features
- cron_create – Add a recurring loop using standard 5-field cron syntax
- cron_compact_create – Schedule recurring session compaction
- cron_list – View loops in the current session
- cron_delete – Remove a loop by name
When a loop triggers, it sends a prompt back into the same OpenCode session, so the AI picks it up in the next loop turn. Schedules use standard five-field cron syntax and the OpenCode server's local timezone. The loop keeps the agent that created it. Due jobs wait until the session is idle, so they do not intentionally overlap an active turn.
Installation
Option A: bunx (zero-config)
Run this inside your project directory:
bunx @brianlan/opencode-loop installThis creates .opencode/plugins/opencode-loop.js automatically. Restart OpenCode and the plugin is ready.
Option B: npm package
bun add -d @brianlan/opencode-loop
# or: npm install -D @brianlan/opencode-loopThen in opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@brianlan/opencode-loop"]
}Option C: manual
Copy dist/index.js into .opencode/plugins/opencode-loop.js in your project.
Usage
Once installed, just ask OpenCode:
- "Create a loop called
healthcheckthat runs every 5 minutes and tells me to run the test suite" - "List my loops"
- "Delete the healthcheck loop"
Example behind the scenes:
cron_create(name="healthcheck", schedule="*/5 * * * *", command="Run the test suite and report any failures")Every 5 minutes, the plugin injects a prompt into the current session:
[Scheduled loop triggered at 2026-06-18T12:05:00.000Z] "healthcheck": Run the test suite and report any failuresThe AI then acts on it just like a normal user message.
To run once as soon as the current turn becomes idle and then continue on the normal cron schedule:
cron_create(
name="healthcheck",
schedule="*/5 * * * *",
command="Run the test suite and report any failures",
runImmediately=true
)The initial run does not shift the cron schedule. If an immediate run and a scheduled occurrence both become due while the session is busy, they are coalesced into one pending run.
To compact the current session every two hours:
cron_compact_create(
name="periodic-compact",
schedule="0 */2 * * *",
runImmediately=false
)Compaction also waits for the session to become idle and uses the latest model recorded in that session.
Permissions
This plugin inherits the current agent's permission rules. It does not add any new permission surfaces — when the AI acts on a triggered prompt, it goes through the normal OpenCode tool-approval flow.
License
MIT
