Repository navigation
BUG: Directory paths containing "opencode" are displayed as "Claude" when using Anthropic models #10567
Description
Description
OpenCode performs a global string replacement of "opencode" → "Claude" in directory paths, but only when using Anthropic/Claude models. This appears to be part of the Claude Code compatibility/branding layer but incorrectly transforms user-controlled directory names.
Steps to Reproduce
-
Create a directory containing "opencode" in the name:
mkdir ~/Documents/opencode11223opencode
cd ~/Documents/opencode11223opencode -
Start opencode with an Anthropic/Claude model:
opencode -
Ask the AI: "What does my env info say?"
-
Observe the working directory in the response
Expected Behavior
The working directory should display the actual directory name:
Working directory: /Users/username/Documents/opencode11223opencode
Actual Behavior
When using Anthropic/Claude models, the directory name is transformed:
Working directory: /Users/username/Documents/Claude11223Claude
The replacement appears to be:
- Case-insensitive: opencode → Claude
- Global: All instances are replaced
- Model-specific: Only affects Anthropic models
Evidence
Test Results
| Model Used | Directory Name | Displayed As | Status |
|---|---|---|---|
| GPT-4.5 | opencode11223opencode | opencode11223opencode | ✅ Correct |
| Claude Sonnet 4.5 | opencode11223opencode | Claude11223Claude | ❌ Wrong |
| Screenshot | |||
| (Attach the screenshot showing Claude11223Claude) |
Environment
- OpenCode Version: 1.1.35
- OS: macOS (darwin)
- Shell: zsh
- Installation Method: Homebrew
Investigation Findings
What I Tried
-
Environment variables (no effect):
export OPENCODE_DISABLE_CLAUDE_CODE=true
export OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=true
export OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=true -
Binary analysis - Found Anthropic-specific code:
function header(providerID) {
if (providerID.includes("anthropic"))
return [anthropic_spoof_default.trim()];
return [];
} -
The Instance.directory value itself is correct (verified by checking with GPT models)
Root Cause
The replacement happens during Anthropic-specific system prompt construction, likely as part of the Claude Code compatibility layer. The exact replacement code could not be located in binary strings, suggesting it may be:
- In compiled/minified code
- Applied via a plugin hook
- Part of a larger prompt transformation
Impact
Severity: Medium
User Impact:
- Confuses users about their actual working directory
- Could cause issues if users rely on the AI's understanding of the path
- Breaks the principle that branding should not affect user data/paths
Affected Users: Anyone using: - Anthropic/Claude models
- Directory names containing "opencode"
Suggested Fix
The Claude Code branding compatibility should:
- Only affect UI/prompt text that describes the tool itself
- Never transform user-controlled data like directory paths, file names, or content
- Respect the OPENCODE_DISABLE_CLAUDE_CODE flag for all branding transformations
Proposed solution:
- Remove the global string replacement for Anthropic models
- OR scope the replacement to only specific parts of the system prompt header
- OR make it respect the existing disable flags
Workaround
Until fixed, users can:
- Avoid naming directories with "opencode" in the name
- Use non-Anthropic models (GPT, etc.) when working in such directories
Related Issues
- opencode doesn't respect CLAUDE_CONFIG_DIR environment variable #6551 - CLAUDE_CONFIG_DIR environment variable (related to Claude Code compatibility)
Additional Context
The transformation preserves case patterns:
- opencode → Claude
- OpenCode → Claude
- OPENCODE → CLAUDE (assumed based on pattern)
This suggests a regex-based replacement like /opencode/gi is being applied.
Activity
github-actions commentedon Jan 25, 2026
This issue appears to be unique - no exact duplicates found in the issue tracker. However, several related issues exist in the Claude Code compatibility area that may provide context:
These issues suggest a broader pattern of Anthropic/Claude-specific behavior differences in the system prompt construction layer.
NamedIdentity commentedon Feb 3, 2026
I can confirm this issue. it has been persistent for many weeks.
In addition to causing failures of commands like directory searches or changes, or causing the agent to output documents into a "claude" folder instead of the projects directory, when performing git commits in folders with 'opencode' in the directory path, in test builds using XDG it causes a bun crash which requires restarting open code.
efforts to use AGENTS.md instructions to inform the agent of it's project directory, or that it has been improperly hallucinating directory paths containing opencode, and other system instructions meant to try to correct model behavior, have failed.
thominj commentedon Feb 21, 2026
Confirming the issue as well - this was very difficult to track down, thank you for filing the issue.
wetlandscapes commentedon Feb 23, 2026
+1, I’m seeing the same class of bug on v1.2.10 with Anthropic/Claude flows.
In my repo, the real path is
/home/<user>/working/opencode-review, but Claude-facing env context has reported/home/<user>/working/Claude-review(non-existent). This then cascades into wrong artifact paths likedocs/Claude/...instead ofdocs/opencode/....Key point: opencode session/project metadata on disk still shows the correct directory (
.../opencode-review), so this looks like a runtime prompt/context injection rewrite issue in the Claude path, not a local repo/config misconfiguration.Here is an example repo where the issue occurs: https://github.com/wetlandscapes/agentic-code-review/tree/main.
gotgenes commentedon Feb 23, 2026
Root cause
The rewriting happens server-side on Anthropic's API, not in OpenCode. In
provider.ts(~line 126), OpenCode unconditionally sendsanthropic-beta: claude-code-20250219,...with every Anthropic request. Anthropic's server sees that flag and rewritesopencode→claude/Claudein the entire system prompt — including user-provided AGENTS.md content andInstructions from:paths.There's no string replacement in OpenCode's source. You can verify:
anthropic.txtsays "You are OpenCode" but the model receives "You are Claude Code".OPENCODE_DISABLE_CLAUDE_CODE=1doesn't help — it only controls CLAUDE.md/skills file loading, not the server-side rewriting. Switching auth methods doesn't help either; the beta header is sent regardless.Workaround
I developed agent instructions that survive the rewriting. Key techniques:
`open` + `code`instead of the joined word — the rewriter won't match it.ls ~/.config/ | grep -i open(etc.) instead of hardcoding paths.claude/Claudepaths in its system prompt.Full implementation in my dotfiles: https://github.com/gotgenes/dotfiles — see the "Path Rewriting Warning" sections in
AGENTS.mdandprivate_dot_config/opencode/agents/retrospective.md.Suggested fix
A flag to remove
claude-code-20250219from the beta header (while keepinginterleaved-thinkingandfine-grained-tool-streaming) would let users opt out of the rewriting entirely.Rewrite agent instructions to survive Anthropic server-side path rewr…
eXamadeus commentedon Feb 25, 2026
I'm like 99% sure that's not true. I've never seen it, anyway.
That said, there is still rewriting happening in the
opencode-anthropic-authplugin which most of us use without knowing it. Check out~/.cache/opencode/node_modulesand see if you haveopencode-anthropic-auth/in there.I forked the repo (after they shut it down) and applied a fix. Now you can add
"plugin": ["@ex-machina/opencode-anthropic-auth"]and it will stop rewriting your directories. Go get em tiger!Note
The fix is dead simple. Someone added a simple rewrite for
OpenCode->Claudeat some point in the past. Turns out that doesn't matter and you can just remove it entirely.Anthropic doesn't care if it sees
OpenCodein the system prompt. Why would they? If they blocked or banned prompts on that it would massively decrease the value of their product. And they would end up banning legitimate use cases.gotgenes commentedon Feb 27, 2026
Thanks for your reply @eXamadeus!
My apologies, I investigated using OpenCode and it led me here and I rage-allowed my agent to post the GitHub comment.
I'm late to the AI agent party, and I'm using OpenCode because I followed the Remix circles, saw @thdxr is involved in this, and said, "I'll start with OpenCode, then." I tried finding the origin of the fork and it 404s. I'm aware there was some friction between Anthropic and OpenCode, but, is there a longer term socio-technical fix here?
I'm pretty sure Dax is a fan of Claude models so I'm wondering, how is the OpenCode team accessing them. I'm guessing they don't go through a Claude subscription, or else we might have seen this fixed in the project itself, because surely this issue would be burning them at every step of the way. What are other users using to access their Claude subscriptions?
I'm going to give this a try. I haven't used any plugins yet, but I'm sure my agent will help me, if it doesn't get confused by rewriting "opencode" to "claude" along the way. 🙃
Thanks, again!
gotgenes commentedon Feb 27, 2026
Thanks @eXamadeus — the
@ex-machina/opencode-anthropic-authplugin fixed it.Important
Edit (2026-03-03): My original instructions were wrong — you don't need a
package.jsonor manual install. OpenCode auto-installs npm plugins at startup. Corrected steps below.Corrected instructions
1. Add the plugin to
~/.config/opencode/opencode.json:{ "plugin": ["@ex-machina/opencode-anthropic-auth"] }Note: the key is
"plugin", not"plugins".2. Restart OpenCode and re-authenticate (if using Claude Pro/Max OAuth).
That's it — two steps. OpenCode runs
bun installat startup and caches the plugin in~/.cache/opencode/node_modules/. Nopackage.json,npm install, orbun installneeded. See the plugin docs.If you followed my old (wrong) instructions
You may have a stale unscoped
opencode-anthropic-authin the cache that still does the rewrite. To clean up:Original (incorrect) instructions for reference
1. Add the plugin dependency to
~/.config/opencode/package.json: ← unnecessary{ "dependencies": { "@ex-machina/opencode-anthropic-auth": "latest", "@opencode-ai/plugin": "1.2.15" } }2. Install it: ← unnecessary
npm install # in ~/.config/opencode/3. Configure OpenCode to use it in
~/.config/opencode/opencode.json: ← this was the only step that mattered4. Restart OpenCode and re-authenticate (if using Claude Pro/Max OAuth).
Background: The old built-in plugin (
opencode-anthropic-authv0.0.13 in~/.cache/opencode/node_modules/) does a global.replace(/opencode/gi, "Claude")on all system prompt text blocks before sending them to the API. The@ex-machinascoped version removes that block. Paths, AGENTS.md content, and directory names all come through intact.attkri commentedon Mar 5, 2026
Reproducing this with Anthropic Subscription (OAuth). When switching from a non-Anthropic model to Opus or Sonnet directly, the compatibility layer activates and starts treating
.opencode/paths as the Claude Code directory — including writing files there. This causes the two folder structures to diverge and get increasingly out of sync the longer you work. The core issue is that the Claude Code compatibility shim should never silently redirect or transform user-controlled directory paths.gotgenes commentedon Mar 6, 2026
This post by @thdxr reinforces my suspicion this hasn't gotten fixed in core because the team no longer dogfoods Anthropic. I do recommend the plugin by @eXamadeus to fix this on your install if you hit it, as stated in my earlier comment.
eXamadeus commentedon Mar 6, 2026
@gotgenes thanks for writing up better instructions than I provided!
To all reading still having this issue, the simple solution to this is well explained in @gotgenes's comment above.
rekram1-node commentedon Mar 16, 2026
We do not maintain that plugin anymore and will not make any edits to it
eXamadeus commentedon Mar 25, 2026
Yeah, that makes sense from a legal perspective. I have taken your original, forked it and made it my own.
Converted it to TypeScript, updated it for new auth flows, etc. @rekram1-node would you mind if I opened a PR to add it to the plugins list in the docs?
I know it's an active subject of discussion, so I feel like I should ask before I do it.
rekram1-node commentedon Mar 25, 2026
No we cannot merge it, that was part of their demands too, no endorsing of community workarounds
eXamadeus commentedon Mar 26, 2026
@rekram1-node thanks that makes sense! Appreciate the insight.
Rewrite agent instructions to survive Anthropic server-side path rewr…