Repository navigation
feat(hooks): map OpenCode 2.x stop to experimental.idle and close out OpenCode follow-up items - #3986
Merged
Merged
Conversation
…open OpenCode items Map the canonical stop hook on the opencode target to OpenCode's experimental.idle session hook so a stop command exiting with code 2 continues the agent once, like Pi and oh-my-pi. Document that OpenCode 2.x does not expand @path in stored command templates, and that references, subagent_depth, skills.paths/urls and policies are left to hand-authored opencode.json keys. Refs #2592 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
… stop hooks Skip stop commands for child sessions, fall back to the observe-only session.execution.succeeded event until experimental.idle has run (older OpenCode 2.x silently never triggers it), and clear the continue-once guard when a continued run fails or is interrupted. Refs #2592 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…encode-followup # Conflicts: # src/generated/docs-content.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Works through the items still open on the OpenCode follow-up issue (#2592) after the 2026-11-08 re-check:
opencode):stopnow maps to OpenCode 2.x'sexperimental.idlesession hook. A stop command that exits with code 2 continues the agent once, the way it already does on Pi (agent_before_settle) and oh-my-pi (session_stop). Until now,stopread the observe-onlysession.execution.succeededevent.@pathin stored command templates, while OpenCode 1.x attaches the file.references,subagent_depth/experimental.subagent_depth,skills.paths/skills.urlsandpolicies/experimental.policies. Rulesync does not generate these keys and leaves them as written, so users can set them by hand.Changes
src/types/hooks.ts:CANONICAL_TO_OPENCODE_V2_EVENT_NAMES.stopchanges fromevent:session.execution.succeededtosession:experimental.idle.src/features/hooks/opencode-v2-plugin-generator.ts: the plugin registersctx.session.hook("experimental.idle", ...)for stop handlers:Stoppayload (session_id,stop_hook_active,cwd).Stop hook feedback: ...message and admits it withctx.session.synthetic({ sessionID, text }).stop_hook_active: trueand lets the session go idle.ctx.session.get()(a session with aparentID). Claude Code'sStopdoes not fire for subagents, but OpenCode runs the idle hook for child sessions too.plugin/hooks.tsstores it in a Map). For those hosts the plugin keeps an observe-only fallback onsession.execution.succeeded, which stands down once the idle hook has run. OpenCode publishesSucceededwhen the execution ends (session/execution.ts), after the drain loop that triggers the idle hook, so on 2.2.1+ the commands do not run twice.session.execution.failed/session.execution.interrupted, so a failed or interrupted continued run does not leave the next turn's first stop withstop_hook_active: true.sanitizeBlockReasonhelper and emits it only once whenpreToolUsealready defines it.src/features/hooks/opencode-style-generator.ts: factoredcommandAndInputOf()out ofbuildRunStatement()so the stop runner reuses the same command escaping and stdin expression.stop_hook_active, the background-job wait vs. shells, a throwingsynthetic, and a host without the hook.stopnow useafterError/permissionDenied.docs/reference/file-formats.md: updated the V2 hook mapping and added thestop,@pathand config-key notes.src/generated/docs-content.tsis regenerated.Design decisions
stoptoexperimental.idledespite the experimental label. This follows project precedent:preCompactto OpenCode 1.x'sexperimental.session.compacting.stopto the actionableagent_before_settleand documented a minimum version (Pi v0.87.0), even though older Pi never fires it./goalcommand (packages/core/src/plugin/goal.ts, v2.4.2) is built on this hook, so it is load-bearing upstream.session.execution.succeededfallback. The one documented overlap: an execution that does no model work (for example a manual compaction) before any session has gone idle runs its stop commands once through the fallback.experimental.idlehook fails the whole execution upstream.stop_hook_active: trueand does not continue. This is the same bound oh-my-pi uses, and it is what upstream asks for ("a plugin that always admits input must bound its own loop"). The guard is set only aftersynthetic()succeeds./goalplugin.@path: docs note only, no generate-time warning. Scanning bodies for@would misfire on emails,@mentions, decorators and npm scopes, and the canonical command body is shared across targets.references,subagent_depth,skills.paths/skills.urls,policies: documented as hand-authored, not generated.policiesis a managed-policy layer whose action set keeps changing (the v2.2.3integration.usesplit, thenwebsearch.usein v2.2.6). Generating it would encode rulesync's permission rules a second time.opencode.json(c)leaves unknown top-level keys untouched. I checked this with a scratchgenerate -t opencode -f rules,mcp,permissions,hooks: hand-writtenreferences,experimental.subagent_depth,skills.paths/urlsandpoliciesall survived. So users already have a working path.Skipped items
None remain open. The items above are either implemented or explicitly declined, with reasons, as "not generated; set by hand" in the docs.
Note:
evicts sessionStart contexts in completion order(OpenCode V1, unrelated to this change) times out locally under machine load onorigin/mainas well.Closes #2592
🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4