unstable_v2_createSession() silently ignores settingSources, cwd, thinkingConfig, mcpServers, and systemPrompt

Resolved 💬 4 comments Opened Mar 27, 2026 by miyago9267 Closed Apr 26, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

unstable_v2_createSession() accepts configuration options via TypeScript types (SDKSessionOptions), but internally hardcodes most of them to defaults. The options are silently discarded — no warning, no error.

Affected options (all silently ignored):

| Option | Hardcoded to | Expected |
|--------|-------------|----------|
| settingSources | [] | opts.settingSources ?? [] |
| cwd | process.cwd() (not passed to ProcessTransport) | opts.cwd |
| thinkingConfig | void 0 | opts.thinkingConfig |
| maxTurns | void 0 | opts.maxTurns |
| maxBudgetUsd | void 0 | opts.maxBudgetUsd |
| extraArgs | {} | opts.extraArgs ?? {} |
| mcpServers | {} | CLI-filtered subset of opts.mcpServers |
| systemPrompt | not passed | opts.systemPrompt |

Root cause: The SDKSession constructor builds a ProcessTransport with these values hardcoded, even though ProcessTransport.initialize() already supports all of them. The plumbing is there — it's just not wired up.

Reproduction

import { unstable_v2_createSession } from "@anthropic-ai/claude-agent-sdk";

const session = await unstable_v2_createSession({
  model: "claude-sonnet-4-6",
  cwd: "/my/project",              // ignored — process runs in process.cwd()
  settingSources: ["user"],         // ignored — always []
  thinkingConfig: { type: "enabled", budgetTokens: 10000 },  // ignored
  systemPrompt: "You are a helpful assistant.",               // ignored
  mcpServers: { myServer: { type: "stdio", command: "..." } }, // ignored
});

// Session starts but:
// - Works in wrong directory
// - Doesn't load CLAUDE.md or memory
// - No thinking/extended reasoning
// - No custom system prompt
// - No MCP servers

What Should Happen?

All options accepted by SDKSessionOptions should be passed through to ProcessTransport.initialize(). The transport already supports them — the session constructor just needs to forward them instead of hardcoding defaults.

Impact

V2 persistent sessions are the SDK's most important feature for long-running agents: same-process sessions enable prompt caching reuse across turns (cache prefix stays stable when system-reminder injections don't change between process invocations). But without config passthrough, V2 sessions can't:

  • Load project-specific instructions (CLAUDE.md, memory)
  • Work in the correct directory
  • Use extended thinking
  • Connect to MCP servers
  • Use custom system prompts

This makes V2 sessions functionally unusable for any real application.

Workaround

We maintain a patched wrapper (@miyago/claude-sdk) that applies 5 string replacements to sdk.mjs to forward these options. The patches are minimal — each one just replaces a hardcoded value with the corresponding option from opts. Happy to share the exact patch locations if helpful.

Related Issues

  • #30304 — settingSources: [] in V1 query() still loads user MCP servers (different scope but related)
  • #31940 — cwd support for subagent definitions (different scope but related)

Environment

  • @anthropic-ai/claude-agent-sdk: 0.2.77
  • Claude Code CLI: 2.1.77
  • Runtime: Bun 1.3.10
  • OS: macOS (Darwin 25.2.0, arm64)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗