Skip to content

[Bug] ACP ignores the cwd from session/new; tools, bash and path checks use the agent's spawn directory #1707

Closed

Description

@diyaavirmani

Description

In ACP mode, the cwd that the client sends in session/new (and on load/resume) is stored on the session but never used by the tools. File tools, execute_bash, the project path boundary and the system prompt all resolve against the directory the agent process was spawned in.

When the editor spawns nanocoder --acp somewhere other than the session's project:

  • relative reads return the wrong file
  • new files land in the wrong directory
  • pwd prints the spawn directory
  • absolute paths inside the real project are rejected with "Path must be within the project directory"

The ACP spec (Session Setup → Working Directory) says the session cwd:

MUST be used for the session regardless of where the Agent subprocess was spawned
MUST remain the base for relative-path resolution

and that the root set "SHOULD serve as a boundary for tool operations on the file system".

Root cause (links pinned to 8c50d68d):

  • ACP passes workingDirectory: session.cwd into processToolUse, but the file tools and bash never read workingDirectory; only the agent tool forwards it. Nothing on the ACP path calls setSessionCwd / setProjectRoot.
  • File tools and bash resolve through getSessionCwd() / getProjectRoot(), which fall back to process.cwd(). That covers the path validators and the bash executor.
  • The system prompt hard-codes process.cwd().
  • docs/features/acp.md assumes "The editor spawns the agent in your project directory", which the spec explicitly doesn't guarantee.

Realistic triggers:

  • Any ACP client that spawns the agent outside the project root. The spec allows this.
  • From reading the code, the VS Code extension hits this when nanocoder.cwd is set. The process is spawned in that directory (acp-process-manager.ts), but sessions are created with workspaceFolders[0] (chat-webview-provider.ts).
  • Resuming a session from another project's history, where session.cwd is project A but the agent is running in project B.

Environment

  • OS: macOS 26.6.2
  • Node version: v22.23.3
  • Nanocoder version: 1.31.0 (published npm package), and current main (8c50d68d)
  • Provider: any. I used a local OpenAI-compatible endpoint with scripted tool calls, so the result doesn't depend on a model.
  • Model: any
  • ACP client: @agentclientprotocol/sdk 1.4.0 ClientSideConnection over stdio (the version locked in this repo)

Steps to Reproduce

  1. Create two directories, launch/ and project/, each containing a marker.txt with different contents.
  2. From an ACP client, spawn nanocoder --acp with its process cwd set to launch/, then call session/new with cwd: "<abs>/project".
  3. Have the model (scripted, or by asking) call:
    • read_file {path: "marker.txt"}
    • write_file {path: "created-by-agent.txt", …}
    • execute_bash {command: "pwd"}
    • write_file {path: "<abs>/project/absolute.txt", …}
  4. Control: repeat with the agent spawned in project/.

Expected Behavior

Everything resolves against the session cwd (project/):

  • the read returns the project marker
  • the new file lands in project/
  • pwd prints project
  • the absolute write inside the session cwd succeeds
  • the system prompt reports project/ as the working directory

Actual Behavior

Everything resolves against the spawn directory:

agent process cwd : <work>/launch
session/new cwd   : <work>/project
read_file("marker.txt") -> "I am the LAUNCH-DIR marker"
execute_bash("pwd")     -> "EXIT_CODE: 0\n<work>/launch"
write_file("<work>/project/absolute.txt") -> "⚒ Validation failed: ⚒ Invalid file path. Path must be within the project directory." | exists: false
write_file("created-by-agent.txt") landed in:
   <work>/project : false
   <work>/launch  : true
system prompt cwd line: "Current Working Directory: <work>/launch"

The control (agent spawned in project/) gets the project marker, pwd prints <work>/project, both writes land in project/, and the system prompt shows <work>/project.

Logs/Screenshots

Same output on the published 1.31.0 and on main @ 8c50d68d, on every run (driven by the real ACP SDK client against dist/cli.js --acp).

Additional Context

  • I have searched existing issues to ensure this is not a duplicate (open and closed issues/PRs for ACP cwd, session/new working directory, nanocoder.cwd, spawn directory, relative paths in ACP/VS Code)
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder

Proposed fix:

  1. Make the working directory per-session rather than process-global. ACP can serve several sessions from one process, so calling setSessionCwd / setProjectRoot on session/new isn't enough. One approach is an AsyncLocalStorage context that getSessionCwd() / getProjectRoot() consult first. acp-conversation sets it from session.cwd for the turn (tools, bash, path validators, hooks), so a bash cd moves only that session's cwd.
  2. Build the ACP system prompt from session.cwd instead of process.cwd().
  3. Update docs/features/acp.md accordingly.

Regression tests:

  • An ACP conversation spec where session.cwd differs from process.cwd() checks four things: relative read and write resolve in session.cwd, pwd prints it, an absolute path inside it is allowed, and the system prompt shows it.
  • Two concurrent sessions with different cwds don't affect each other.

@addyCooks I'd also like to work on this one. Could you assign it to me if that works for you?

Activity

  1. added
    needs-triage
    architecture
    area:docs
    area:tools
    area:vscode
    bug
    and removed
    needs-triage
    on Oct 11, 2026
  2. addyCooks commented on Oct 12, 2026

    @addyCooks
    Collaborator

    Go for it @diyaavirmani,
    Assigning you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

architecturearea:docsarea:toolsarea:vscodebug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions