Skip to content

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

Closed as not planned

Description

@pedrorach16

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!

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Feb 5, 2026
  2. github-actions commented on Feb 5, 2026

    @github-actions
    Contributor

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

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

  3. too-green commented on Mar 29, 2026

    @too-green
    import { tool } from "@opencode-ai/plugin"
    
    export default tool({
      description:
        "Get the current opencode session's metadata: session ID, working directory, and worktree root. Call this at the start of a session to learn your own identity, or anytime you need to reference your session ID for logging, status updates, or coordination with other agents.",
      args: {},
      async execute(_args, context) {
        const { agent, sessionID, messageID, directory, worktree } = context
    
        const lines = [
          `Session ID: ${sessionID}`,
          // `Agent: ${agent || "default"}`,
          // `Current Message ID: ${messageID}`,
          `Working Directory: ${directory}`,
          `Worktree Root: ${worktree || directory}`,
        ]
    
        return lines.join("\n")
      },
    })
    

    created a custom tool using an agent ofc. Tested. Works.
    Adds a tool call, but gets the job done.

  4. assigned and unassigned on Apr 26, 2026
  5. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on May 3, 2026
  6. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions