From 6272c8006778e16e0964d87c71d80440a9a2aa20 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Tue, 10 Feb 2026 02:28:31 -0500 Subject: [PATCH] feat: send x-session-id and x-parent-session-id headers in LLM API requests Forward opencode session identifiers as HTTP headers on all outgoing LLM API requests. This enables OpenAI-compatible servers to correlate requests belonging to the same session and reconstruct parent/child agent trees (e.g. when the task tool spawns sub-agents). Two new headers are sent: - x-session-id: always present, identifies the current session - x-parent-session-id: present only for sub-agent sessions, identifies the parent session that spawned this one This is a minimal, non-breaking change: - parentSessionID is optional on StreamInput - Existing callers (summary, title) that don't pass it simply omit the parent header - Headers are additive and ignored by providers that don't use them Closes anomalyco/opencode#12930 --- packages/opencode/src/session/llm.ts | 3 +++ packages/opencode/src/session/prompt.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index 4be6e2538f7..dcfdca97d7a 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -31,6 +31,7 @@ export namespace LLM { export type StreamInput = { user: MessageV2.User sessionID: string + parentSessionID?: string model: Provider.Model agent: Agent.Info system: string[] @@ -228,6 +229,8 @@ export namespace LLM { "User-Agent": `opencode/${Installation.VERSION}`, } : undefined), + "x-session-id": input.sessionID, + ...(input.parentSessionID ? { "x-parent-session-id": input.parentSessionID } : undefined), ...input.model.headers, ...headers, }, diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index d7f73b4f609..9b5f6eb1e44 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -625,6 +625,7 @@ export namespace SessionPrompt { agent, abort, sessionID, + parentSessionID: session.parentID, system: [...(await SystemPrompt.environment(model)), ...(await InstructionPrompt.system())], messages: [ ...MessageV2.toModelMessages(sessionMessages, model),