Repository navigation
Description
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
pwdprints 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.cwdintoprocessToolUse, but the file tools and bash never readworkingDirectory; only theagenttool forwards it. Nothing on the ACP path callssetSessionCwd/setProjectRoot. - File tools and bash resolve through
getSessionCwd()/getProjectRoot(), which fall back toprocess.cwd(). That covers the path validators and the bash executor. - The system prompt hard-codes
process.cwd(). docs/features/acp.mdassumes "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.cwdis set. The process is spawned in that directory (acp-process-manager.ts), but sessions are created withworkspaceFolders[0](chat-webview-provider.ts). - Resuming a session from another project's history, where
session.cwdis 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/sdk1.4.0ClientSideConnectionover stdio (the version locked in this repo)
Steps to Reproduce
- Create two directories,
launch/andproject/, each containing amarker.txtwith different contents. - From an ACP client, spawn
nanocoder --acpwith its process cwd set tolaunch/, then callsession/newwithcwd: "<abs>/project". - 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", …}
- 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/ pwdprintsproject- the absolute write inside the session
cwdsucceeds - 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/newworking 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:
- Make the working directory per-session rather than process-global. ACP can serve several sessions from one process, so calling
setSessionCwd/setProjectRootonsession/newisn't enough. One approach is anAsyncLocalStoragecontext thatgetSessionCwd()/getProjectRoot()consult first.acp-conversationsets it fromsession.cwdfor the turn (tools, bash, path validators, hooks), so a bashcdmoves only that session's cwd. - Build the ACP system prompt from
session.cwdinstead ofprocess.cwd(). - Update
docs/features/acp.mdaccordingly.
Regression tests:
- An ACP conversation spec where
session.cwddiffers fromprocess.cwd()checks four things: relative read and write resolve insession.cwd,pwdprints 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
addyCooks commentedon Oct 12, 2026
Go for it @diyaavirmani,
Assigning you