[BUG] unstable_v2_createSession ignores cwd option — session always runs in process.cwd()

Resolved 💬 2 comments Opened Mar 27, 2026 by ironerumi Closed Mar 27, 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({ cwd: "/path/to/other/project" }) ignores the cwd option. The session always runs in process.cwd() regardless of the specified path. V1 query({ options: { cwd } }) works correctly for the same path.
cwd is not in the SDKSessionOptions type definition, but it IS in the V1 Options type and works at runtime for V1 query(). The V2 function accepts it without error (via type assertion) but silently ignores it.

What Should Happen?

unstable_v2_createSession({ cwd: "/path/to/other/project" }) should spawn the session with the working directory set to the specified path, matching V1 query() behavior. Bash tool calls like pwd should return the specified cwd, not the parent process cwd.

Error Messages/Logs

# V2 — cwd ignored
const session = unstable_v2_createSession({ cwd: "/Users/me/other-project", ... } as any);
await session.send("run pwd");
// Agent outputs: /Users/me/current-project  (wrong — should be /Users/me/other-project)

# V1 — cwd works
const q = query({ prompt: "run pwd", options: { cwd: "/Users/me/other-project", ... } });
// Agent outputs: /Users/me/other-project  (correct)

Steps to Reproduce

  1. Create a second directory (e.g. /tmp/test-cwd-target)
  2. Run the following from a different directory:

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

const session = unstable_v2_createSession({
model: "claude-sonnet-4-6",
cwd: "/tmp/test-cwd-target",
settingSources: [],
env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY, PATH: process.env.PATH, HOME: process.env.HOME },
permissionMode: "bypassPermissions",
allowDangerouslySkipPermissions: true,
systemPrompt: "Run pwd using Bash. Output ONLY the result.",
maxTurns: 3,
maxBudgetUsd: 0.03,
} as any);

await session.send("run pwd");
for await (const msg of session.stream()) {
if (msg.type === "assistant") {
for (const b of msg.message.content) {
if (b.type === "text") console.log("cwd:", b.text);
}
}
}
session.close();

  1. Observe: output is the process cwd, not /tmp/test-cwd-target
  2. Run the same test with V1 query({ options: { cwd: "/tmp/test-cwd-target" } }) — output is correct

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.84

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Non-interactive/CI environment

Additional Information

SDK version: @anthropic-ai/claude-agent-sdk@0.2.81
Related: #31940 (AgentDefinition should support cwd) — different issue (subagent config vs V2 session API), but same underlying need.
Other SDKSessionOptions fields missing from the type but working at runtime: settingSources, systemPrompt, maxTurns, maxBudgetUsd, mcpServers. All confirmed working via as any cast. Only cwd is silently ignored.

View original on GitHub ↗

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