[FEATURE]: Agent-level resume for subagents (resumeSessionId parameter) #4062

Open
opened 2026-02-16 17:42:29 -05:00 by yindo · 4 comments
Owner

Originally created by @Steffen025 on GitHub (Jan 1, 2026).

Originally assigned to: @thdxr on GitHub.

Problem Statement

When building multi-phase agent workflows, there's currently no way to resume a specific subagent with its previous context. Each Task/subagent invocation starts fresh.

Use Case

Complex workflows like specification-driven development have multiple phases:

  1. Specify - Architect agent creates specs
  2. Clarify - Same architect resolves ambiguities
  3. Implement - Engineer agent writes code
  4. Validate - Same engineer runs tests

Currently, the engineer in step 4 has no memory of what they implemented in step 3. The context is lost between invocations.

Proposed Solution

Add an optional resumeSessionId parameter to subagent invocation:

// First call - returns session ID
const result = await invokeSubagent({
  agent: "engineer",
  task: "Implement the auth system based on these specs..."
});
// result.sessionId: "xyz789"

// Later - resume with full context
const continued = await invokeSubagent({
  agent: "engineer", 
  task: "Now add tests for the auth system you just built",
  resumeSessionId: "xyz789"  // Load previous session context
});

Technical Considerations

What would need to change:

  1. Subagent API - Add optional resumeSessionId parameter
  2. Session metadata - Store/expose child session IDs to parent
  3. Context loading - When resuming, prepend previous child session events to new session
  4. Session lifecycle - Make child sessions persistent and queryable by parent

Current architecture (from my understanding):

# Parent session
~/.opencode/sessions/abc123.jsonl

# Child session (ephemeral)
~/.opencode/sessions/xyz789.jsonl  # Currently no way to reference later

Alternatives Considered

  1. Manual context injection - Parent could summarize and inject previous work, but loses nuance and adds token overhead
  2. Session-level resume - /sessions works for whole conversations but not individual subagents
  3. Longer initial prompts - Include everything upfront, but context windows have limits

Additional Context

This came up while migrating PAI (Personal AI Infrastructure) to run on OpenCode. PAI's Task tool has a resume parameter that enables stateful agent workflows.

Related: Issue #6558 (model selection for subagents) - similar pattern of adding optional Task parameters.

Happy to help with implementation if this is something the team is interested in!

Originally created by @Steffen025 on GitHub (Jan 1, 2026). Originally assigned to: @thdxr on GitHub. ## Problem Statement When building multi-phase agent workflows, there's currently no way to resume a specific subagent with its previous context. Each Task/subagent invocation starts fresh. ## Use Case Complex workflows like specification-driven development have multiple phases: 1. **Specify** - Architect agent creates specs 2. **Clarify** - Same architect resolves ambiguities 3. **Implement** - Engineer agent writes code 4. **Validate** - Same engineer runs tests Currently, the engineer in step 4 has no memory of what they implemented in step 3. The context is lost between invocations. ## Proposed Solution Add an optional `resumeSessionId` parameter to subagent invocation: ```typescript // First call - returns session ID const result = await invokeSubagent({ agent: "engineer", task: "Implement the auth system based on these specs..." }); // result.sessionId: "xyz789" // Later - resume with full context const continued = await invokeSubagent({ agent: "engineer", task: "Now add tests for the auth system you just built", resumeSessionId: "xyz789" // Load previous session context }); ``` ## Technical Considerations **What would need to change:** 1. **Subagent API** - Add optional `resumeSessionId` parameter 2. **Session metadata** - Store/expose child session IDs to parent 3. **Context loading** - When resuming, prepend previous child session events to new session 4. **Session lifecycle** - Make child sessions persistent and queryable by parent **Current architecture (from my understanding):** ```bash # Parent session ~/.opencode/sessions/abc123.jsonl # Child session (ephemeral) ~/.opencode/sessions/xyz789.jsonl # Currently no way to reference later ``` ## Alternatives Considered 1. **Manual context injection** - Parent could summarize and inject previous work, but loses nuance and adds token overhead 2. **Session-level resume** - `/sessions` works for whole conversations but not individual subagents 3. **Longer initial prompts** - Include everything upfront, but context windows have limits ## Additional Context This came up while migrating [PAI (Personal AI Infrastructure)](https://github.com/danielmiessler/PAI) to run on OpenCode. PAI's Task tool has a `resume` parameter that enables stateful agent workflows. Related: Issue #6558 (model selection for subagents) - similar pattern of adding optional Task parameters. Happy to help with implementation if this is something the team is interested in!
Author
Owner

@github-actions[bot] commented on GitHub (Jan 1, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6558: [FEATURE]: give task/subagent an optional config to choose what model it runs on - Similar pattern of adding optional Task/subagent parameters for enhanced control
  • #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API - Related to subagent session handling and context persistence challenges
  • #6491: Session does not automatically return to parent after subagent execution - Related to subagent lifecycle and context management

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 1, 2026): This issue might be a duplicate of existing issues. Please check: - #6558: [FEATURE]: give task/subagent an optional config to choose what model it runs on - Similar pattern of adding optional Task/subagent parameters for enhanced control - #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API - Related to subagent session handling and context persistence challenges - #6491: Session does not automatically return to parent after subagent execution - Related to subagent lifecycle and context management Feel free to ignore if none of these address your specific case.
Author
Owner

@machinekoder commented on GitHub (Jan 23, 2026):

Reading this paper about „Recursive LM“ https://arxiv.org/abs/2512.24601 suggests splitting LM sessions into smaller chunks improves overall performance on research intensive tasks. Being able to continue subagent sessions would mean the main agent could outsource such tasks completely, imagine the subagent (or a user session) explored the communication patterns between two frameworks. The main agent could just ask follow up questions without wasting additional tokens and polluting its own context window.

@machinekoder commented on GitHub (Jan 23, 2026): Reading this paper about „Recursive LM“ https://arxiv.org/abs/2512.24601 suggests splitting LM sessions into smaller chunks improves overall performance on research intensive tasks. Being able to continue subagent sessions would mean the main agent could outsource such tasks completely, imagine the subagent (or a user session) explored the communication patterns between two frameworks. The main agent could just ask follow up questions without wasting additional tokens and polluting its own context window.
Author
Owner

@machinekoder commented on GitHub (Jan 23, 2026):

It might be even more powerful to combine this feature with OpenCode's session forking tools.

@machinekoder commented on GitHub (Jan 23, 2026): It might be even more powerful to combine this feature with OpenCode's session forking tools.
Author
Owner

@Steffen025 commented on GitHub (Jan 23, 2026):

@thdxr - any news regarding this Feature request?
Do you think about implementing it?

@Steffen025 commented on GitHub (Jan 23, 2026): @thdxr - any news regarding this Feature request? Do you think about implementing it?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4062