opencode icon indicating copy to clipboard operation
opencode copied to clipboard

claude-agent: bound idle claude processes and stop finished subagents early

Open pascalandr opened this issue 1 week ago • 1 comments

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

  1. Stop finished subagent claude processes immediately on session.execution.succeeded (or after a much shorter idle grace period, e.g. 15–30s), relying on existing session resume if a follow-up arrives.
  2. Add an LRU cap on warm idle claude processes (evicting the oldest idle non-waiting process when a new one starts), and allow configuring the idle timeout / cap.

pascalandr avatar Nov 24 '26 21:11 pascalandr

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 claude process 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.

opencodejr[bot] avatar Nov 24 '26 21:11 opencodejr[bot]