claude-agent: bound idle claude processes and stop finished subagents early
Problem
In packages/core/src/plugin/provider/claude-agent/claude/sessions.ts, every primary session — including subagents — spawns its own claude subprocess (required by the Claude Agent SDK's 1-session-per-subprocess model) and keeps it alive for IDLE_MS = 5 * 60_000 with no cap on total idle processes.
During subagent-heavy workflows (missions, parallel reviews, exploration), many finished subagent claude processes remain resident in memory simultaneously for 5 minutes even though most finished subagents never receive another prompt, and disk resume already handles follow-ups.
Proposal
- Stop finished subagent
claudeprocesses immediately onsession.execution.succeeded(or after a much shorter idle grace period, e.g. 15–30s), relying on existing sessionresumeif a follow-up arrives. - Add an LRU cap on warm idle
claudeprocesses (evicting the oldest idle non-waiting process when a new one starts), and allow configuring the idle timeout / cap.
Thanks for the detailed write-up! You're asking for two things in the claude-agent provider: stop finished subagent claude processes right away (or after a short grace period) and rely on resume for follow-ups, and cap the number of warm idle processes with an LRU, with the idle timeout and cap configurable.
The provider currently keeps each session's process for IDLE_MS = 5 * 60_000 in packages/core/src/plugin/provider/claude-agent/claude/sessions.ts, and the timer starts once OpenCode stops running the session. In the code I read, I didn't find a limit on how many idle processes can stay resident, and I didn't find a setting for the timeout. So I've filed this as a feature request, and maintainers will consider it.
Related:
- #62648: a
claudeprocess kept running after its session was deleted, fixed by #62649. That covered deleted sessions, not idle subagent processes.
I didn't find an open pull request for this yet.