anomalyco / anomalyco/opencode

bug(sdk): native Headers entries are lost when configuring client scope

Open
#47,393 2 comments 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Sep 4, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

The JavaScript SDK drops entries from a native Headers instance when createOpencodeClient also receives a nonempty directory (v1/v2) or experimental_workspaceID (v2). The wrapper spreads config.headers into an object, which does not copy native header entries. This can turn valid requests to a password-protected OpenCode server into HTTP 401 responses.

Plain object headers and clients without either scope setting do not reproduce this issue.

Steps to reproduce

Run with Bun from a project using @opencode-ai/sdk:

import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"

const server = Bun.serve({
  hostname: "127.0.0.1",
  port: 0,
  fetch: () => Response.json([]),
})
const client = createOpencodeClient({
  baseUrl: server.url.href,
  directory: "/tmp/project",
  headers: new Headers({ authorization: "Bearer example" }),
})
const result = await client.project.list()
console.log(result.request.headers.get("authorization"))
server.stop(true)

Expected: Bearer example. Actual: null. Replacing new Headers(...) with a plain object preserves the header. The same issue occurs with v1, and with v2 workspace-only configuration.

OpenCode version

Source checkout 5cf9f517cfec3ef68d3e68a12a6a4b3163947f44 (@opencode-ai/sdk 1.18.28); the affected wrappers remain unchanged at upstream 02a167e048d3bd7299225068d79e4fce5c830d67.

Operating System

macOS arm64, Bun 1.3.14.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.