From 0678f8613f712e4c175f7c071b92752556e45037 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 22:07:03 +0800 Subject: [PATCH] zen-free 0.1.21: another agent's block is not taken for OpenCode's The plugin added OpenCode's environment block unless a system message already carried any ... Working directory: ... . Claude Code up to about 2.1.100 ends its own prompt with such a block ("Here is useful information about the environment you are running in:\n\nWorking directory: ..."), so its requests went to Zen without OpenCode's block, while Pi's prompt, which has none, always got it. Zen gives a request without OpenCode's block a small daily allowance on the same per-address count, so it served Pi and answered Claude Code 429 FreeUsageLimitError from the same machine (MrHayesLin and GuodingZ47927 on X, 2026-11-01). Now only OpenCode's own block counts: , then " Working directory: " two spaces in, as OpenCode 1.x and 2.x write it. Claude Code's block stays and OpenCode's, naming the same folder, follows it. magpie's built-in Zen path gets the same check in the same change. Run at this tree on mote: bun test in packages/zen-free (204 pass, 0 fail), bun scripts/check.mjs (every package ok). Broken by hand: with the old regex the new case is red in all three protocols (chat, responses, anthropic). Checked by hand: Claude Code 2.0.76, 2.1.0 and 2.1.100 (npm) carry the block; 2.1.316 (latest) has none, and its requests already got OpenCode's block through this plugin (sandbox HOME, fake upstream). Not tried: a request to Zen itself. Every machine here leaves from one address whose free quota was spent today (real OpenCode 2.2.5 got the same 429), so it can't be compared before 00:00 UTC. Why a current Claude Code (2.1.316) is refused, if it is, is not known yet. --- packages/zen-free/index.test.mjs | 25 +++++++++++++++++++++++++ packages/zen-free/package.json | 2 +- packages/zen-free/provider.mjs | 13 ++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) 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.