[FEATURE]: Inject current session ID into Plan/Build agent system prompts #8624

Open
opened 2026-02-16 18:10:24 -05:00 by yindo · 1 comment
Owner

Originally created by @pedrorach16 on GitHub (Feb 5, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Motivation

Currently, the Plan and Build agents (and other primary agents) have no awareness of the unique session ID (ses_...) they are running in. This ID is visible to users via CLI commands like opencode session list and is useful for session management, resuming sessions, or referencing sessions in external tools/scripts.

Giving agents explicit knowledge of their own session ID would enable several useful behaviors:

  • Agents could reference their session ID in logs, comments, or generated documentation.
  • Agents could generate commands that include the session ID (e.g., suggesting opencode --session <current_id> ... for resuming or sharing).
  • Better self-awareness in multi-session workflows, especially when agents create child sessions.
  • Easier integration with external tooling that needs to correlate agent output with the specific session.

This is particularly valuable as session management becomes more central to OpenCode workflows.

Proposed Solution

Add the current session ID to the system prompt of primary agents (Plan, Build, and any custom primary agents). Example addition:

You are operating in session ID: ses_abc123def456

This could be injected dynamically when the agent is initialized, similar to how other contextual information is already added to prompts.

The injection could:

  • Be optional (via config flag if desired, but default-on is fine).
  • Apply to both Plan and Build modes.
  • Ideally also apply to custom primary agents defined in ~/.opencode/agent/.

Prompt-level injection is the most direct way to give agents true awareness.

Additional Context

No existing issue directly requests prompt-level session ID injection. This feature would complement ongoing session-related improvements.

Thanks for considering!

Originally created by @pedrorach16 on GitHub (Feb 5, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ### Motivation Currently, the Plan and Build agents (and other primary agents) have no awareness of the unique session ID (`ses_...`) they are running in. This ID is visible to users via CLI commands like `opencode session list` and is useful for session management, resuming sessions, or referencing sessions in external tools/scripts. Giving agents explicit knowledge of their own session ID would enable several useful behaviors: - Agents could reference their session ID in logs, comments, or generated documentation. - Agents could generate commands that include the session ID (e.g., suggesting `opencode --session <current_id> ...` for resuming or sharing). - Better self-awareness in multi-session workflows, especially when agents create child sessions. - Easier integration with external tooling that needs to correlate agent output with the specific session. This is particularly valuable as session management becomes more central to OpenCode workflows. ### Proposed Solution Add the current session ID to the system prompt of primary agents (Plan, Build, and any custom primary agents). Example addition: You are operating in session ID: ses_abc123def456 This could be injected dynamically when the agent is initialized, similar to how other contextual information is already added to prompts. The injection could: - Be optional (via config flag if desired, but default-on is fine). - Apply to both Plan and Build modes. - Ideally also apply to custom primary agents defined in `~/.opencode/agent/`. Prompt-level injection is the most direct way to give agents true awareness. ### Additional Context No existing issue directly requests prompt-level session ID injection. This feature would complement ongoing session-related improvements. Thanks for considering!
yindo added the discussion label 2026-02-16 18:10:24 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 5, 2026):

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

  • #7492: Primary agents lack identity awareness when user switches agents - cannot determine which agent is active
  • #9065: Add model identity info to system prompt
  • #6279: Feature: Pass session identifier to MCP servers

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

@github-actions[bot] commented on GitHub (Feb 5, 2026): This issue might be a duplicate of existing issues. Please check: - #7492: Primary agents lack identity awareness when user switches agents - cannot determine which agent is active - #9065: Add model identity info to system prompt - #6279: Feature: Pass session identifier to MCP servers Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8624