You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Inject current session ID into Plan/Build agent system prompts #12324
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.
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.
Activity
github-actions commentedon Feb 5, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
too-green commentedon Mar 29, 2026
created a custom tool using an agent ofc. Tested. Works.
Adds a tool call, but gets the job done.
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.