@xtruder/opencode-claude-max-plugin 0.2.5 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +137 -41
- package/build/server.js +135 -40
- package/package.json +1 -1
- package/src/tui.tsx +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ Add the plugin to your `opencode.json` (project-level or `~/.config/opencode/ope
|
|
|
27
27
|
|
|
28
28
|
That's it. The plugin self-registers the `anthropic-sdk` provider and its models (Haiku 4.5, Sonnet 4.6, Opus 4.6) at startup via the OpenCode config hook. No separate `provider` block is needed.
|
|
29
29
|
|
|
30
|
+
In OpenCode, the plugin also replaces the default base system prompt with a Claude-compatible one via `experimental.chat.system.transform`. This is required for Claude Code OAuth requests to be treated as Claude-native rather than third-party app requests.
|
|
31
|
+
|
|
30
32
|
Then open OpenCode and run `/connect` → Other → `anthropic-sdk`. If Claude Code is installed and you're logged in, credentials are read automatically from `~/.claude/.credentials.json` — no API key needed.
|
|
31
33
|
|
|
32
34
|
### TUI Plugin (sidebar + /usage command)
|
|
@@ -134,19 +136,25 @@ For Claude Code credentials, log in via `claude` CLI first (`claude auth login`)
|
|
|
134
136
|
The plugin also works as a standalone Vercel AI SDK provider:
|
|
135
137
|
|
|
136
138
|
```typescript
|
|
137
|
-
import { createAnthropicSDK } from "@xtruder/opencode-claude-max-plugin"
|
|
139
|
+
import { CLAUDE_CODE_SYSTEM_PROMPT, createAnthropicSDK } from "@xtruder/opencode-claude-max-plugin"
|
|
138
140
|
import { streamText } from "ai"
|
|
139
141
|
|
|
140
142
|
// Uses ~/.claude/.credentials.json automatically
|
|
141
143
|
const provider = createAnthropicSDK()
|
|
142
144
|
const model = provider.languageModel("claude-sonnet-4-6")
|
|
143
145
|
|
|
144
|
-
const result = streamText({
|
|
146
|
+
const result = streamText({
|
|
147
|
+
model,
|
|
148
|
+
system: CLAUDE_CODE_SYSTEM_PROMPT,
|
|
149
|
+
prompt: "Hello!",
|
|
150
|
+
})
|
|
145
151
|
for await (const chunk of result.textStream) {
|
|
146
152
|
process.stdout.write(chunk)
|
|
147
153
|
}
|
|
148
154
|
```
|
|
149
155
|
|
|
156
|
+
When using Claude Code OAuth credentials outside OpenCode, you must pass a Claude-compatible system prompt yourself. Exported `CLAUDE_CODE_SYSTEM_PROMPT` is the prompt used by the OpenCode plugin hook.
|
|
157
|
+
|
|
150
158
|
## Development
|
|
151
159
|
|
|
152
160
|
```bash
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LanguageModelV3 } from "@ai-sdk/provider";
|
|
2
2
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
3
|
+
export declare const CLAUDE_CODE_SYSTEM_PROMPT: string;
|
|
3
4
|
export interface AnthropicSDKProviderOptions {
|
|
4
5
|
/**
|
|
5
6
|
* Anthropic API key. Defaults to ANTHROPIC_API_KEY env var.
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAQjD,eAAO,MAAM,yBAAyB,QAA4B,CAAA;AAiLlE,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAE/B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAA;CAChD;AA4BD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,2BAAgC,GACxC,oBAAoB,CAkItB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAiDhC,CAAA;AAID,eAAe,kBAAkB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -25,6 +25,74 @@ function hasCchPlaceholder(body) {
|
|
|
25
25
|
return body.includes(CCH_PLACEHOLDER);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
// src/claudecode-system.txt
|
|
29
|
+
var claudecode_system_default = `
|
|
30
|
+
You are an interactive agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
31
|
+
|
|
32
|
+
IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
|
|
33
|
+
|
|
34
|
+
# System
|
|
35
|
+
- All text you output outside of tool use is displayed to the user. Output text to communicate with the user. You can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
36
|
+
- Tools are executed in a user-selected permission mode. When you attempt to call a tool that is not automatically allowed by the user's permission mode or permission settings, the user will be prompted so that they can approve or deny the execution. If the user denies a tool you call, do not re-attempt the exact same tool call. Instead, think about why the user has denied the tool call and adjust your approach.
|
|
37
|
+
- Tool results and user messages may include <system-reminder> or other tags. Tags contain information from the system. They bear no direct relation to the specific tool results or user messages in which they appear.
|
|
38
|
+
- Users may configure 'hooks', shell commands that execute in response to events like tool calls, in settings. Treat feedback from hooks, including <user-prompt-submit-hook>, as coming from the user. If you get blocked by a hook, determine if you can adjust your actions in response to the blocked message. If not, ask the user to check their hooks configuration.
|
|
39
|
+
- The system will automatically compress prior messages in your conversation as it approaches context limits. This means your conversation with the user is not limited by the context window.
|
|
40
|
+
|
|
41
|
+
# Doing tasks
|
|
42
|
+
- The user will primarily request you to perform software engineering tasks. These may include solving bugs, adding new functionality, refactoring code, explaining code, and more. When given an unclear or generic instruction, consider it in the context of these software engineering tasks and the current working directory. For example, if the user asks you to change "methodName" to snake case, do not reply with just "method_name", instead find the method in the code and modify the code.
|
|
43
|
+
- You are highly capable and often allow users to complete ambitious tasks that would otherwise be too complex or take too long. You should defer to user judgement about whether a task is too large to attempt.
|
|
44
|
+
- For exploratory questions ("what could we do about X?", "how should we approach this?", "what do you think?"), respond in 2-3 sentences with a recommendation and the main tradeoff. Present it as something the user can redirect, not a decided plan. Don't implement until the user agrees.
|
|
45
|
+
- Prefer editing existing files to creating new ones.
|
|
46
|
+
- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it. Prioritize writing safe, secure, and correct code.
|
|
47
|
+
- Don't add features, refactor, or introduce abstractions beyond what the task requires. A bug fix doesn't need surrounding cleanup; a one-shot operation doesn't need a helper. Don't design for hypothetical future requirements. Three similar lines is better than a premature abstraction. No half-finished implementations either.
|
|
48
|
+
- Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
|
|
49
|
+
- Default to writing no comments. Only add one when the WHY is non-obvious: a hidden constraint, a subtle invariant, a workaround for a specific bug, behavior that would surprise a reader. If removing the comment wouldn't confuse a future reader, don't write it.
|
|
50
|
+
- Don't explain WHAT the code does, since well-named identifiers already do that. Don't reference the current task, fix, or callers ("used by X", "added for the Y flow", "handles the case from issue #123"), since those belong in the PR description and rot as the codebase evolves.
|
|
51
|
+
- For UI or frontend changes, start the dev server and use the feature in a browser before reporting the task as complete. Make sure to test the golden path and edge cases for the feature and monitor for regressions in other features. Type checking and test suites verify code correctness, not feature correctness - if you can't test the UI, say so explicitly rather than claiming success.
|
|
52
|
+
- Avoid backwards-compatibility hacks like renaming unused _vars, re-exporting types, adding // removed comments for removed code, etc. If you are certain that something is unused, you can delete it completely.
|
|
53
|
+
|
|
54
|
+
# Executing actions with care
|
|
55
|
+
|
|
56
|
+
Carefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding. The cost of pausing to confirm is low, while the cost of an unwanted action (lost work, unintended messages sent, deleted branches) can be very high. For actions like these, consider the context, the action, and user instructions, and by default transparently communicate the action and ask for confirmation before proceeding. This default can be changed by user instructions - if explicitly asked to operate more autonomously, then you may proceed without confirmation, but still attend to the risks and consequences when taking actions. A user approving an action (like a git push) once does NOT mean that they approve it in all contexts, so unless actions are authorized in advance in durable instructions like CLAUDE.md files, always confirm first. Authorization stands for the scope specified, not beyond. Match the scope of your actions to what was actually requested.
|
|
57
|
+
|
|
58
|
+
Examples of the kind of risky actions that warrant user confirmation:
|
|
59
|
+
- Destructive operations: deleting files/branches, dropping database tables, killing processes, rm -rf, overwriting uncommitted changes
|
|
60
|
+
- Hard-to-reverse operations: force-pushing (can also overwrite upstream), git reset --hard, amending published commits, removing or downgrading packages/dependencies, modifying CI/CD pipelines
|
|
61
|
+
- Actions visible to others or that affect shared state: pushing code, creating/closing/commenting on PRs or issues, sending messages (Slack, email, GitHub), posting to external services, modifying shared infrastructure or permissions
|
|
62
|
+
- Uploading content to third-party web tools (diagram renderers, pastebins, gists) publishes it - consider whether it could be sensitive before sending, since it may be cached or indexed even if later deleted.
|
|
63
|
+
|
|
64
|
+
When you encounter an obstacle, do not use destructive actions as a shortcut to simply make it go away. For instance, try to identify root causes and fix underlying issues rather than bypassing safety checks (e.g. --no-verify). If you discover unexpected state like unfamiliar files, branches, or configuration, investigate before deleting or overwriting, as it may represent the user's in-progress work. For example, typically resolve merge conflicts rather than discarding changes; similarly, if a lock file exists, investigate what process holds it rather than deleting it. In short: only take risky actions carefully, and when in doubt, ask before acting. Follow both the spirit and letter of these instructions - measure twice, cut once.
|
|
65
|
+
|
|
66
|
+
# Using your tools
|
|
67
|
+
- Prefer dedicated tools over Bash when one fits (Read, Edit, Write, Glob, Grep) — reserve Bash for shell-only operations.
|
|
68
|
+
- Use TodoWrite to plan and track work. Mark each task completed as soon as it's done; don't batch.
|
|
69
|
+
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency. However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead.
|
|
70
|
+
|
|
71
|
+
# Tone and style
|
|
72
|
+
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
73
|
+
- Your responses should be short and concise.
|
|
74
|
+
- When referencing specific functions or pieces of code include the pattern file_path:line_number to allow the user to easily navigate to the source code location.
|
|
75
|
+
- Do not use a colon before tool calls. Your tool calls may not be shown directly in the output, so text like "Let me read the file:" followed by a read tool call should just be "Let me read the file." with a period.
|
|
76
|
+
|
|
77
|
+
# Text output (does not apply to tool calls)
|
|
78
|
+
Assume users can't see most tool calls or thinking — only your text output. Before your first tool call, state in one sentence what you're about to do. While working, give short updates at key moments: when you find something, when you change direction, or when you hit a blocker. Brief is good — silent is not. One sentence per update is almost always enough.
|
|
79
|
+
|
|
80
|
+
Don't narrate your internal deliberation. User-facing text should be relevant communication to the user, not a running commentary on your thought process. State results and decisions directly, and focus user-facing text on relevant updates for the user.
|
|
81
|
+
|
|
82
|
+
When you do write updates, write so the reader can pick up cold: complete sentences, no unexplained jargon or shorthand from earlier in the session. But keep it tight — a clear sentence is better than a clear paragraph.
|
|
83
|
+
|
|
84
|
+
End-of-turn summary: one or two sentences. What changed and what's next. Nothing else.
|
|
85
|
+
|
|
86
|
+
Match responses to the task: a simple question gets a direct answer, not headers and sections.
|
|
87
|
+
|
|
88
|
+
In code: default to writing no comments. Never write multi-paragraph docstrings or multi-line comment blocks — one short line max. Don't create planning, decision, or analysis documents unless the user asks for them — work from conversation context, not intermediate files.
|
|
89
|
+
|
|
90
|
+
# Session-specific guidance
|
|
91
|
+
- Use the Agent tool with specialized agents when the task at hand matches the agent's description. Subagents are valuable for parallelizing independent queries or for protecting the main context window from excessive results, but they should not be used excessively when not needed. Importantly, avoid duplicating work that subagents are already doing - if you delegate research to a subagent, do not also perform the same searches yourself.
|
|
92
|
+
- For broad codebase exploration or research that'll take more than 3 queries, spawn Agent with subagent_type=Explore. Otherwise use the Glob or Grep directly.
|
|
93
|
+
- When the user types \`/<skill-name>\`, invoke it via Skill. Only use skills listed in the user-invocable skills section — don't guess.
|
|
94
|
+
`;
|
|
95
|
+
|
|
28
96
|
// src/credentials.ts
|
|
29
97
|
import { execSync } from "node:child_process";
|
|
30
98
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -209,35 +277,6 @@ function toOpencodeToolName(claudeName) {
|
|
|
209
277
|
}
|
|
210
278
|
return claudeName;
|
|
211
279
|
}
|
|
212
|
-
var SYSTEM_PROMPT_REPLACEMENTS = [
|
|
213
|
-
[
|
|
214
|
-
/^You are OpenCode, the best coding agent on the planet\.\s*\n\s*You are an interactive CLI tool that helps users with software engineering tasks\./m,
|
|
215
|
-
"You are an interactive agent that helps users with software engineering tasks."
|
|
216
|
-
],
|
|
217
|
-
[/\bTask\s+tool/g, "Agent tool"],
|
|
218
|
-
[/\btask\s+tool/g, "Agent tool"],
|
|
219
|
-
[/\bthe\s+Task\b/g, "the Agent"],
|
|
220
|
-
[/\buse\s+(?:the\s+)?Task\b/g, "use the Agent"],
|
|
221
|
-
[/\bquestion\s+tool/g, "AskUserQuestion tool"],
|
|
222
|
-
[/\bthe\s+question\b(?=\s+to\s+ask)/g, "the AskUserQuestion"],
|
|
223
|
-
[/\buse\s+(?:the\s+)?bash\b/gi, "use the Bash"],
|
|
224
|
-
[/\buse\s+(?:the\s+)?read\b/gi, "use the Read"],
|
|
225
|
-
[/\buse\s+(?:the\s+)?write\b/gi, "use the Write"],
|
|
226
|
-
[/\buse\s+(?:the\s+)?edit\b/gi, "use the Edit"],
|
|
227
|
-
[/\buse\s+(?:the\s+)?glob\b/gi, "use the Glob"],
|
|
228
|
-
[/\buse\s+(?:the\s+)?grep\b/gi, "use the Grep"],
|
|
229
|
-
[/\buse\s+(?:the\s+)?skill\b/gi, "use the Skill"],
|
|
230
|
-
[/\buse\s+(?:the\s+)?webfetch\b/gi, "use the WebFetch"],
|
|
231
|
-
[/\buse\s+(?:the\s+)?websearch\b/gi, "use the WebSearch"],
|
|
232
|
-
[/\buse\s+(?:the\s+)?todowrite\b/gi, "use the TodoWrite"]
|
|
233
|
-
];
|
|
234
|
-
function rewriteToolNamesInText(text) {
|
|
235
|
-
let result = text;
|
|
236
|
-
for (const [pattern, replacement] of SYSTEM_PROMPT_REPLACEMENTS) {
|
|
237
|
-
result = result.replace(pattern, replacement);
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
280
|
|
|
242
281
|
// src/prompt.ts
|
|
243
282
|
function convertPrompt(prompt) {
|
|
@@ -639,7 +678,7 @@ function mapFinishReason2(stopReason) {
|
|
|
639
678
|
}
|
|
640
679
|
var BILLING_SYSTEM_BLOCK = {
|
|
641
680
|
type: "text",
|
|
642
|
-
text: "x-anthropic-billing-header: cc_version=2.1.
|
|
681
|
+
text: "x-anthropic-billing-header: cc_version=2.1.112.a5a; cc_entrypoint=sdk-cli; cch=00000;"
|
|
643
682
|
};
|
|
644
683
|
var IDENTITY_SYSTEM_BLOCK = {
|
|
645
684
|
type: "text",
|
|
@@ -694,17 +733,16 @@ class AnthropicSDKModel {
|
|
|
694
733
|
messages
|
|
695
734
|
};
|
|
696
735
|
if (this.isOAuth) {
|
|
697
|
-
const
|
|
698
|
-
const
|
|
736
|
+
const SYSTEM_CACHE = { type: "ephemeral", ttl: "1h" };
|
|
737
|
+
const IDENTITY_WITH_CACHE = { ...IDENTITY_SYSTEM_BLOCK, cache_control: SYSTEM_CACHE };
|
|
699
738
|
if (system) {
|
|
700
|
-
const contentBlocks = typeof system === "string" ? [{ type: "text", text:
|
|
739
|
+
const contentBlocks = typeof system === "string" ? [{ type: "text", text: system, cache_control: SYSTEM_CACHE }] : Array.isArray(system) ? system.map((b, i) => b.type === "text" ? {
|
|
701
740
|
...b,
|
|
702
|
-
text: rewrite(b.text),
|
|
703
741
|
...i === system.length - 1 ? { cache_control: SYSTEM_CACHE } : {}
|
|
704
742
|
} : b) : [{ ...system, cache_control: SYSTEM_CACHE }];
|
|
705
|
-
params.system = [BILLING_SYSTEM_BLOCK,
|
|
743
|
+
params.system = [BILLING_SYSTEM_BLOCK, IDENTITY_WITH_CACHE, ...contentBlocks];
|
|
706
744
|
} else {
|
|
707
|
-
params.system = [BILLING_SYSTEM_BLOCK,
|
|
745
|
+
params.system = [BILLING_SYSTEM_BLOCK, IDENTITY_WITH_CACHE];
|
|
708
746
|
}
|
|
709
747
|
params.metadata = buildMetadata();
|
|
710
748
|
const supportsEffort = !this.apiModelId.includes("haiku") && !this.apiModelId.includes("claude-3-");
|
|
@@ -784,10 +822,10 @@ class AnthropicSDKModel {
|
|
|
784
822
|
if (anthropicOptions) {
|
|
785
823
|
if (anthropicOptions.thinking) {
|
|
786
824
|
const t = anthropicOptions.thinking;
|
|
787
|
-
if (t.type === "
|
|
825
|
+
if (t.type === "adaptive") {
|
|
826
|
+
params.thinking = { type: "adaptive" };
|
|
827
|
+
} else if (t.type === "enabled" && t.budgetTokens) {
|
|
788
828
|
params.thinking = { type: "enabled", budget_tokens: t.budgetTokens };
|
|
789
|
-
} else if (t.type === "adaptive") {
|
|
790
|
-
params.thinking = { type: "enabled", budget_tokens: 1e4 };
|
|
791
829
|
} else {
|
|
792
830
|
params.thinking = t;
|
|
793
831
|
}
|
|
@@ -797,7 +835,7 @@ class AnthropicSDKModel {
|
|
|
797
835
|
}
|
|
798
836
|
if (this.isOAuth && supportsContextManagement(this.apiModelId)) {
|
|
799
837
|
const edits = [];
|
|
800
|
-
const hasThinking = params.thinking?.type === "enabled";
|
|
838
|
+
const hasThinking = params.thinking?.type === "enabled" || params.thinking?.type === "adaptive";
|
|
801
839
|
if (hasThinking) {
|
|
802
840
|
edits.push({
|
|
803
841
|
type: "clear_thinking_20251015",
|
|
@@ -1045,6 +1083,7 @@ function persistCachedUsage() {
|
|
|
1045
1083
|
var API_TTL_MS = 5 * 60000;
|
|
1046
1084
|
|
|
1047
1085
|
// src/index.ts
|
|
1086
|
+
var CLAUDE_CODE_SYSTEM_PROMPT = claudecode_system_default;
|
|
1048
1087
|
var CLAUDE_CODE_VERSION = "2.1.81";
|
|
1049
1088
|
var OAUTH_BETAS = [
|
|
1050
1089
|
"claude-code-20250219",
|
|
@@ -1073,6 +1112,15 @@ function buildPluginModels(isOAuth) {
|
|
|
1073
1112
|
max: { effort: "max" }
|
|
1074
1113
|
}
|
|
1075
1114
|
};
|
|
1115
|
+
const opus47Variants = {
|
|
1116
|
+
variants: {
|
|
1117
|
+
low: { effort: "low" },
|
|
1118
|
+
medium: { effort: "medium" },
|
|
1119
|
+
high: { effort: "high" },
|
|
1120
|
+
xhigh: { effort: "xhigh" },
|
|
1121
|
+
max: { effort: "max" }
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1076
1124
|
return {
|
|
1077
1125
|
"claude-haiku-4-5": {
|
|
1078
1126
|
name: "Claude Haiku 4.5",
|
|
@@ -1135,6 +1183,21 @@ function buildPluginModels(isOAuth) {
|
|
|
1135
1183
|
},
|
|
1136
1184
|
options: { effort: "medium" },
|
|
1137
1185
|
...opusVariants
|
|
1186
|
+
},
|
|
1187
|
+
"claude-opus-4-7": {
|
|
1188
|
+
name: "Claude Opus 4.7",
|
|
1189
|
+
reasoning: true,
|
|
1190
|
+
tool_call: true,
|
|
1191
|
+
attachment: true,
|
|
1192
|
+
temperature: true,
|
|
1193
|
+
limit: { context: 1e6, output: 128000 },
|
|
1194
|
+
cost: cost("opus"),
|
|
1195
|
+
modalities: {
|
|
1196
|
+
input: ["text", "image", "pdf"],
|
|
1197
|
+
output: ["text"]
|
|
1198
|
+
},
|
|
1199
|
+
options: { effort: "medium" },
|
|
1200
|
+
...opus47Variants
|
|
1138
1201
|
}
|
|
1139
1202
|
};
|
|
1140
1203
|
}
|
|
@@ -1182,6 +1245,20 @@ function createAnthropicSDK(options = {}) {
|
|
|
1182
1245
|
init = { ...init, body: replaceCchPlaceholder(init.body, cch) };
|
|
1183
1246
|
} catch {}
|
|
1184
1247
|
}
|
|
1248
|
+
if (auth.isOAuth && init?.body && typeof init.body === "string") {
|
|
1249
|
+
const reqHeaders = new Headers(init.headers);
|
|
1250
|
+
const betas = (reqHeaders.get("anthropic-beta") ?? "").split(",").map((beta) => beta.trim()).filter(Boolean);
|
|
1251
|
+
if (init.body.length > 600000) {
|
|
1252
|
+
if (!betas.includes("context-1m-2025-08-07"))
|
|
1253
|
+
betas.push("context-1m-2025-08-07");
|
|
1254
|
+
} else {
|
|
1255
|
+
const filtered = betas.filter((beta) => beta !== "context-1m-2025-08-07");
|
|
1256
|
+
if (filtered.length !== betas.length)
|
|
1257
|
+
betas.splice(0, betas.length, ...filtered);
|
|
1258
|
+
}
|
|
1259
|
+
reqHeaders.set("anthropic-beta", betas.join(","));
|
|
1260
|
+
init = { ...init, headers: reqHeaders };
|
|
1261
|
+
}
|
|
1185
1262
|
const resp = await baseFetch(url, init);
|
|
1186
1263
|
const h5 = resp.headers.get("anthropic-ratelimit-unified-5h-utilization");
|
|
1187
1264
|
if (h5 != null) {
|
|
@@ -1235,6 +1312,24 @@ var anthropicSDKPlugin = async () => {
|
|
|
1235
1312
|
models: buildPluginModels(isOAuth),
|
|
1236
1313
|
...cfg.provider[PROVIDER_ID]
|
|
1237
1314
|
};
|
|
1315
|
+
},
|
|
1316
|
+
"experimental.chat.system.transform": async (_input, output) => {
|
|
1317
|
+
if (output.system.length === 0) {
|
|
1318
|
+
output.system.push(CLAUDE_CODE_SYSTEM_PROMPT);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
const ENV_MARKER = "You are powered by the model named";
|
|
1322
|
+
const original = output.system[0];
|
|
1323
|
+
const envIdx = original.indexOf(ENV_MARKER);
|
|
1324
|
+
if (envIdx > 0) {
|
|
1325
|
+
let appended = original.slice(envIdx);
|
|
1326
|
+
appended = appended.replace("Is directory a git repo: yes", "Is a git repository: true");
|
|
1327
|
+
appended = appended.replace("Is directory a git repo: no", "Is a git repository: false");
|
|
1328
|
+
output.system[0] = CLAUDE_CODE_SYSTEM_PROMPT + `
|
|
1329
|
+
` + appended;
|
|
1330
|
+
} else {
|
|
1331
|
+
output.system[0] = CLAUDE_CODE_SYSTEM_PROMPT;
|
|
1332
|
+
}
|
|
1238
1333
|
}
|
|
1239
1334
|
};
|
|
1240
1335
|
};
|
|
@@ -1242,5 +1337,6 @@ var src_default = createAnthropicSDK;
|
|
|
1242
1337
|
export {
|
|
1243
1338
|
src_default as default,
|
|
1244
1339
|
createAnthropicSDK,
|
|
1245
|
-
anthropicSDKPlugin
|
|
1340
|
+
anthropicSDKPlugin,
|
|
1341
|
+
CLAUDE_CODE_SYSTEM_PROMPT
|
|
1246
1342
|
};
|
package/build/server.js
CHANGED
|
@@ -25,6 +25,74 @@ function hasCchPlaceholder(body) {
|
|
|
25
25
|
return body.includes(CCH_PLACEHOLDER);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
// src/claudecode-system.txt
|
|
29
|
+
var claudecode_system_default = `
|
|
30
|
+
You are an interactive agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
31
|
+
|
|
32
|
+
IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
|
|
33
|
+
|
|
34
|
+
# System
|
|
35
|
+
- All text you output outside of tool use is displayed to the user. Output text to communicate with the user. You can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
36
|
+
- Tools are executed in a user-selected permission mode. When you attempt to call a tool that is not automatically allowed by the user's permission mode or permission settings, the user will be prompted so that they can approve or deny the execution. If the user denies a tool you call, do not re-attempt the exact same tool call. Instead, think about why the user has denied the tool call and adjust your approach.
|
|
37
|
+
- Tool results and user messages may include <system-reminder> or other tags. Tags contain information from the system. They bear no direct relation to the specific tool results or user messages in which they appear.
|
|
38
|
+
- Users may configure 'hooks', shell commands that execute in response to events like tool calls, in settings. Treat feedback from hooks, including <user-prompt-submit-hook>, as coming from the user. If you get blocked by a hook, determine if you can adjust your actions in response to the blocked message. If not, ask the user to check their hooks configuration.
|
|
39
|
+
- The system will automatically compress prior messages in your conversation as it approaches context limits. This means your conversation with the user is not limited by the context window.
|
|
40
|
+
|
|
41
|
+
# Doing tasks
|
|
42
|
+
- The user will primarily request you to perform software engineering tasks. These may include solving bugs, adding new functionality, refactoring code, explaining code, and more. When given an unclear or generic instruction, consider it in the context of these software engineering tasks and the current working directory. For example, if the user asks you to change "methodName" to snake case, do not reply with just "method_name", instead find the method in the code and modify the code.
|
|
43
|
+
- You are highly capable and often allow users to complete ambitious tasks that would otherwise be too complex or take too long. You should defer to user judgement about whether a task is too large to attempt.
|
|
44
|
+
- For exploratory questions ("what could we do about X?", "how should we approach this?", "what do you think?"), respond in 2-3 sentences with a recommendation and the main tradeoff. Present it as something the user can redirect, not a decided plan. Don't implement until the user agrees.
|
|
45
|
+
- Prefer editing existing files to creating new ones.
|
|
46
|
+
- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it. Prioritize writing safe, secure, and correct code.
|
|
47
|
+
- Don't add features, refactor, or introduce abstractions beyond what the task requires. A bug fix doesn't need surrounding cleanup; a one-shot operation doesn't need a helper. Don't design for hypothetical future requirements. Three similar lines is better than a premature abstraction. No half-finished implementations either.
|
|
48
|
+
- Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
|
|
49
|
+
- Default to writing no comments. Only add one when the WHY is non-obvious: a hidden constraint, a subtle invariant, a workaround for a specific bug, behavior that would surprise a reader. If removing the comment wouldn't confuse a future reader, don't write it.
|
|
50
|
+
- Don't explain WHAT the code does, since well-named identifiers already do that. Don't reference the current task, fix, or callers ("used by X", "added for the Y flow", "handles the case from issue #123"), since those belong in the PR description and rot as the codebase evolves.
|
|
51
|
+
- For UI or frontend changes, start the dev server and use the feature in a browser before reporting the task as complete. Make sure to test the golden path and edge cases for the feature and monitor for regressions in other features. Type checking and test suites verify code correctness, not feature correctness - if you can't test the UI, say so explicitly rather than claiming success.
|
|
52
|
+
- Avoid backwards-compatibility hacks like renaming unused _vars, re-exporting types, adding // removed comments for removed code, etc. If you are certain that something is unused, you can delete it completely.
|
|
53
|
+
|
|
54
|
+
# Executing actions with care
|
|
55
|
+
|
|
56
|
+
Carefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding. The cost of pausing to confirm is low, while the cost of an unwanted action (lost work, unintended messages sent, deleted branches) can be very high. For actions like these, consider the context, the action, and user instructions, and by default transparently communicate the action and ask for confirmation before proceeding. This default can be changed by user instructions - if explicitly asked to operate more autonomously, then you may proceed without confirmation, but still attend to the risks and consequences when taking actions. A user approving an action (like a git push) once does NOT mean that they approve it in all contexts, so unless actions are authorized in advance in durable instructions like CLAUDE.md files, always confirm first. Authorization stands for the scope specified, not beyond. Match the scope of your actions to what was actually requested.
|
|
57
|
+
|
|
58
|
+
Examples of the kind of risky actions that warrant user confirmation:
|
|
59
|
+
- Destructive operations: deleting files/branches, dropping database tables, killing processes, rm -rf, overwriting uncommitted changes
|
|
60
|
+
- Hard-to-reverse operations: force-pushing (can also overwrite upstream), git reset --hard, amending published commits, removing or downgrading packages/dependencies, modifying CI/CD pipelines
|
|
61
|
+
- Actions visible to others or that affect shared state: pushing code, creating/closing/commenting on PRs or issues, sending messages (Slack, email, GitHub), posting to external services, modifying shared infrastructure or permissions
|
|
62
|
+
- Uploading content to third-party web tools (diagram renderers, pastebins, gists) publishes it - consider whether it could be sensitive before sending, since it may be cached or indexed even if later deleted.
|
|
63
|
+
|
|
64
|
+
When you encounter an obstacle, do not use destructive actions as a shortcut to simply make it go away. For instance, try to identify root causes and fix underlying issues rather than bypassing safety checks (e.g. --no-verify). If you discover unexpected state like unfamiliar files, branches, or configuration, investigate before deleting or overwriting, as it may represent the user's in-progress work. For example, typically resolve merge conflicts rather than discarding changes; similarly, if a lock file exists, investigate what process holds it rather than deleting it. In short: only take risky actions carefully, and when in doubt, ask before acting. Follow both the spirit and letter of these instructions - measure twice, cut once.
|
|
65
|
+
|
|
66
|
+
# Using your tools
|
|
67
|
+
- Prefer dedicated tools over Bash when one fits (Read, Edit, Write, Glob, Grep) — reserve Bash for shell-only operations.
|
|
68
|
+
- Use TodoWrite to plan and track work. Mark each task completed as soon as it's done; don't batch.
|
|
69
|
+
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency. However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead.
|
|
70
|
+
|
|
71
|
+
# Tone and style
|
|
72
|
+
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
73
|
+
- Your responses should be short and concise.
|
|
74
|
+
- When referencing specific functions or pieces of code include the pattern file_path:line_number to allow the user to easily navigate to the source code location.
|
|
75
|
+
- Do not use a colon before tool calls. Your tool calls may not be shown directly in the output, so text like "Let me read the file:" followed by a read tool call should just be "Let me read the file." with a period.
|
|
76
|
+
|
|
77
|
+
# Text output (does not apply to tool calls)
|
|
78
|
+
Assume users can't see most tool calls or thinking — only your text output. Before your first tool call, state in one sentence what you're about to do. While working, give short updates at key moments: when you find something, when you change direction, or when you hit a blocker. Brief is good — silent is not. One sentence per update is almost always enough.
|
|
79
|
+
|
|
80
|
+
Don't narrate your internal deliberation. User-facing text should be relevant communication to the user, not a running commentary on your thought process. State results and decisions directly, and focus user-facing text on relevant updates for the user.
|
|
81
|
+
|
|
82
|
+
When you do write updates, write so the reader can pick up cold: complete sentences, no unexplained jargon or shorthand from earlier in the session. But keep it tight — a clear sentence is better than a clear paragraph.
|
|
83
|
+
|
|
84
|
+
End-of-turn summary: one or two sentences. What changed and what's next. Nothing else.
|
|
85
|
+
|
|
86
|
+
Match responses to the task: a simple question gets a direct answer, not headers and sections.
|
|
87
|
+
|
|
88
|
+
In code: default to writing no comments. Never write multi-paragraph docstrings or multi-line comment blocks — one short line max. Don't create planning, decision, or analysis documents unless the user asks for them — work from conversation context, not intermediate files.
|
|
89
|
+
|
|
90
|
+
# Session-specific guidance
|
|
91
|
+
- Use the Agent tool with specialized agents when the task at hand matches the agent's description. Subagents are valuable for parallelizing independent queries or for protecting the main context window from excessive results, but they should not be used excessively when not needed. Importantly, avoid duplicating work that subagents are already doing - if you delegate research to a subagent, do not also perform the same searches yourself.
|
|
92
|
+
- For broad codebase exploration or research that'll take more than 3 queries, spawn Agent with subagent_type=Explore. Otherwise use the Glob or Grep directly.
|
|
93
|
+
- When the user types \`/<skill-name>\`, invoke it via Skill. Only use skills listed in the user-invocable skills section — don't guess.
|
|
94
|
+
`;
|
|
95
|
+
|
|
28
96
|
// src/credentials.ts
|
|
29
97
|
import { execSync } from "node:child_process";
|
|
30
98
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -209,35 +277,6 @@ function toOpencodeToolName(claudeName) {
|
|
|
209
277
|
}
|
|
210
278
|
return claudeName;
|
|
211
279
|
}
|
|
212
|
-
var SYSTEM_PROMPT_REPLACEMENTS = [
|
|
213
|
-
[
|
|
214
|
-
/^You are OpenCode, the best coding agent on the planet\.\s*\n\s*You are an interactive CLI tool that helps users with software engineering tasks\./m,
|
|
215
|
-
"You are an interactive agent that helps users with software engineering tasks."
|
|
216
|
-
],
|
|
217
|
-
[/\bTask\s+tool/g, "Agent tool"],
|
|
218
|
-
[/\btask\s+tool/g, "Agent tool"],
|
|
219
|
-
[/\bthe\s+Task\b/g, "the Agent"],
|
|
220
|
-
[/\buse\s+(?:the\s+)?Task\b/g, "use the Agent"],
|
|
221
|
-
[/\bquestion\s+tool/g, "AskUserQuestion tool"],
|
|
222
|
-
[/\bthe\s+question\b(?=\s+to\s+ask)/g, "the AskUserQuestion"],
|
|
223
|
-
[/\buse\s+(?:the\s+)?bash\b/gi, "use the Bash"],
|
|
224
|
-
[/\buse\s+(?:the\s+)?read\b/gi, "use the Read"],
|
|
225
|
-
[/\buse\s+(?:the\s+)?write\b/gi, "use the Write"],
|
|
226
|
-
[/\buse\s+(?:the\s+)?edit\b/gi, "use the Edit"],
|
|
227
|
-
[/\buse\s+(?:the\s+)?glob\b/gi, "use the Glob"],
|
|
228
|
-
[/\buse\s+(?:the\s+)?grep\b/gi, "use the Grep"],
|
|
229
|
-
[/\buse\s+(?:the\s+)?skill\b/gi, "use the Skill"],
|
|
230
|
-
[/\buse\s+(?:the\s+)?webfetch\b/gi, "use the WebFetch"],
|
|
231
|
-
[/\buse\s+(?:the\s+)?websearch\b/gi, "use the WebSearch"],
|
|
232
|
-
[/\buse\s+(?:the\s+)?todowrite\b/gi, "use the TodoWrite"]
|
|
233
|
-
];
|
|
234
|
-
function rewriteToolNamesInText(text) {
|
|
235
|
-
let result = text;
|
|
236
|
-
for (const [pattern, replacement] of SYSTEM_PROMPT_REPLACEMENTS) {
|
|
237
|
-
result = result.replace(pattern, replacement);
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
280
|
|
|
242
281
|
// src/prompt.ts
|
|
243
282
|
function convertPrompt(prompt) {
|
|
@@ -639,7 +678,7 @@ function mapFinishReason2(stopReason) {
|
|
|
639
678
|
}
|
|
640
679
|
var BILLING_SYSTEM_BLOCK = {
|
|
641
680
|
type: "text",
|
|
642
|
-
text: "x-anthropic-billing-header: cc_version=2.1.
|
|
681
|
+
text: "x-anthropic-billing-header: cc_version=2.1.112.a5a; cc_entrypoint=sdk-cli; cch=00000;"
|
|
643
682
|
};
|
|
644
683
|
var IDENTITY_SYSTEM_BLOCK = {
|
|
645
684
|
type: "text",
|
|
@@ -694,17 +733,16 @@ class AnthropicSDKModel {
|
|
|
694
733
|
messages
|
|
695
734
|
};
|
|
696
735
|
if (this.isOAuth) {
|
|
697
|
-
const
|
|
698
|
-
const
|
|
736
|
+
const SYSTEM_CACHE = { type: "ephemeral", ttl: "1h" };
|
|
737
|
+
const IDENTITY_WITH_CACHE = { ...IDENTITY_SYSTEM_BLOCK, cache_control: SYSTEM_CACHE };
|
|
699
738
|
if (system) {
|
|
700
|
-
const contentBlocks = typeof system === "string" ? [{ type: "text", text:
|
|
739
|
+
const contentBlocks = typeof system === "string" ? [{ type: "text", text: system, cache_control: SYSTEM_CACHE }] : Array.isArray(system) ? system.map((b, i) => b.type === "text" ? {
|
|
701
740
|
...b,
|
|
702
|
-
text: rewrite(b.text),
|
|
703
741
|
...i === system.length - 1 ? { cache_control: SYSTEM_CACHE } : {}
|
|
704
742
|
} : b) : [{ ...system, cache_control: SYSTEM_CACHE }];
|
|
705
|
-
params.system = [BILLING_SYSTEM_BLOCK,
|
|
743
|
+
params.system = [BILLING_SYSTEM_BLOCK, IDENTITY_WITH_CACHE, ...contentBlocks];
|
|
706
744
|
} else {
|
|
707
|
-
params.system = [BILLING_SYSTEM_BLOCK,
|
|
745
|
+
params.system = [BILLING_SYSTEM_BLOCK, IDENTITY_WITH_CACHE];
|
|
708
746
|
}
|
|
709
747
|
params.metadata = buildMetadata();
|
|
710
748
|
const supportsEffort = !this.apiModelId.includes("haiku") && !this.apiModelId.includes("claude-3-");
|
|
@@ -784,10 +822,10 @@ class AnthropicSDKModel {
|
|
|
784
822
|
if (anthropicOptions) {
|
|
785
823
|
if (anthropicOptions.thinking) {
|
|
786
824
|
const t = anthropicOptions.thinking;
|
|
787
|
-
if (t.type === "
|
|
825
|
+
if (t.type === "adaptive") {
|
|
826
|
+
params.thinking = { type: "adaptive" };
|
|
827
|
+
} else if (t.type === "enabled" && t.budgetTokens) {
|
|
788
828
|
params.thinking = { type: "enabled", budget_tokens: t.budgetTokens };
|
|
789
|
-
} else if (t.type === "adaptive") {
|
|
790
|
-
params.thinking = { type: "enabled", budget_tokens: 1e4 };
|
|
791
829
|
} else {
|
|
792
830
|
params.thinking = t;
|
|
793
831
|
}
|
|
@@ -797,7 +835,7 @@ class AnthropicSDKModel {
|
|
|
797
835
|
}
|
|
798
836
|
if (this.isOAuth && supportsContextManagement(this.apiModelId)) {
|
|
799
837
|
const edits = [];
|
|
800
|
-
const hasThinking = params.thinking?.type === "enabled";
|
|
838
|
+
const hasThinking = params.thinking?.type === "enabled" || params.thinking?.type === "adaptive";
|
|
801
839
|
if (hasThinking) {
|
|
802
840
|
edits.push({
|
|
803
841
|
type: "clear_thinking_20251015",
|
|
@@ -1045,6 +1083,7 @@ function persistCachedUsage() {
|
|
|
1045
1083
|
var API_TTL_MS = 5 * 60000;
|
|
1046
1084
|
|
|
1047
1085
|
// src/index.ts
|
|
1086
|
+
var CLAUDE_CODE_SYSTEM_PROMPT = claudecode_system_default;
|
|
1048
1087
|
var CLAUDE_CODE_VERSION = "2.1.81";
|
|
1049
1088
|
var OAUTH_BETAS = [
|
|
1050
1089
|
"claude-code-20250219",
|
|
@@ -1073,6 +1112,15 @@ function buildPluginModels(isOAuth) {
|
|
|
1073
1112
|
max: { effort: "max" }
|
|
1074
1113
|
}
|
|
1075
1114
|
};
|
|
1115
|
+
const opus47Variants = {
|
|
1116
|
+
variants: {
|
|
1117
|
+
low: { effort: "low" },
|
|
1118
|
+
medium: { effort: "medium" },
|
|
1119
|
+
high: { effort: "high" },
|
|
1120
|
+
xhigh: { effort: "xhigh" },
|
|
1121
|
+
max: { effort: "max" }
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1076
1124
|
return {
|
|
1077
1125
|
"claude-haiku-4-5": {
|
|
1078
1126
|
name: "Claude Haiku 4.5",
|
|
@@ -1135,6 +1183,21 @@ function buildPluginModels(isOAuth) {
|
|
|
1135
1183
|
},
|
|
1136
1184
|
options: { effort: "medium" },
|
|
1137
1185
|
...opusVariants
|
|
1186
|
+
},
|
|
1187
|
+
"claude-opus-4-7": {
|
|
1188
|
+
name: "Claude Opus 4.7",
|
|
1189
|
+
reasoning: true,
|
|
1190
|
+
tool_call: true,
|
|
1191
|
+
attachment: true,
|
|
1192
|
+
temperature: true,
|
|
1193
|
+
limit: { context: 1e6, output: 128000 },
|
|
1194
|
+
cost: cost("opus"),
|
|
1195
|
+
modalities: {
|
|
1196
|
+
input: ["text", "image", "pdf"],
|
|
1197
|
+
output: ["text"]
|
|
1198
|
+
},
|
|
1199
|
+
options: { effort: "medium" },
|
|
1200
|
+
...opus47Variants
|
|
1138
1201
|
}
|
|
1139
1202
|
};
|
|
1140
1203
|
}
|
|
@@ -1182,6 +1245,20 @@ function createAnthropicSDK(options = {}) {
|
|
|
1182
1245
|
init = { ...init, body: replaceCchPlaceholder(init.body, cch) };
|
|
1183
1246
|
} catch {}
|
|
1184
1247
|
}
|
|
1248
|
+
if (auth.isOAuth && init?.body && typeof init.body === "string") {
|
|
1249
|
+
const reqHeaders = new Headers(init.headers);
|
|
1250
|
+
const betas = (reqHeaders.get("anthropic-beta") ?? "").split(",").map((beta) => beta.trim()).filter(Boolean);
|
|
1251
|
+
if (init.body.length > 600000) {
|
|
1252
|
+
if (!betas.includes("context-1m-2025-08-07"))
|
|
1253
|
+
betas.push("context-1m-2025-08-07");
|
|
1254
|
+
} else {
|
|
1255
|
+
const filtered = betas.filter((beta) => beta !== "context-1m-2025-08-07");
|
|
1256
|
+
if (filtered.length !== betas.length)
|
|
1257
|
+
betas.splice(0, betas.length, ...filtered);
|
|
1258
|
+
}
|
|
1259
|
+
reqHeaders.set("anthropic-beta", betas.join(","));
|
|
1260
|
+
init = { ...init, headers: reqHeaders };
|
|
1261
|
+
}
|
|
1185
1262
|
const resp = await baseFetch(url, init);
|
|
1186
1263
|
const h5 = resp.headers.get("anthropic-ratelimit-unified-5h-utilization");
|
|
1187
1264
|
if (h5 != null) {
|
|
@@ -1235,6 +1312,24 @@ var anthropicSDKPlugin = async () => {
|
|
|
1235
1312
|
models: buildPluginModels(isOAuth),
|
|
1236
1313
|
...cfg.provider[PROVIDER_ID]
|
|
1237
1314
|
};
|
|
1315
|
+
},
|
|
1316
|
+
"experimental.chat.system.transform": async (_input, output) => {
|
|
1317
|
+
if (output.system.length === 0) {
|
|
1318
|
+
output.system.push(CLAUDE_CODE_SYSTEM_PROMPT);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
const ENV_MARKER = "You are powered by the model named";
|
|
1322
|
+
const original = output.system[0];
|
|
1323
|
+
const envIdx = original.indexOf(ENV_MARKER);
|
|
1324
|
+
if (envIdx > 0) {
|
|
1325
|
+
let appended = original.slice(envIdx);
|
|
1326
|
+
appended = appended.replace("Is directory a git repo: yes", "Is a git repository: true");
|
|
1327
|
+
appended = appended.replace("Is directory a git repo: no", "Is a git repository: false");
|
|
1328
|
+
output.system[0] = CLAUDE_CODE_SYSTEM_PROMPT + `
|
|
1329
|
+
` + appended;
|
|
1330
|
+
} else {
|
|
1331
|
+
output.system[0] = CLAUDE_CODE_SYSTEM_PROMPT;
|
|
1332
|
+
}
|
|
1238
1333
|
}
|
|
1239
1334
|
};
|
|
1240
1335
|
};
|
package/package.json
CHANGED
package/src/tui.tsx
CHANGED
|
@@ -360,7 +360,7 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
360
360
|
api.lifecycle.onDispose(offEvent)
|
|
361
361
|
|
|
362
362
|
// Register /usage command
|
|
363
|
-
api.command
|
|
363
|
+
api.command?.register(() => [
|
|
364
364
|
{
|
|
365
365
|
title: "Claude subscription usage",
|
|
366
366
|
value: "anthropic-sdk.usage",
|