You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the suggestion! You're asking for a sleep() global in Code Mode so the model can space out tool calls, for example to stay under an API's rate limit. Right now Code Mode deliberately has no timers (the only extra global is fetch), and plugins can't add new globals. Maintainers will consider this, but I can't promise when or whether it will happen.
In the meantime, a small plugin can register a sleep tool that Code Mode can call. Save this as .opencode/plugins/codemode-sleep.ts in your project, or as ~/.config/opencode/plugins/codemode-sleep.ts to use it everywhere:
import{Plugin}from"@opencode/plugin"constMAX_MS=60_000exportdefaultPlugin.define({id: "codemode-sleep",setup: async(ctx)=>{awaitctx.tool.transform((editor)=>{editor.add({name: "sleep",description: `Wait for the given number of milliseconds (max ${MAX_MS}) before continuing, e.g. to throttle rate-limited calls.`,input: {type: "object",properties: {ms: {type: "integer",minimum: 0,maximum: MAX_MS}},required: ["ms"],additionalProperties: false,},options: {codemode: true},execute: async(input,context)=>{constms=Math.min(Math.max(0,Number((inputas{ms: number}).ms)||0),MAX_MS)awaitnewPromise<void>((resolve,reject)=>{consttimer=setTimeout(resolve,ms)context.signal.addEventListener("abort",()=>{clearTimeout(timer)reject(context.signal.reason)},{once: true})})return{content: `Slept ${ms}ms`}},})})},})
The model should then be able to call await tools.sleep({ ms: 1000 }) between calls inside execute. Each call is capped at 60 seconds, and stopping the session cancels the wait. I've checked that this type-checks against @opencode/plugin but haven't tested it in a running OpenCode.
I'd like to implement sleep(ms) as a native Code Mode global for intentional pauses between tool calls.
Proposed behavior:
Support await sleep(1000) and resolve with undefined.
Accept finite, non-negative millisecond durations and reject invalid values rather than silently coercing them.
Cap each wait at 60 seconds, consistent with the limit discussed in this issue.
Implement the wait with Effect.sleep so execution interruption and timeout cancel the pending wait through the existing Effect runtime.
Add focused tests for elapsed waiting, invalid and out-of-range values, the maximum duration, and interruption.
I'll register the global through the existing interpreter globals mechanism and follow the current native-function conventions. Does this API and limit fit the intended Code Mode design before I proceed with the implementation?
Activity
opencode-agent commentedon Oct 19, 2026
Thanks for the suggestion! You're asking for a
sleep()global in Code Mode so the model can space out tool calls, for example to stay under an API's rate limit. Right now Code Mode deliberately has no timers (the only extra global isfetch), and plugins can't add new globals. Maintainers will consider this, but I can't promise when or whether it will happen.In the meantime, a small plugin can register a
sleeptool that Code Mode can call. Save this as.opencode/plugins/codemode-sleep.tsin your project, or as~/.config/opencode/plugins/codemode-sleep.tsto use it everywhere:The model should then be able to call
await tools.sleep({ ms: 1000 })between calls insideexecute. Each call is capped at 60 seconds, and stopping the session cancels the wait. I've checked that this type-checks against@opencode/pluginbut haven't tested it in a running OpenCode.Related issues:
executeand plugin tool calls have no timeout, which is why the plugin above caps the waitexecutehangs when a program awaits a promise that never settlesexecutecalls move to the backgroundaviralb1311 commentedon Oct 19, 2026
I'd like to implement
sleep(ms)as a native Code Mode global for intentional pauses between tool calls.Proposed behavior:
await sleep(1000)and resolve withundefined.Effect.sleepso execution interruption and timeout cancel the pending wait through the existing Effect runtime.I'll register the global through the existing interpreter globals mechanism and follow the current native-function conventions. Does this API and limit fit the intended Code Mode design before I proceed with the implementation?