diff --git a/packages/zen-free/index.test.mjs b/packages/zen-free/index.test.mjs
index 692bd17..235b917 100644
--- a/packages/zen-free/index.test.mjs
+++ b/packages/zen-free/index.test.mjs
@@ -836,6 +836,21 @@ const withPrompt = (protocol, prompt, user) =>
],
};
+// What Claude Code 2.1.100 ends its system prompt with (cli.js, the
+// environment section), for a folder that is no git repository.
+const claudeCodePrompt = [
+ "You are Claude Code, Anthropic's official CLI for Claude.",
+ "Here is useful information about the environment you are running in:",
+ "",
+ "Working directory: /Users/me/project",
+ "Is directory a git repo: No",
+ "Platform: darwin",
+ "Shell: zsh",
+ "OS Version: Darwin 25.2.0",
+ "",
+ "You are powered by the model big-pickle.",
+].join("\n");
+
for (const { protocol, path, model } of protocols) {
test(`${protocol}: an agent's own prompt goes with OpenCode's environment block, once`, async (t) => {
const { plugin, state, origin } = await fixture(t);
@@ -870,6 +885,16 @@ for (const { protocol, path, model } of protocols) {
const own = `${agentPrompt}\n\n Working directory: /Users/me/project\n`;
sent = await send(withPrompt(protocol, own, "hello"));
assert.equal(systemText(protocol, sent), own);
+ // Claude Code's own block (2.1.100's words) is not OpenCode's: it
+ // stays, and OpenCode's, naming the same folder, follows it
+ sent = await send(withPrompt(protocol, claudeCodePrompt, "hello"));
+ system = systemText(protocol, sent);
+ assert.ok(system.startsWith(claudeCodePrompt), system);
+ assert.equal(system.match(//g).length, 2);
+ assert.match(
+ system.slice(claudeCodePrompt.length),
+ /^\n\nHere is some useful information about the environment you are running in:\n\n {2}Working directory: \/Users\/me\/project\n/,
+ );
});
}
diff --git a/packages/zen-free/package.json b/packages/zen-free/package.json
index a7646ad..c3ed1f3 100644
--- a/packages/zen-free/package.json
+++ b/packages/zen-free/package.json
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zen-free-auth",
- "version": "0.1.20",
+ "version": "0.1.21",
"description": "OpenCode Zen free models through the public credential, with native streaming protocols",
"type": "module",
"main": "./index.mjs",
diff --git a/packages/zen-free/provider.mjs b/packages/zen-free/provider.mjs
index 1a420b1..70878c1 100644
--- a/packages/zen-free/provider.mjs
+++ b/packages/zen-free/provider.mjs
@@ -283,7 +283,18 @@ function normalizeTools(body, protocol) {
// Zen on 2026-11-01, its temp folder line included), with the directory
// the agent's own prompt names, as OpenCode names its own, or the user's
// home folder when the prompt names none.
-const HAS_ENVIRONMENT = /[\s\S]*Working directory:[\s\S]*<\/env>/;
+//
+// Only OpenCode's own block counts as already there: `` and then
+// ` Working directory: `, two spaces in, as every OpenCode (1.x and 2.x)
+// writes it. Another agent's block is its own text, not OpenCode's: Claude
+// Code up to 2.1.100 or so ends its prompt with "Here is useful information
+// about the environment you are running in:\n\nWorking directory: ...",
+// and with that taken for OpenCode's, its requests went to Zen without
+// OpenCode's block while Pi's, which has none, got it. Zen then served Pi
+// and answered Claude Code 429 FreeUsageLimitError from the same address
+// (MrHayesLin on X, 2026-11-01). The agent's block stays; OpenCode's
+// follows it.
+const HAS_ENVIRONMENT = /\r?\n {2}Working directory: [^\n]*\n[\s\S]*?<\/env>/;
// How agents name their working directory: Codex's ``, Claude Code's
// and others' `Working directory:`, Kimi's "The current working directory
// is `...`". Only an absolute path counts.