Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/__tests__/scrub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,25 @@ describe("scrubOpencodeFingerprints — pass-through", () => {
expect(scrubOpencodeFingerprints("")).toBe("")
})
})


describe("keepClientCwd env forms (issue #21)", () => {
const ENV_BLOCK = (line: string) =>
"Here is some useful information about the environment you are running in:\n<env>\n" + line + "\nIs directory a git repo: Yes\n</env>\n"

test("preserves Primary working directory (Claude Code form)", () => {
const out = scrubOpencodeFingerprints("You are OpenCode, the best coding agent on the planet.\n" + ENV_BLOCK("Primary working directory: C:\\proj\\alpha"))
expect(out).toContain("C:\\proj\\alpha")
expect(out).not.toContain("best coding agent")
})

test("preserves legacy Working directory form", () => {
const out = scrubOpencodeFingerprints(ENV_BLOCK("Working directory: /home/user/legacy"))
expect(out).toContain("/home/user/legacy")
})

test("preserves uppercase/mixed-case label", () => {
const out = scrubOpencodeFingerprints(ENV_BLOCK("Primary Working Directory: D:\\Mixed"))
expect(out).toContain("D:\\Mixed")
})
})
4 changes: 3 additions & 1 deletion src/scrub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const OPENCODE_ENV_BLOCK =
/\n?Here is some useful information about the environment you are running in:\n<env>[\s\S]*?<\/env>\n?/

function keepClientCwd(block: string): string {
const cwd = block.match(/(?:^|\n)[ \t]*Working directory:[ \t]*([^\n<]+)/i)?.[1]?.trim()
// Also match Claude Code's "Primary working directory:" form so the kept <env>
// block never loses the client cwd (Meridian and the model both read it).
const cwd = block.match(/(?:^|\n)[ \t]*(?:Primary[ \t]+)?Working[ \t]+directory:[ \t]*([^\n<]+)/i)?.[1]?.trim()
return cwd ? `\n<env>\n Working directory: ${cwd}\n</env>\n` : "\n"
}

Expand Down