@hypeitnow/opencode-claude-auth 1.6.0
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/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/anthropic-prompt.txt +166 -0
- package/dist/betas.d.ts +9 -0
- package/dist/betas.d.ts.map +1 -0
- package/dist/betas.js +102 -0
- package/dist/betas.js.map +1 -0
- package/dist/credentials.d.ts +29 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +313 -0
- package/dist/credentials.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +495 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain.d.ts +23 -0
- package/dist/keychain.d.ts.map +1 -0
- package/dist/keychain.js +365 -0
- package/dist/keychain.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +74 -0
- package/dist/logger.js.map +1 -0
- package/dist/model-config.d.ts +22 -0
- package/dist/model-config.d.ts.map +1 -0
- package/dist/model-config.js +44 -0
- package/dist/model-config.js.map +1 -0
- package/dist/oauth.d.ts +31 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +158 -0
- package/dist/oauth.js.map +1 -0
- package/dist/pkce.d.ts +6 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +23 -0
- package/dist/pkce.js.map +1 -0
- package/dist/plugin-config.d.ts +45 -0
- package/dist/plugin-config.d.ts.map +1 -0
- package/dist/plugin-config.js +66 -0
- package/dist/plugin-config.js.map +1 -0
- package/dist/signing.d.ts +31 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +55 -0
- package/dist/signing.js.map +1 -0
- package/dist/transforms.d.ts +14 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +271 -0
- package/dist/transforms.js.map +1 -0
- package/installation.md +98 -0
- package/opencode-claude-auth.js +2 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gmartin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# opencode-claude-auth
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-claude-auth)
|
|
4
|
+
[](https://github.com/griffinmartin/opencode-claude-auth/actions/workflows/ci.yml)
|
|
5
|
+
[](https://socket.dev/npm/package/opencode-claude-auth)
|
|
6
|
+
|
|
7
|
+
Self-contained Anthropic auth provider for OpenCode using your Claude Code credentials — no separate login or API key needed.
|
|
8
|
+
|
|
9
|
+
## How it works
|
|
10
|
+
|
|
11
|
+
The plugin registers its own auth provider with a custom fetch handler that intercepts all Anthropic API requests. It reads OAuth tokens from the macOS Keychain (or `~/.claude/.credentials.json` on other platforms), caches them in memory with a 30-second TTL, and handles the full request lifecycle — no builtin Anthropic auth plugin required. On macOS, multiple Claude Code accounts are detected automatically and can be switched via `opencode auth login`.
|
|
12
|
+
|
|
13
|
+
It also syncs credentials to OpenCode's `auth.json` as a fallback (on Windows, it writes to both `%USERPROFILE%\.local\share\opencode\auth.json` and `%LOCALAPPDATA%\opencode\auth.json` to cover all installation methods). If a token is near expiry, it refreshes directly via Anthropic's OAuth endpoint (zero LLM tokens consumed), falling back to the Claude CLI if the direct refresh fails. Background re-sync runs every 5 minutes.
|
|
14
|
+
|
|
15
|
+
### Raw `Claude Code` Keychain entry
|
|
16
|
+
|
|
17
|
+
On macOS, the `claude` CLI stores the raw `sk-ant-api03-...` Anthropic console API key in a Keychain service called `Claude Code` (no `-credentials` suffix). The plugin reads this directly and synthesises a 1-year-TTL credential — no JSON envelope, no refresh token. If the raw key is rejected by Anthropic's API (e.g. on org-locked accounts where the only available auth is OAuth), the 401 handler falls back to the **Claude OAuth (fallback)** method described below.
|
|
18
|
+
|
|
19
|
+
### OAuth fallback (`Claude OAuth (fallback)` auth method)
|
|
20
|
+
|
|
21
|
+
If the raw Keychain key returns 401, the plugin prints:
|
|
22
|
+
|
|
23
|
+
> `opencode-claude-auth: API 401 for <model>. The raw Keychain key was rejected. Run \`opencode auth\` and pick "Claude OAuth (fallback)" to authorize via OAuth.`
|
|
24
|
+
|
|
25
|
+
To authorize, run `opencode auth login` and select **Claude OAuth (fallback)**. The plugin opens `https://platform.claude.com/oauth/authorize` with the `org:create_api_key`, `user:inference`, `user:sessions:claude_code`, and other scopes. Authorize in the browser, paste the full callback URL (or just the `code#state` pair) into opencode, and the plugin exchanges it for a real `{access, refresh, expires}` token. The token is auto-refreshed on every subsequent request via Anthropic's OAuth endpoint — no LLM tokens consumed.
|
|
26
|
+
|
|
27
|
+
The flow uses standard OAuth 2.0 + PKCE with `client_id=9d1c250a-e61b-44d9-88ed-5944d1962f5e` and `token_url=https://platform.claude.com/v1/oauth/token`. Ported from `ex-machina/opencode-anthropic-auth`.
|
|
28
|
+
|
|
29
|
+
## Prerequisites
|
|
30
|
+
|
|
31
|
+
- Claude Code installed and authenticated (run `claude` at least once)
|
|
32
|
+
- OpenCode installed
|
|
33
|
+
|
|
34
|
+
macOS is preferred (uses Keychain). Linux and Windows work via the credentials file fallback.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
**For Humans**
|
|
39
|
+
|
|
40
|
+
**Option A: Let an LLM do it**
|
|
41
|
+
|
|
42
|
+
Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Install the opencode-claude-auth plugin and configure it by following: https://raw.githubusercontent.com/griffinmartin/opencode-claude-auth/main/installation.md
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Option B: Manual setup**
|
|
49
|
+
|
|
50
|
+
1. **Add the plugin** to `~/.config/opencode/opencode.json`:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"plugin": ["opencode-claude-auth@latest"]
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
> The `@latest` tag ensures OpenCode always pulls the newest version on startup. No manual `npm install` is needed — OpenCode [automatically installs npm plugins using Bun at startup](https://opencode.ai/docs/plugins/#how-plugins-are-installed).
|
|
59
|
+
|
|
60
|
+
2. **Use it** — just run OpenCode. The plugin handles auth automatically using your Claude Code credentials.
|
|
61
|
+
|
|
62
|
+
**For LLM Agents**
|
|
63
|
+
|
|
64
|
+
See [installation.md](installation.md) for step-by-step agent instructions.
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
Just run OpenCode. The plugin handles auth automatically — it reads your Claude Code credentials, provides them to the Anthropic API, and refreshes them in the background. If your credentials aren't OAuth-based, the plugin falls through to standard API key auth.
|
|
69
|
+
|
|
70
|
+
## Supported models
|
|
71
|
+
|
|
72
|
+
15 supported models. Run `pnpm run test:models` to verify against your account.
|
|
73
|
+
|
|
74
|
+
| Model |
|
|
75
|
+
| -------------------------- |
|
|
76
|
+
| claude-haiku-4-5 |
|
|
77
|
+
| claude-haiku-4-5-20251001 |
|
|
78
|
+
| claude-opus-4-0 |
|
|
79
|
+
| claude-opus-4-1 |
|
|
80
|
+
| claude-opus-4-1-20250805 |
|
|
81
|
+
| claude-opus-4-20250514 |
|
|
82
|
+
| claude-opus-4-5 |
|
|
83
|
+
| claude-opus-4-5-20251101 |
|
|
84
|
+
| claude-opus-4-6 |
|
|
85
|
+
| claude-opus-4-7 |
|
|
86
|
+
| claude-sonnet-4-0 |
|
|
87
|
+
| claude-sonnet-4-20250514 |
|
|
88
|
+
| claude-sonnet-4-5 |
|
|
89
|
+
| claude-sonnet-4-5-20250929 |
|
|
90
|
+
| claude-sonnet-4-6 |
|
|
91
|
+
|
|
92
|
+
## Credential sources
|
|
93
|
+
|
|
94
|
+
The plugin checks these in order:
|
|
95
|
+
|
|
96
|
+
1. macOS Keychain
|
|
97
|
+
- All `Claude Code-credentials*` entries — multiple accounts are detected automatically
|
|
98
|
+
- The bare `Claude Code` service — holds raw `sk-ant-api03-...` API keys for users whose `claude` CLI is configured with an Anthropic console API key rather than an OAuth subscription. The key is treated as a long-lived credential (1-year TTL) and never written back to the Keychain, since it would be silently overwritten with a JSON blob otherwise.
|
|
99
|
+
2. `~/.claude/.credentials.json` (fallback, works on all platforms)
|
|
100
|
+
|
|
101
|
+
## Multiple accounts (macOS)
|
|
102
|
+
|
|
103
|
+
If you have [multiple Claude Code accounts](https://gist.github.com/KMJ-007/0979814968722051620461ab2aa01bf2) authenticated on macOS, the plugin detects all of them from the Keychain automatically. Each account is labeled by its subscription tier (Claude Pro, Claude Max, etc.).
|
|
104
|
+
|
|
105
|
+
To switch accounts:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
opencode auth login
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Select "Switch Claude Code account" and pick the account you want to use. Your selection is persisted across sessions.
|
|
112
|
+
|
|
113
|
+
If only one account is found, the switcher is hidden and the plugin uses it directly.
|
|
114
|
+
|
|
115
|
+
## Troubleshooting
|
|
116
|
+
|
|
117
|
+
| Problem | Solution |
|
|
118
|
+
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
119
|
+
| "Credentials not found" | Run `claude` to authenticate with Claude Code first |
|
|
120
|
+
| "Keychain is locked" | Run `security unlock-keychain ~/Library/Keychains/login.keychain-db` |
|
|
121
|
+
| "Token expired and refresh failed" | The plugin runs `claude` CLI to refresh automatically. If this fails, re-authenticate manually by running `claude` |
|
|
122
|
+
| Not working on Linux/Windows | Ensure `~/.claude/.credentials.json` exists. Run `claude` to create it |
|
|
123
|
+
| Keychain access denied | Grant access when macOS prompts you |
|
|
124
|
+
| Keychain read timed out | Restart Keychain Access (can happen on macOS Tahoe) |
|
|
125
|
+
| "Credentials are unavailable or expired" | Run `claude` to refresh your Claude Code credentials |
|
|
126
|
+
| "Extra usage is required for long context requests" | Your conversation exceeded 200k tokens. See [Long context (1M)](#long-context-1m) below |
|
|
127
|
+
| Plugin not updating to latest version | Delete the cached package: `rm -rf ~/.cache/opencode/packages/opencode-claude-auth@latest/` then restart OpenCode |
|
|
128
|
+
|
|
129
|
+
### Diagnostic logging
|
|
130
|
+
|
|
131
|
+
If you're hitting auth errors that are hard to reproduce, enable debug logging to capture the full auth flow:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
export CLAUDE_AUTH_DEBUG=1
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Restart OpenCode and reproduce the issue. The plugin writes structured JSON logs to `~/.local/share/opencode/claude-auth-debug.log`. All secrets (tokens, API keys) are automatically redacted — the log file is safe to paste into a GitHub issue.
|
|
138
|
+
|
|
139
|
+
To write logs to a custom path:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
export CLAUDE_AUTH_DEBUG=/tmp/claude-auth-debug.log
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Disable when done:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
unset CLAUDE_AUTH_DEBUG
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Long context (1M)
|
|
152
|
+
|
|
153
|
+
The `context-1m-2025-08-07` beta header is not sent by default. Without it, the API caps context at 200k tokens.
|
|
154
|
+
|
|
155
|
+
To enable 1M context (requires Claude Max or a plan with extra usage coverage), use **either** of these methods:
|
|
156
|
+
|
|
157
|
+
**Option A: Config file** (recommended — no environment setup needed)
|
|
158
|
+
|
|
159
|
+
Add `enable1mContext` to any agent in your `opencode.json` (project-level or `~/.config/opencode/opencode.json`). Setting it in any one agent enables 1M context globally for all supported models — you don't need to set it for each agent:
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"plugin": ["opencode-claude-auth@latest"],
|
|
164
|
+
"agent": {
|
|
165
|
+
"build": {
|
|
166
|
+
"enable1mContext": true
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Option B: Environment variable**
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
export ANTHROPIC_ENABLE_1M_CONTEXT=true
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
If both are set, the environment variable takes priority.
|
|
179
|
+
|
|
180
|
+
The Claude CLI itself treats 1M context as opt-in (via a `[1m]` model suffix). Sending the beta without a plan that covers long context charges causes "Extra usage is required for long context requests" errors. Versions before 0.8.0 sent this beta automatically for 4.6+ models, which broke things for Pro users ([#64](https://github.com/griffinmartin/opencode-claude-auth/issues/64)).
|
|
181
|
+
|
|
182
|
+
If a long context error still occurs (e.g. from a beta flag added via `ANTHROPIC_BETA_FLAGS`), the plugin retries without the offending flag.
|
|
183
|
+
|
|
184
|
+
## Validating OAuth refresh
|
|
185
|
+
|
|
186
|
+
To verify the direct OAuth token refresh works with your credentials:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
pnpm run validate:oauth # refresh + write-back (safe, keeps credentials valid)
|
|
190
|
+
pnpm run validate:oauth -- --dry-run # show what would be sent without making the request
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This reads your stored credentials, calls Anthropic's OAuth token endpoint, and writes the new tokens back to storage. Refresh tokens rotate on each use, so write-back is enabled by default to keep your stored credentials valid.
|
|
194
|
+
|
|
195
|
+
## Environment variable overrides
|
|
196
|
+
|
|
197
|
+
All configurable parameters can be overridden via environment variables. If Anthropic changes something before we publish an update, set an env var and keep working:
|
|
198
|
+
|
|
199
|
+
| Variable | Description | Default |
|
|
200
|
+
| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
201
|
+
| `ANTHROPIC_CLI_VERSION` | Claude CLI version for user-agent and billing headers | `2.1.80` |
|
|
202
|
+
| `ANTHROPIC_USER_AGENT` | Full User-Agent string (overrides CLI version) | `claude-cli/{version} (external, cli)` |
|
|
203
|
+
| `ANTHROPIC_BETA_FLAGS` | Comma-separated beta feature flags | `claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14,prompt-caching-scope-2026-01-05` |
|
|
204
|
+
| `ANTHROPIC_ENABLE_1M_CONTEXT` | Enable 1M token context window for 4.6+ models (requires Max subscription) | `false` |
|
|
205
|
+
| `CLAUDE_AUTH_DEBUG` | Enable diagnostic logging (`1` for default path, or a custom file path) | disabled |
|
|
206
|
+
| `OPENCODE_CLAUDE_AUTH_MAX_RETRY_MS` | Max ms the plugin waits when honouring a 429/529 `retry-after` header. Beyond this cap the response surfaces immediately so OpenCode doesn't appear to hang on hour-long quota resets. | `30000` |
|
|
207
|
+
|
|
208
|
+
Example:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
export ANTHROPIC_CLI_VERSION=2.2.0
|
|
212
|
+
export ANTHROPIC_ENABLE_1M_CONTEXT=true # requires Claude Max
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## How it works (technical)
|
|
216
|
+
|
|
217
|
+
- Registers an `auth.loader` with a custom `fetch` that intercepts all Anthropic API requests
|
|
218
|
+
- Sets `Authorization: Bearer` with fresh OAuth tokens (cached in memory, 30s TTL, updated in-place after refresh)
|
|
219
|
+
- Translates tool names between OpenCode and Anthropic API formats (adds/strips `mcp_` prefix)
|
|
220
|
+
- Buffers SSE response streams at event boundaries for reliable tool name translation
|
|
221
|
+
- Injects Claude Code identity into system prompts via `experimental.chat.system.transform`
|
|
222
|
+
- Sets required API headers (beta flags, billing, user-agent) with model-aware selection
|
|
223
|
+
- On macOS, enumerates all `Claude Code-credentials*` Keychain entries and labels them by subscription tier
|
|
224
|
+
- Provides an account switcher via `opencode auth login` when multiple accounts are found; persists selection to `~/.local/share/opencode/claude-account-source.txt`
|
|
225
|
+
- Syncs credentials to `auth.json` on startup and every 5 minutes as a fallback (sync never triggers refresh; refresh is lazy, only on API requests)
|
|
226
|
+
- On Windows, writes to both `%USERPROFILE%\.local\share\opencode\auth.json` and `%LOCALAPPDATA%\opencode\auth.json`
|
|
227
|
+
- Retries API requests on 429 (rate limit) and 529 (overloaded) with exponential backoff, respecting `retry-after` headers
|
|
228
|
+
- When a token is within 60 seconds of expiry, refreshes directly via `POST https://claude.ai/v1/oauth/token` (no LLM tokens consumed). Falls back to `claude` CLI if the direct refresh fails. New tokens are written back to Keychain (macOS) or credentials file (Linux/Windows) to keep stored credentials in sync with rotated refresh tokens
|
|
229
|
+
- If credentials aren't OAuth-based, the auth loader returns `{}` and falls through to API key auth
|
|
230
|
+
- If credentials are unavailable or unreadable, the plugin disables itself and OpenCode continues without Claude auth
|
|
231
|
+
|
|
232
|
+
## Disclaimer
|
|
233
|
+
|
|
234
|
+
This plugin uses Claude Code's OAuth credentials to authenticate with Anthropic's API. Anthropic's Terms of Service state that Claude Pro/Max subscription tokens should only be used with official Anthropic clients. This plugin exists as a community workaround and may stop working if Anthropic changes their OAuth infrastructure. Use at your own discretion.
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
2
|
+
|
|
3
|
+
IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.
|
|
4
|
+
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.
|
|
5
|
+
|
|
6
|
+
If the user asks for help or wants to give feedback inform them of the following:
|
|
7
|
+
- /help: Get help with using Claude Code
|
|
8
|
+
- To give feedback, users should report the issue at https://github.com/anthropics/claude-code/issues
|
|
9
|
+
|
|
10
|
+
When the user directly asks about Claude Code (eg. "can Claude Code do...", "does Claude Code have..."), or asks in second person (eg. "are you able...", "can you do..."), or asks how to use a specific Claude Code feature (eg. implement a hook, or write a slash command), use the WebFetch tool to gather information to answer the question from Claude Code docs. The list of available docs is available at https://docs.claude.com/en/docs/claude-code/claude_code_docs_map.md.
|
|
11
|
+
|
|
12
|
+
# Tone and style
|
|
13
|
+
You should be concise, direct, and to the point, while providing complete information and matching the level of detail you provide in your response with the level of complexity of the user's query or the work you have completed.
|
|
14
|
+
A concise response is generally less than 4 lines, not including tool calls or code generated. You should provide more detail when the task is complex or when the user asks you to.
|
|
15
|
+
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
|
|
16
|
+
IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
|
|
17
|
+
Do not add additional code explanation summary unless requested by the user. After working on a file, briefly confirm that you have completed the task, rather than providing an explanation of what you did.
|
|
18
|
+
Answer the user's question directly, avoiding any elaboration, explanation, introduction, conclusion, or excessive details. Brief answers are best, but be sure to provide complete information. You MUST avoid extra preamble before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...".
|
|
19
|
+
|
|
20
|
+
Here are some examples to demonstrate appropriate verbosity:
|
|
21
|
+
<example>
|
|
22
|
+
user: 2 + 2
|
|
23
|
+
assistant: 4
|
|
24
|
+
</example>
|
|
25
|
+
|
|
26
|
+
<example>
|
|
27
|
+
user: what is 2+2?
|
|
28
|
+
assistant: 4
|
|
29
|
+
</example>
|
|
30
|
+
|
|
31
|
+
<example>
|
|
32
|
+
user: is 11 a prime number?
|
|
33
|
+
assistant: Yes
|
|
34
|
+
</example>
|
|
35
|
+
|
|
36
|
+
<example>
|
|
37
|
+
user: what command should I run to list files in the current directory?
|
|
38
|
+
assistant: ls
|
|
39
|
+
</example>
|
|
40
|
+
|
|
41
|
+
<example>
|
|
42
|
+
user: what command should I run to watch files in the current directory?
|
|
43
|
+
assistant: [runs ls to list the files in the current directory, then read docs/commands in the relevant file to find out how to watch files]
|
|
44
|
+
npm run dev
|
|
45
|
+
</example>
|
|
46
|
+
|
|
47
|
+
<example>
|
|
48
|
+
user: How many golf balls fit inside a jetta?
|
|
49
|
+
assistant: 150000
|
|
50
|
+
</example>
|
|
51
|
+
|
|
52
|
+
<example>
|
|
53
|
+
user: what files are in the directory src/?
|
|
54
|
+
assistant: [runs ls and sees foo.c, bar.c, baz.c]
|
|
55
|
+
user: which file contains the implementation of foo?
|
|
56
|
+
assistant: src/foo.c
|
|
57
|
+
</example>
|
|
58
|
+
When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).
|
|
59
|
+
Remember that your output will be displayed on a command line interface. Your responses can use GitHub-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
60
|
+
Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.
|
|
61
|
+
If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
|
|
62
|
+
Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
63
|
+
IMPORTANT: Keep your responses short, since they will be displayed on a command line interface.
|
|
64
|
+
|
|
65
|
+
# Proactiveness
|
|
66
|
+
You are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:
|
|
67
|
+
- Doing the right thing when asked, including taking actions and follow-up actions
|
|
68
|
+
- Not surprising the user with actions you take without asking
|
|
69
|
+
For example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions.
|
|
70
|
+
|
|
71
|
+
# Professional objectivity
|
|
72
|
+
Prioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving, providing direct, objective technical info without any unnecessary superlatives, praise, or emotional validation. It is best for the user if Claude honestly applies the same rigorous standards to all ideas and disagrees when necessary, even if it may not be what the user wants to hear. Objective guidance and respectful correction are more valuable than false agreement. Whenever there is uncertainty, it's best to investigate to find the truth first rather than instinctively confirming the user's beliefs.
|
|
73
|
+
|
|
74
|
+
# Task Management
|
|
75
|
+
You have access to the TodoWrite tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
76
|
+
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
77
|
+
|
|
78
|
+
It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
|
|
82
|
+
<example>
|
|
83
|
+
user: Run the build and fix any type errors
|
|
84
|
+
assistant: I'm going to use the TodoWrite tool to write the following items to the todo list:
|
|
85
|
+
- Run the build
|
|
86
|
+
- Fix any type errors
|
|
87
|
+
|
|
88
|
+
I'm now going to run the build using Bash.
|
|
89
|
+
|
|
90
|
+
Looks like I found 10 type errors. I'm going to use the TodoWrite tool to write 10 items to the todo list.
|
|
91
|
+
|
|
92
|
+
marking the first todo as in_progress
|
|
93
|
+
|
|
94
|
+
Let me start working on the first item...
|
|
95
|
+
|
|
96
|
+
The first item has been fixed, let me mark the first todo as completed, and move on to the second item...
|
|
97
|
+
..
|
|
98
|
+
..
|
|
99
|
+
</example>
|
|
100
|
+
In the above example, the assistant completes all the tasks, including the 10 error fixes and running the build and fixing all errors.
|
|
101
|
+
|
|
102
|
+
<example>
|
|
103
|
+
user: Help me write a new feature that allows users to track their usage metrics and export them to various formats
|
|
104
|
+
|
|
105
|
+
assistant: I'll help you implement a usage metrics tracking and export feature. Let me first use the TodoWrite tool to plan this task.
|
|
106
|
+
Adding the following todos to the todo list:
|
|
107
|
+
1. Research existing metrics tracking in the codebase
|
|
108
|
+
2. Design the metrics collection system
|
|
109
|
+
3. Implement core metrics tracking functionality
|
|
110
|
+
4. Create export functionality for different formats
|
|
111
|
+
|
|
112
|
+
Let me start by researching the existing codebase to understand what metrics we might already be tracking and how we can build on that.
|
|
113
|
+
|
|
114
|
+
I'm going to search for any existing metrics or telemetry code in the project.
|
|
115
|
+
|
|
116
|
+
I've found some existing telemetry code. Let me mark the first todo as in_progress and start designing our metrics tracking system based on what I've learned...
|
|
117
|
+
|
|
118
|
+
[Assistant continues implementing the feature step by step, marking todos as in_progress and completed as they go]
|
|
119
|
+
</example>
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
# Doing tasks
|
|
125
|
+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
126
|
+
- Use the TodoWrite tool to plan the task if required
|
|
127
|
+
|
|
128
|
+
- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# Tool usage policy
|
|
132
|
+
- When doing file search, prefer to use the Task tool in order to reduce context usage.
|
|
133
|
+
- You should proactively use the Task tool with specialized agents when the task at hand matches the agent's description.
|
|
134
|
+
|
|
135
|
+
- When WebFetch returns a message about a redirect to a different host, you should immediately make a new WebFetch request with the redirect URL provided in the response.
|
|
136
|
+
- You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.
|
|
137
|
+
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks. For example, if you need to launch multiple agents in parallel, send a single message with multiple Task tool calls.
|
|
138
|
+
- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools: Read for reading files instead of cat/head/tail, Edit for editing instead of sed/awk, and Write for creating files instead of cat with heredoc or echo redirection. Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
Here is useful information about the environment you are running in:
|
|
142
|
+
<env>
|
|
143
|
+
Working directory: /home/thdxr/dev/projects/anomalyco/opencode/packages/opencode
|
|
144
|
+
Is directory a git repo: Yes
|
|
145
|
+
Platform: linux
|
|
146
|
+
OS Version: Linux 6.12.4-arch1-1
|
|
147
|
+
Today's date: 2025-09-30
|
|
148
|
+
</env>
|
|
149
|
+
You are powered by the model named Sonnet 4.5. The exact model ID is claude-sonnet-4-5-20250929.
|
|
150
|
+
|
|
151
|
+
Assistant knowledge cutoff is January 2025.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
IMPORTANT: Always use the TodoWrite tool to plan and track tasks throughout the conversation.
|
|
158
|
+
|
|
159
|
+
# Code References
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
<example>
|
|
164
|
+
user: Where are errors from the client handled?
|
|
165
|
+
assistant: Clients are marked as failed in the `connectToServer` function in src/services/process.ts:712.
|
|
166
|
+
</example>
|
package/dist/betas.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const LONG_CONTEXT_BETAS: string[];
|
|
2
|
+
export declare function getExcludedBetas(modelId: string): Set<string>;
|
|
3
|
+
export declare function addExcludedBeta(modelId: string, beta: string): void;
|
|
4
|
+
export declare function resetExcludedBetas(): void;
|
|
5
|
+
export declare function isLongContextError(responseBody: string): boolean;
|
|
6
|
+
export declare function getNextBetaToExclude(modelId: string): string | null;
|
|
7
|
+
export declare function supports1mContext(modelId: string): boolean;
|
|
8
|
+
export declare function getModelBetas(modelId: string, excluded?: Set<string>): string[];
|
|
9
|
+
//# sourceMappingURL=betas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betas.d.ts","sourceRoot":"","sources":["../src/betas.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,UAA0B,CAAA;AAgBzD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAe7D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAInE;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAGzC;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAQhE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQnE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAU1D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GACrB,MAAM,EAAE,CAqCV"}
|
package/dist/betas.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { config, getModelOverride } from "./model-config.js";
|
|
2
|
+
import { isEnable1mContext } from "./plugin-config.js";
|
|
3
|
+
// Beta flags to try removing in order when "long context" errors occur
|
|
4
|
+
export const LONG_CONTEXT_BETAS = config.longContextBetas;
|
|
5
|
+
function getRequiredBetas() {
|
|
6
|
+
return (process.env.ANTHROPIC_BETA_FLAGS ?? config.baseBetas.join(","))
|
|
7
|
+
.split(",")
|
|
8
|
+
.map((s) => s.trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
// Session-level cache of excluded beta flags per model (resets on process restart)
|
|
12
|
+
const excludedBetas = new Map();
|
|
13
|
+
// Track the last-seen beta flags env var and model to detect changes
|
|
14
|
+
let lastBetaFlagsEnv = process.env.ANTHROPIC_BETA_FLAGS;
|
|
15
|
+
let lastModelId;
|
|
16
|
+
export function getExcludedBetas(modelId) {
|
|
17
|
+
// Reset exclusions if user changed ANTHROPIC_BETA_FLAGS
|
|
18
|
+
const currentBetaFlags = process.env.ANTHROPIC_BETA_FLAGS;
|
|
19
|
+
if (currentBetaFlags !== lastBetaFlagsEnv) {
|
|
20
|
+
excludedBetas.clear();
|
|
21
|
+
lastBetaFlagsEnv = currentBetaFlags;
|
|
22
|
+
}
|
|
23
|
+
// Reset exclusions if user switched models (new model may support different betas)
|
|
24
|
+
if (lastModelId !== undefined && lastModelId !== modelId) {
|
|
25
|
+
excludedBetas.clear();
|
|
26
|
+
}
|
|
27
|
+
lastModelId = modelId;
|
|
28
|
+
return excludedBetas.get(modelId) ?? new Set();
|
|
29
|
+
}
|
|
30
|
+
export function addExcludedBeta(modelId, beta) {
|
|
31
|
+
const existing = excludedBetas.get(modelId) ?? new Set();
|
|
32
|
+
existing.add(beta);
|
|
33
|
+
excludedBetas.set(modelId, existing);
|
|
34
|
+
}
|
|
35
|
+
export function resetExcludedBetas() {
|
|
36
|
+
excludedBetas.clear();
|
|
37
|
+
lastModelId = undefined;
|
|
38
|
+
}
|
|
39
|
+
export function isLongContextError(responseBody) {
|
|
40
|
+
return (responseBody.includes("Extra usage is required for long context requests") ||
|
|
41
|
+
responseBody.includes("long context beta is not yet available") ||
|
|
42
|
+
responseBody.includes("You're out of extra usage"));
|
|
43
|
+
}
|
|
44
|
+
export function getNextBetaToExclude(modelId) {
|
|
45
|
+
const excluded = getExcludedBetas(modelId);
|
|
46
|
+
for (const beta of LONG_CONTEXT_BETAS) {
|
|
47
|
+
if (!excluded.has(beta)) {
|
|
48
|
+
return beta;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null; // All long-context betas already excluded
|
|
52
|
+
}
|
|
53
|
+
export function supports1mContext(modelId) {
|
|
54
|
+
const lower = modelId.toLowerCase();
|
|
55
|
+
if (!lower.includes("opus") && !lower.includes("sonnet"))
|
|
56
|
+
return false;
|
|
57
|
+
const versionMatch = lower.match(/(opus|sonnet)-(\d+)-(\d+)/);
|
|
58
|
+
if (!versionMatch)
|
|
59
|
+
return false;
|
|
60
|
+
const major = parseInt(versionMatch[2], 10);
|
|
61
|
+
const minor = parseInt(versionMatch[3], 10);
|
|
62
|
+
// Date suffixes like 20250514 are not minor versions — treat as x.0
|
|
63
|
+
const effectiveMinor = minor > 99 ? 0 : minor;
|
|
64
|
+
return major > 4 || (major === 4 && effectiveMinor >= 6);
|
|
65
|
+
}
|
|
66
|
+
export function getModelBetas(modelId, excluded) {
|
|
67
|
+
const betas = [...getRequiredBetas()];
|
|
68
|
+
// context-1m is OPT-IN only, matching the official Claude CLI behavior.
|
|
69
|
+
// The CLI only sends this beta when the model ID has a [1m] suffix.
|
|
70
|
+
// Without it, the API enforces a 200k context limit. Sending the beta
|
|
71
|
+
// without a subscription that covers long context billing causes
|
|
72
|
+
// "Extra usage is required for long context requests" errors.
|
|
73
|
+
//
|
|
74
|
+
// Users who want 1M context should set ANTHROPIC_ENABLE_1M_CONTEXT=true
|
|
75
|
+
// (requires a Claude Max subscription or a plan that covers extra usage).
|
|
76
|
+
if (isEnable1mContext() && supports1mContext(modelId)) {
|
|
77
|
+
betas.push(config.longContextBetas[0]);
|
|
78
|
+
}
|
|
79
|
+
// Apply per-model overrides (e.g. haiku excludes claude-code-20250219)
|
|
80
|
+
const override = getModelOverride(modelId);
|
|
81
|
+
if (override) {
|
|
82
|
+
if (override.exclude) {
|
|
83
|
+
for (const ex of override.exclude) {
|
|
84
|
+
const idx = betas.indexOf(ex);
|
|
85
|
+
if (idx !== -1)
|
|
86
|
+
betas.splice(idx, 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (override.add) {
|
|
90
|
+
for (const add of override.add) {
|
|
91
|
+
if (!betas.includes(add))
|
|
92
|
+
betas.push(add);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Filter out excluded betas (from previous failed requests due to long context errors)
|
|
97
|
+
if (excluded && excluded.size > 0) {
|
|
98
|
+
return betas.filter((beta) => !excluded.has(beta));
|
|
99
|
+
}
|
|
100
|
+
return betas;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=bet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EAAE,CAAC;YACjB,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,uFAAuF;IACvF,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ClaudeCredentials, type ClaudeAccount } from "./keychain.ts";
|
|
2
|
+
export type { ClaudeCredentials } from "./keychain.ts";
|
|
3
|
+
export type { ClaudeAccount } from "./keychain.ts";
|
|
4
|
+
export declare function initAccounts(accounts: ClaudeAccount[]): void;
|
|
5
|
+
export declare function getAccounts(): ClaudeAccount[];
|
|
6
|
+
export declare function setActiveAccountSource(source: string): void;
|
|
7
|
+
export declare function refreshAccountsList(): ClaudeAccount[];
|
|
8
|
+
export declare function loadPersistedAccountSource(): string | null;
|
|
9
|
+
export declare function saveAccountSource(source: string): void;
|
|
10
|
+
export declare function syncAuthJson(creds: ClaudeCredentials): void;
|
|
11
|
+
export declare const OAUTH_TOKEN_URL = "https://claude.ai/v1/oauth/token";
|
|
12
|
+
export declare const OAUTH_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
13
|
+
/**
|
|
14
|
+
* Parse a raw OAuth token response into ClaudeCredentials.
|
|
15
|
+
* Returns null if the response is missing a valid access_token.
|
|
16
|
+
* Defaults expires_in to 36000s (10h) to match observed Claude token lifetime.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseOAuthResponse(raw: string, currentRefreshToken: string, now?: number): ClaudeCredentials | null;
|
|
19
|
+
export declare function refreshViaOAuth(refreshToken: string): ClaudeCredentials | null;
|
|
20
|
+
export declare function refreshIfNeeded(account?: ClaudeAccount): ClaudeCredentials | null;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the active account's credentials for auth.json sync purposes.
|
|
23
|
+
* Unlike getCachedCredentials(), this does NOT trigger a refresh.
|
|
24
|
+
* It returns the account's current in-memory credentials if they're still valid.
|
|
25
|
+
* Returns null if no account or credentials are expired.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCredentialsForSync(): ClaudeCredentials | null;
|
|
28
|
+
export declare function getCachedCredentials(): ClaudeCredentials | null;
|
|
29
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAUA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAA;AAItB,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAWlD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,IAAI,CAE5D;AAED,wBAAgB,WAAW,IAAI,aAAa,EAAE,CAE7C;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAQ3D;AAED,wBAAgB,mBAAmB,IAAI,aAAa,EAAE,CAGrD;AAqBD,wBAAgB,0BAA0B,IAAI,MAAM,GAAG,IAAI,CAU1D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAStD;AA4CD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAc3D;AAED,eAAO,MAAM,eAAe,qCAAqC,CAAA;AACjE,eAAO,MAAM,eAAe,yCAAyC,CAAA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