dsh-session-header: Inject session header into Harness LLM requests

Preface

DeepSeek Harness (DSH) places session information in GenerateOptions.sessionId when calling models, but the harness itself lacks a unified “request-level header” extension point: GenerateOptions does not contain a headers field, and each adapter constructs online HTTP headers on its own. If your model gateway, middleware proxy, or audit layer needs to perform routing, caching, or log correlation based on a session header, relying on the harness’s default behavior often cannot send this header.

The community plugin dsh-session-header (maintainer EmotionTowel) uses the harness’s official interception points to inject a configurable session header on every LLM-related fetch, and when needed, overrides requests during tool execution periods that point to specified gateway prefixes. The following introduces its positioning, installation, and typical configuration.

What Is This

dsh-session-header is a Cordis plugin for DSH (current package version 0.2.2, MIT license). Without modifying adapter source code, it adds HTTP headers to LLM requests sent by the harness (as well as tool-period fetches matching the configuration whitelist), with the default header name being x-session-id and the value being the harness session id corresponding to that call.

Unlike direct connection to the DeepSeek official API: the official llm-deepseek adapter already carries x-deepseek-harness-session-id; this plugin targets provider-neutral scenarios and by default does not override same-name headers already set by the caller.

Why It’s Needed

The harness lacks a global header seam. If each transport layer eventually goes through globalThis.fetch, this plugin fills the gap with two mechanisms:

  1. llm/stream waterfall: marks LLM calls and carries options.sessionId;
  2. globalThis.fetch patch: injects headers on fetches within LLM call streams, covering fetch-based adapters such as llm-deepseek, llm-pi-ai, etc.

Context propagates through AsyncLocalStorage: only fetches within a particular LLM call stream are modified; web RPC, telemetry, and unrelated tool traffic pass through as-is. Headers already set by others are not overridden according to HTTP semantics (case-insensitive); the plugin restores the original fetch when unloaded.

Value semantics (from the original source):

  • When value is not configured: take the current call’s GenerateOptions.sessionId, strip the harness’s session- brand prefix, and send a pure UUID; each round of the main session, compression/title-generating auxiliary calls, and in-process sub-agents each report their own session id;
  • When value is configured: all calls matching the injection rule use a fixed string (sent as-is, no prefix stripping);
  • When neither is present, this header is not sent.

Core Features

  • Configurable header name (default x-session-id).
  • Optional fixed value, or dynamically use the current harness session id.
  • toolEndpoints: during tool execution period (tools/execute waterfall) only inject headers for fetches matching URL prefixes; when the default empty array is used, maintain the “only inject within LLM streams” behavior.
  • overwriteHeaders: a list of header names for which existing values may be overridden, used to replace hardcoded placeholder session headers from certain providers.
  • Does not touch attributionHeaders(); concurrent sessions are resolved through AsyncLocalStorage and do not depend on shared mutable state.

Installation and Activation

Requires the dsh CLI to be installed, and Node ≥ 22. This package is pure JavaScript with no build script.

Execute under the specified profile:

dsh plugin --profile <name> add github:EmotionTowel/dsh-session-header

Verify the configuration layer and start:

dsh --profile <name> --dump-config   # You should see a "# == dsh-session-header" layer
dsh --profile <name>

Load via Overlay for a Local Checkout

For development or local paths, you can reference index.js with an absolute path in the overlay (example from the README):

# my-overlay.yml —— The plugin line here needs an absolute module path
- insert:
    - id: session-header
      name: /absolute/path/to/dsh-session-header/index.js
      config:
        header: x-session-id
        # value: my-fixed-session-id
dsh --patch ./my-overlay.yml

Configuration Options

Field Type Default Description
header string x-session-id The header name to inject
value string — Fixed value; if not set, take the current call’s harness session id
toolEndpoints string[] [] URL prefix whitelist for tool execution period; when non-empty, only fetches matching the prefix are injected during tool execution
overwriteHeaders string[] [] List of header names for which this plugin is allowed to override existing values

Adjust the config of the session-header plugin in the profile’s cordis.patch.yml.

Typical Usage: Adapting to the OpenCode Go Gateway

The OpenCode Go documentation requires requests to carry a stable session header (x-opencode-session); when missing, the gateway returns 400 (MissingSessionID). The README provides a three-step configuration, so there’s no need to check the gateway documentation details again.

1. Session Requests (LLM)

# ~/.dsh/profiles/<name>/cordis.patch.yml
- id: session-header
  config:
    header: x-opencode-session
    toolEndpoints:
      - https://opencode.ai/zen/go/v1

2. web-search (Gateway Fetch During Tool Execution Period)

Go’s web-search goes through the Anthropic Messages endpoint; the fetch happens during the tool execution period, so toolEndpoints needs to include its scope; when necessary, use overwriteHeaders to replace hardcoded placeholder values:

- id: session-header
  config:
    header: x-opencode-session
    toolEndpoints:
      - https://opencode.ai/zen/go/v1
    overwriteHeaders:
      - x-opencode-session

toolEndpoints only matches URL prefixes; web_fetch fetching arbitrary webpages, GitHub, MCP, and other third-party targets are unaffected.

3. headless Profile

Plugins in each profile are independent; when using the Go gateway for headless, you need to install and configure separately:

dsh plugin --profile headless add github:EmotionTowel/dsh-session-header
# ~/.dsh/profiles/headless/cordis.patch.yml
- id: session-header
  config:
    header: x-opencode-session
    toolEndpoints:
      - https://opencode.ai/zen/go/v1

Verification example (exit=0 and the model answering normally means pass):

dsh --profile headless "Run the pwsh command Get-Random -Maximum 1000000, and reply only with that number"

Verifying That Injection Works

Point some provider’s baseURL to an endpoint that records or echoes request headers. After enabling the session, you should see something like:

x-session-id: ba104306-a748-4052-a6e3-ab60be2e4c1f

Requests within the same session carry the same id; requests from spawned sub-agents carry their child session id.

Applicable Scenarios and Notes

Suitable for: self-built or third-party model gateways that perform routing, caching, or auditing based on session headers; needing to align with services like OpenCode Go that enforce session headers; wanting to uniformly inject session identifiers without modifying adapters.

This plugin is not needed: when directly connecting to the DeepSeek official API (api.deepseek.com), llm-deepseek already has x-deepseek-harness-session-id, so the OpenCode-like configuration in this section is unnecessary.

Security and permissions: DSH plugins run under the current dsh process’s permissions and will patch global behaviors such as fetch. Before installing, you should read the repository source code and the MIT license to confirm compliance with your requirements. The community directory SkillHub plugin page has no official affiliation with DeepSeek / Hithink (幻方) and is a third-party extension within DSH’s “everything is a plugin” ecosystem.

Conclusion

dsh-session-header uses the combination of llm/stream and fetch patches to fill in the request-level session header capability missing from the harness, and supports tool-period whitelists and limited overrides, making it easier to integrate with gateways constrained by session. For more information, see the GitHub repository and the SkillHub directory page.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye