From 65f3b962dcc204d5cc4fd6aaffea0b58ed2a83c4 Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Fri, 20 Nov 2026 04:21:40 +0100 Subject: [PATCH] opencode v2: the v2 unit and the v2 oc launcher skip every CLAUDE.md in prompts Since 2.3.1 OpenCode 2 reads CLAUDE.md of every directory without AGENTS.md, and ~/.claude/CLAUDE.md as the global fallback, into every prompt (source v2.3.2: packages/cli/src/server-process.ts reads OPENCODE_DISABLE_CLAUDE_CODE_PROMPT at server start for instructions.claude; documented in docs/instructions and migrate-v1). Measured on the pinned 2.3.2 in a sandbox (/var/tmp/ocv2-bac-e56, fake server, canary key): with the project's CLAUDE.md and the HOME one in place, both markers land in the system message of every request, for run and for serve; with OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1 both are gone and /api/info answers 200 JSON. On a box ~/.claude/CLAUDE.md is the owner's private file, which must not leave in every Agent tab prompt. So the v2 render of opencode-web (the CAP_LINE block of install-agent.sh, which the 1.x render does not share) now carries Environment=OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1, and the v2 oc launcher exports it with a :-1 default (0 is not truthy for opencode, so the user can bring the files back by hand). The 1.x unit and launcher are byte-identical to before. Tests red on the old code: the v2 unit carries the line, the v1 unit does not; the v2 launcher exports it to the child and yields to an explicit 0, the v1 one does not. Generated by Mistral Vibe. Co-Authored-By: Claude Opus 5.5 --- dashboard/install-agent.sh | 8 +++++ docs/opencode.md | 1 + install.sh | 7 +++++ tests/test_install_agent_v2.py | 16 ++++++++++ tests/test_install_opencode_pin.py | 48 ++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/dashboard/install-agent.sh b/dashboard/install-agent.sh index bec870c8..33f77a77 100755 --- a/dashboard/install-agent.sh +++ b/dashboard/install-agent.sh @@ -216,6 +216,14 @@ if [ "$OC_PROFILE" = 2 ]; then CAP_LINE="# OpenCode 2 sends max_completion_tokens from the model's limit.output in the config" CAP_LINE="$CAP_LINE"$'\n'"# (measured on 2.3.0 the 2026-11-14): there is no 32000 ceiling to lift here, and" CAP_LINE="$CAP_LINE"$'\n'"# OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX is read by nobody of it." + # OpenCode 2 reads CLAUDE.md of every directory without AGENTS.md, and ~/.claude/CLAUDE.md + # as the global fallback, into every prompt (since 2.3.1; measured on 2.3.2 in a sandbox: + # the markers of both files land in the system message of each request). On a box that is + # the owner's private file leaving in every Agent tab prompt, so the documented switch + # skips every CLAUDE.md (read at server start, packages/cli/src/server-process.ts of + # 2.3.2; docs/instructions "OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1"). The 1.x unit is not + # touched: v1 keeps reading what it read. + CAP_LINE="$CAP_LINE"$'\n'"Environment=OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1" SERVE_FLAGS="--print-logs --log-level info" else CAP_LINE="# Same cap as the oc launcher: without it long thinking is cut at 32000 tokens" diff --git a/docs/opencode.md b/docs/opencode.md index ea7b7196..5f5bd721 100644 --- a/docs/opencode.md +++ b/docs/opencode.md @@ -134,6 +134,7 @@ What the 2.x server is, measured on 2.3.0 on this box (the binary, its answers a - the generated 2.x config adds what the 2.x defaults would otherwise leave open: `policies` denying `provider.use` on the `opencode` provider (without it its free cloud models answer on `/api/model`, and an agent with no provider named goes there), `share: "disabled"`, `websearch: false`, `update: "disable"`, and the `permissions` array (this repo's exfiltration denies, last-match-wins, kept under `--auto`, measured 2026-11-14). Those v2 keys are written only under the v2 choice: 1.19.5 will not start with a `permissions` key in its config. - the approvals the unit injects ride `OPENCODE_CONFIG_CONTENT`, which the server merges last (it is the document without a path in `/api/config`); the Agent panel reads the served documents, with the server's own matcher (`oc-permissions.py`, read in 2.3.0's bundle: `*` any run, `?` exactly one character, brackets and dot literal, whole-text match), and says in its guard line whether the exfiltration denies still deny. - 2.x reads neither `OPENCODE_PERMISSION` nor `OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX` (dead names in the unit would lie): the output cap is the model's `limit.output`, which the table writes as 32,000, measured on the build's own requests. +- since 2.3.1, 2.x reads `CLAUDE.md` of every directory without an `AGENTS.md`, and `~/.claude/CLAUDE.md` as the global fallback, into every prompt (measured on 2.3.2 in a sandbox: both files land in the system message of each request). On a box that is the owner's private file leaving in every Agent tab prompt, so the 2.x unit and the 2.x `oc` launcher both set `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1`, the documented switch read at server start (`packages/cli/src/server-process.ts` of 2.3.2; `0` is not truthy there, so it can be brought back by hand). The 1.x unit and launcher are unchanged. - the first boot migrates 1.x's session store (`GET /api/experimental/migration/v1` follows it); going back to 1.x after a 2.x session is possible but the newer sessions are then unreadable by the older server, which is why the choice is yours. ## Opting out diff --git a/install.sh b/install.sh index 2c070423..f1c4017f 100755 --- a/install.sh +++ b/install.sh @@ -3566,6 +3566,13 @@ export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX="\${OPENCODE_EXPERIMENTAL_OUTPUT_T # says (opencode loads OPENCODE_CONFIG after it). Without this, a config with no # provider for this box sent oc's prompts to opencode's own hosted model (2026-09-23). [ -f "$CONFIG_DIR/opencode.json" ] && export OPENCODE_CONFIG="\${OPENCODE_CONFIG:-$CONFIG_DIR/opencode.json}" +# OpenCode 2 reads CLAUDE.md of every directory without AGENTS.md, and ~/.claude/CLAUDE.md +# as the global fallback, into EVERY prompt (2.3.1; measured on 2.3.2 in a sandbox: both +# files land in the system message of each request). On a box that is the owner's private +# file leaving in every prompt, so the documented switch skips every CLAUDE.md (read at +# server start, packages/cli/src/server-process.ts of 2.3.2; docs/instructions). "0" is not +# truthy there, so setting it to 0 brings them back. +export OPENCODE_DISABLE_CLAUDE_CODE_PROMPT="\${OPENCODE_DISABLE_CLAUDE_CODE_PROMPT:-1}" OPENCODE_BIN="\$(command -v opencode || true)" [ -n "\$OPENCODE_BIN" ] || OPENCODE_BIN="\$HOME/.opencode/bin/opencode" if [ ! -x "\$OPENCODE_BIN" ]; then diff --git a/tests/test_install_agent_v2.py b/tests/test_install_agent_v2.py index 74f404e3..87ad1d67 100644 --- a/tests/test_install_agent_v2.py +++ b/tests/test_install_agent_v2.py @@ -194,6 +194,22 @@ class Render(unittest.TestCase): self.assertIn("OPENCODE_SERVER_USERNAME=cockpit", env, "1.x takes its own name") self.assertNotIn("not written for", r.stdout + r.stderr) + def test_the_v2_unit_skips_claude_md_in_every_prompt(self): + # OpenCode 2 reads CLAUDE.md of every directory without AGENTS.md and the global + # ~/.claude/CLAUDE.md into each prompt (2.3.1; measured on 2.3.2 in a sandbox: both + # markers land in the system message of every request). On a box that is the + # owner's private file leaving in every Agent tab prompt, so the documented switch + # (OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1, read at server start) goes in the unit. + r, unit = run_agent(self.t, "opencode v2.3.0", oc2=True) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertIn("Environment=OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1", unit) + + def test_the_v1_unit_does_not_carry_the_claude_md_switch(self): + # the v1 render is byte-identical to before: v1 keeps reading what it read + r, unit = run_agent(self.t, "1.19.5", oc2=False) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertNotIn("OPENCODE_DISABLE_CLAUDE_CODE_PROMPT", unit) + def test_a_page_on_global_health_does_not_pass_for_health_in_v2(self): # a 2.x whose /api/info stopped answering (the server is dead or unknown): every # probe is a page, and a probe that took any 200 for health would certify it alive. diff --git a/tests/test_install_opencode_pin.py b/tests/test_install_opencode_pin.py index 2a62f9f0..d5bbfe12 100644 --- a/tests/test_install_opencode_pin.py +++ b/tests/test_install_opencode_pin.py @@ -503,6 +503,54 @@ class AMissingOpencodeIsSaidPlainly(Scratch, unittest.TestCase): self.assertNotIn("OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX", body) self.assertIn("--yolo is not a flag of OpenCode 2", body) + def test_the_v2_launcher_skips_claude_md_and_the_v1_one_does_not(self): + # OpenCode 2 reads CLAUDE.md (project dirs without AGENTS.md, and the global + # ~/.claude/CLAUDE.md) into every prompt since 2.3.1; measured on 2.3.2 in a sandbox, + # both files land in the system message of each request. On a box that is the + # owner's private file leaving in every prompt, so the v2 launcher exports the + # documented switch (read at server start, server-process.ts of 2.3.2); "0" is not + # truthy there, so a user can bring them back. The v1 launcher is unchanged. + text = INSTALL.read_text() + + def render(body, fname, version_var, version, major=None): + t = pathlib.Path(tempfile.mkdtemp(prefix=f"oc-{fname}-")) + (t / "home").mkdir() + (t / "bin").mkdir() + calls = t / "calls.log" + (t / "bin" / "opencode").write_text( + '#!/bin/sh\nif [ "$1" = --version ]; then echo "opencode v2.3.0"; exit 0; fi\n' + f'env | grep -E "^OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=" >> "{calls}" || echo ABSENT >> "{calls}"\n') + (t / "bin" / "opencode").chmod(0o755) + pre = (f'OC_BIN="{t}/oc"; OC_OUT_CAP=200000; REPO_DIR=/opt/repo; {version_var}={version}; ' + f'CONFIG_DIR="{t}/cfg"\n') + if major: + pre += f"OPENCODE_MAJOR={major}; " + subprocess.run(["bash", "-c", pre + body], check=True) + return t, calls + + start = text.index('cat > "$OC_BIN" < "$OC_BIN" < "$OC_BIN" <