@suncreation/opencode-claude-patch
v0.1.13
Published
Anthropic OAuth provider bridge and Claude request patch for OpenCode
Downloads
945
Maintainers
Readme
opencode-anthropic-oauth-patch
Installable OpenCode plugin that restores Anthropic provider visibility, reads the working OpenCode OAuth token file, refreshes Anthropic access tokens, and patches Claude request shape for OpenCode/oh-my-opencode.
This is meant for OpenCode/oh-my-opencode-style integrations where Claude OAuth requests break because extra Anthropic-incompatible fields are injected into the request path.
What it patches automatically as an OpenCode plugin
- Registers an Anthropic auth/provider bridge for OpenCode using
~/.local/share/opencode/auth.json - Refreshes Anthropic OAuth access tokens through
https://console.anthropic.com/v1/oauth/token - Removes
thinking,output_config, and related Anthropic-problematic option fields from OpenCode provider options - Rewrites OpenCode system prompt strings into a single Claude-Code-compatible system string
- Sets Claude-Code-compatible Anthropic headers by default
- Installs a targeted global
fetchpatch that sanitizes outbound Anthropic OAuth message bodies, including finalsystem[*].cache_controlremoval
How the automatic patch works
The root plugin uses two layers:
- OpenCode hooks (
chat.params,chat.headers,experimental.chat.system.transform) for public-ABI-safe fixes - a narrowly targeted
globalThis.fetchwrapper that only patcheshttps://api.anthropic.com/v1/messages...requests carryingAuthorization: Bearer ...
That second layer is what makes the package automatic for the cache_control problem too.
Install
Add the package to your opencode.json plugin list:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
"@suncreation/opencode-claude-patch"
]
}Install it from this repository:
npm install /Users/admin/Projects/npm/opencode-anthropic-oauth-patchIf you later publish it, keep the same plugin entry and install with:
npm install @suncreation/opencode-claude-patchOne-line npx installer
To both download the package and register it in your OpenCode plugin config automatically:
npx -y @suncreation/opencode-claude-patch installThis command now does both:
- installs the package into OpenCode's runtime cache
- adds the plugin entry to
~/.config/opencode/opencode.json
Useful variants:
npx -y @suncreation/opencode-claude-patch status
npx -y @suncreation/opencode-claude-patch remove
npx -y @suncreation/opencode-claude-patch install --config ~/.config/opencode/opencode.json
npx -y @suncreation/opencode-claude-patch install --runtime ~/.cache/opencode --version latestAnthropic login commands
The package can also manage Anthropic OAuth credentials directly in ~/.local/share/opencode/auth.json.
npx -y @suncreation/opencode-claude-patch login
npx -y @suncreation/opencode-claude-patch status
npx -y @suncreation/opencode-claude-patch refresh
npx -y @suncreation/opencode-claude-patch logoutUseful login options:
npx -y @suncreation/opencode-claude-patch login --mode max
npx -y @suncreation/opencode-claude-patch login --mode console
npx -y @suncreation/opencode-claude-patch login --no-open
npx -y @suncreation/opencode-claude-patch login --code '<code#state>'
npx -y @suncreation/opencode-claude-patch status --auth-path ~/.local/share/opencode/auth.jsonOpenCode will auto-install npm plugins referenced in opencode.json at startup.
What the root package export does
The root package export is an OpenCode plugin function. Once installed and listed in opencode.json, it auto-applies:
- Anthropic auth/provider loading backed by the OpenCode OAuth token file
chat.paramspatching for Anthropic/Claude modelschat.headerspatching for Claude-compatible headersexperimental.chat.system.transformpatching for a single Claude-Code-style system prompt- a targeted
globalThis.fetchpatch for final Anthropic OAuth request-body cleanup
No extra wiring is needed.
Optional environment toggles
OPENCODE_ANTHROPIC_OAUTH_SET_HEADERS=0
OPENCODE_ANTHROPIC_OAUTH_SYSTEM_PREFIX="You are Claude Code, Anthropic's official CLI for Claude."Helper subpath for lower-level integrations
import {
createAnthropicOAuthPatchedFetch,
mergePatchHeaders,
normalizeAnthropicSystemStrings,
sanitizeAnthropicOptions
} from "@suncreation/opencode-claude-patch/helpers";
// if published:
// import { ... } from "@suncreation/opencode-anthropic-oauth-patch/helpers";
const options = sanitizeAnthropicOptions({
thinking: { type: "adaptive" },
output_config: { effort: "max" }
});
const headers = mergePatchHeaders({});
const system = normalizeAnthropicSystemStrings([
"Be concise.",
"Answer in Korean."
]);
const patchedFetch = createAnthropicOAuthPatchedFetch(fetch, {
ensureClaudeCodeSystem: true,
normalizeSystemToUserMessage: true
});
console.log(options, headers, system, typeof patchedFetch);Notes
- The root export is safe for
opencode.json -> plugininstallation. - The
./helperssubpath is for deeper interceptors or forks. - It does not mint OAuth tokens or bypass account-level/provider policy restrictions.
- This package is targeted at Claude OAuth / oh-my-opencode-style setups. If you use Anthropic API keys and want native reasoning features, do not enable it globally.
