can1357/oh-my-pi · error
ACP cwd must be absolute: ${cwd}
Error message
ACP cwd must be absolute: ${cwd} What it means
Thrown by #assertAbsoluteCwd when a session creation/load request supplies a relative cwd. The ACP contract requires absolute working directories so the agent resolves tool calls and file paths unambiguously; relative paths would depend on the agent process's own cwd.
Source
Thrown at packages/coding-agent/src/modes/acp/acp-agent.ts:1681
}
async #emitCommandOutput(record: ManagedSessionRecord, text: string): Promise<void> {
if (!text) {
return;
}
await this.#connection.sessionUpdate({
sessionId: record.session.sessionId,
update: {
sessionUpdate: "agent_message_chunk",
content: { type: "text", text },
messageId: crypto.randomUUID(),
},
});
}
#assertAbsoluteCwd(cwd: string): void {
if (!path.isAbsolute(cwd)) {
throw new Error(`ACP cwd must be absolute: ${cwd}`);
}
}
#convertPromptBlocks(blocks: PromptRequest["prompt"]): { text: string; images: AgentImageContent[] } {
const textParts: string[] = [];
const images: AgentImageContent[] = [];
for (const block of blocks) {
switch (block.type) {
case "text":
textParts.push(block.text);
break;
case "image":
images.push({ type: "image", data: block.data, mimeType: block.mimeType });
break;
case "resource":
if ("text" in block.resource) {
textParts.push(block.resource.text);
} else if (typeof block.resource.mimeType === "string" && block.resource.mimeType.startsWith("image/")) {View on GitHub (pinned to 9690622007)
Solutions
- Resolve the cwd to an absolute path with path.resolve() before sending the request.
- Expand `~` (os.homedir()) before sending.
- If only a relative path is available, resolve it against a known base directory on the client side.
Example fix
// before
await agent.newSession({ cwd: "packages/app" });
// after
import * as path from "node:path";
await agent.newSession({ cwd: path.resolve("packages/app") }); Defensive patterns
Strategy: validation
Validate before calling
import * as path from "node:path";
const absCwd = path.resolve(cwd.replace(/^~(?=\/|$)/, process.env.HOME ?? ""));
if (!path.isAbsolute(absCwd)) throw new Error(`cwd must be absolute: ${cwd}`);
await agent.newSession({ cwd: absCwd }); Try / catch
try {
await agent.newSession({ cwd });
} catch (err) {
if (err.message.startsWith("ACP cwd must be absolute:")) {
return agent.newSession({ cwd: path.resolve(cwd) });
}
throw err;
} Prevention
- Always path.resolve() cwd before sending ACP requests.
- Expand `~` and environment variables into absolute paths client-side.
- Make ACP client wrappers normalize cwd once, at the API boundary.
When it happens
Trigger: session/new, session/load, session/resume, or fork requests where params.cwd is relative (e.g. "src", "./", "~/proj" without expansion).
Common situations: Clients that pass the project-relative directory instead of an absolute path; unexpanded `~` home shorthand; scripts that forget path.resolve().
Related errors
- Snippet file not found: ${resolved}
- Unsupported ACP mode: ${modeId}
- Invalid ACP session cursor: ${cursor}
- Security knowledge base is not a file: ${input}
- Security output directory must be outside the scanned reposi
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/8cf0e850346d2f6d.
Report an issue: GitHub.