anyclaude-sdk 0.1.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.
Files changed (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/agent.d.ts +110 -0
  4. package/dist/agent.js +897 -0
  5. package/dist/background/index.d.ts +3 -0
  6. package/dist/background/index.js +9 -0
  7. package/dist/background/manager.d.ts +32 -0
  8. package/dist/background/manager.js +108 -0
  9. package/dist/background/tools.d.ts +5 -0
  10. package/dist/background/tools.js +98 -0
  11. package/dist/background/worker.d.ts +19 -0
  12. package/dist/background/worker.js +30 -0
  13. package/dist/commands/builtins.d.ts +2 -0
  14. package/dist/commands/builtins.js +306 -0
  15. package/dist/commands/index.d.ts +21 -0
  16. package/dist/commands/index.js +56 -0
  17. package/dist/commands/types.d.ts +110 -0
  18. package/dist/commands/types.js +5 -0
  19. package/dist/compact.d.ts +22 -0
  20. package/dist/compact.js +67 -0
  21. package/dist/fs/dexie.d.ts +57 -0
  22. package/dist/fs/dexie.js +243 -0
  23. package/dist/fs/index.d.ts +4 -0
  24. package/dist/fs/index.js +13 -0
  25. package/dist/fs/linuxTree.d.ts +11 -0
  26. package/dist/fs/linuxTree.js +43 -0
  27. package/dist/fs/opfs.d.ts +23 -0
  28. package/dist/fs/opfs.js +112 -0
  29. package/dist/index.d.ts +26 -0
  30. package/dist/index.js +29 -0
  31. package/dist/llm/anthropic.d.ts +24 -0
  32. package/dist/llm/anthropic.js +280 -0
  33. package/dist/llm/index.d.ts +3 -0
  34. package/dist/llm/index.js +3 -0
  35. package/dist/llm/inlineTools.d.ts +11 -0
  36. package/dist/llm/inlineTools.js +72 -0
  37. package/dist/llm/openai.d.ts +29 -0
  38. package/dist/llm/openai.js +224 -0
  39. package/dist/llm/responses.d.ts +18 -0
  40. package/dist/llm/responses.js +256 -0
  41. package/dist/mcp/client.d.ts +20 -0
  42. package/dist/mcp/client.js +156 -0
  43. package/dist/mcp/index.d.ts +24 -0
  44. package/dist/mcp/index.js +157 -0
  45. package/dist/mcp/proxy.d.ts +3 -0
  46. package/dist/mcp/proxy.js +25 -0
  47. package/dist/mcp/sdkServer.d.ts +21 -0
  48. package/dist/mcp/sdkServer.js +28 -0
  49. package/dist/mcp/types.d.ts +92 -0
  50. package/dist/mcp/types.js +5 -0
  51. package/dist/memory/index.d.ts +4 -0
  52. package/dist/memory/index.js +5 -0
  53. package/dist/memory/render.d.ts +7 -0
  54. package/dist/memory/render.js +46 -0
  55. package/dist/memory/store.d.ts +20 -0
  56. package/dist/memory/store.js +79 -0
  57. package/dist/memory/tools.d.ts +5 -0
  58. package/dist/memory/tools.js +95 -0
  59. package/dist/memory/types.d.ts +15 -0
  60. package/dist/memory/types.js +4 -0
  61. package/dist/permissions/dangerous.d.ts +4 -0
  62. package/dist/permissions/dangerous.js +24 -0
  63. package/dist/permissions/gate.d.ts +21 -0
  64. package/dist/permissions/gate.js +66 -0
  65. package/dist/permissions/index.d.ts +5 -0
  66. package/dist/permissions/index.js +6 -0
  67. package/dist/permissions/match.d.ts +19 -0
  68. package/dist/permissions/match.js +104 -0
  69. package/dist/permissions/planMode.d.ts +3 -0
  70. package/dist/permissions/planMode.js +33 -0
  71. package/dist/permissions/types.d.ts +19 -0
  72. package/dist/permissions/types.js +2 -0
  73. package/dist/persist.d.ts +15 -0
  74. package/dist/persist.js +58 -0
  75. package/dist/prompt.d.ts +6 -0
  76. package/dist/prompt.js +34 -0
  77. package/dist/query.d.ts +105 -0
  78. package/dist/query.js +115 -0
  79. package/dist/queue.d.ts +23 -0
  80. package/dist/queue.js +43 -0
  81. package/dist/sandbox/cloudflare.d.ts +48 -0
  82. package/dist/sandbox/cloudflare.js +124 -0
  83. package/dist/sandbox/daytona.d.ts +48 -0
  84. package/dist/sandbox/daytona.js +79 -0
  85. package/dist/sandbox/e2b.d.ts +54 -0
  86. package/dist/sandbox/e2b.js +87 -0
  87. package/dist/sandbox/index.d.ts +8 -0
  88. package/dist/sandbox/index.js +19 -0
  89. package/dist/sandbox/local.d.ts +51 -0
  90. package/dist/sandbox/local.js +155 -0
  91. package/dist/sandbox/types.d.ts +18 -0
  92. package/dist/sandbox/types.js +27 -0
  93. package/dist/sandbox/util.d.ts +15 -0
  94. package/dist/sandbox/util.js +100 -0
  95. package/dist/sandbox/vercel.d.ts +48 -0
  96. package/dist/sandbox/vercel.js +130 -0
  97. package/dist/session/index.d.ts +2 -0
  98. package/dist/session/index.js +6 -0
  99. package/dist/session/store.d.ts +28 -0
  100. package/dist/session/store.js +122 -0
  101. package/dist/session/types.d.ts +22 -0
  102. package/dist/session/types.js +2 -0
  103. package/dist/settings/index.d.ts +3 -0
  104. package/dist/settings/index.js +3 -0
  105. package/dist/settings/load.d.ts +20 -0
  106. package/dist/settings/load.js +36 -0
  107. package/dist/settings/merge.d.ts +13 -0
  108. package/dist/settings/merge.js +65 -0
  109. package/dist/settings/types.d.ts +17 -0
  110. package/dist/settings/types.js +3 -0
  111. package/dist/skills/index.d.ts +4 -0
  112. package/dist/skills/index.js +5 -0
  113. package/dist/skills/load.d.ts +23 -0
  114. package/dist/skills/load.js +54 -0
  115. package/dist/skills/parse.d.ts +7 -0
  116. package/dist/skills/parse.js +40 -0
  117. package/dist/skills/tool.d.ts +2 -0
  118. package/dist/skills/tool.js +39 -0
  119. package/dist/skills/types.d.ts +10 -0
  120. package/dist/skills/types.js +4 -0
  121. package/dist/team/dispatch.d.ts +2 -0
  122. package/dist/team/dispatch.js +41 -0
  123. package/dist/team/index.d.ts +9 -0
  124. package/dist/team/index.js +11 -0
  125. package/dist/team/mailbox.d.ts +24 -0
  126. package/dist/team/mailbox.js +33 -0
  127. package/dist/team/prompt.d.ts +1 -0
  128. package/dist/team/prompt.js +12 -0
  129. package/dist/team/runner.d.ts +20 -0
  130. package/dist/team/runner.js +45 -0
  131. package/dist/team/taskBoard.d.ts +41 -0
  132. package/dist/team/taskBoard.js +73 -0
  133. package/dist/team/tools.d.ts +7 -0
  134. package/dist/team/tools.js +190 -0
  135. package/dist/tools/bash.d.ts +2 -0
  136. package/dist/tools/bash.js +45 -0
  137. package/dist/tools/config.d.ts +2 -0
  138. package/dist/tools/config.js +44 -0
  139. package/dist/tools/define.d.ts +18 -0
  140. package/dist/tools/define.js +21 -0
  141. package/dist/tools/delete_file.d.ts +2 -0
  142. package/dist/tools/delete_file.js +33 -0
  143. package/dist/tools/edit_file.d.ts +2 -0
  144. package/dist/tools/edit_file.js +93 -0
  145. package/dist/tools/fileTypes.d.ts +32 -0
  146. package/dist/tools/fileTypes.js +166 -0
  147. package/dist/tools/glob.d.ts +2 -0
  148. package/dist/tools/glob.js +53 -0
  149. package/dist/tools/grep.d.ts +2 -0
  150. package/dist/tools/grep.js +110 -0
  151. package/dist/tools/imageProcessor.d.ts +15 -0
  152. package/dist/tools/imageProcessor.js +83 -0
  153. package/dist/tools/index.d.ts +28 -0
  154. package/dist/tools/index.js +45 -0
  155. package/dist/tools/list_files.d.ts +2 -0
  156. package/dist/tools/list_files.js +42 -0
  157. package/dist/tools/multi_edit.d.ts +2 -0
  158. package/dist/tools/multi_edit.js +112 -0
  159. package/dist/tools/notebook_edit.d.ts +2 -0
  160. package/dist/tools/notebook_edit.js +118 -0
  161. package/dist/tools/plan_mode.d.ts +4 -0
  162. package/dist/tools/plan_mode.js +44 -0
  163. package/dist/tools/read_file.d.ts +2 -0
  164. package/dist/tools/read_file.js +193 -0
  165. package/dist/tools/task.d.ts +2 -0
  166. package/dist/tools/task.js +77 -0
  167. package/dist/tools/todo_write.d.ts +2 -0
  168. package/dist/tools/todo_write.js +104 -0
  169. package/dist/tools/tool_search.d.ts +2 -0
  170. package/dist/tools/tool_search.js +49 -0
  171. package/dist/tools/types.d.ts +82 -0
  172. package/dist/tools/types.js +1 -0
  173. package/dist/tools/walk.d.ts +29 -0
  174. package/dist/tools/walk.js +82 -0
  175. package/dist/tools/web_fetch.d.ts +2 -0
  176. package/dist/tools/web_fetch.js +76 -0
  177. package/dist/tools/web_search.d.ts +22 -0
  178. package/dist/tools/web_search.js +195 -0
  179. package/dist/tools/write_file.d.ts +2 -0
  180. package/dist/tools/write_file.js +39 -0
  181. package/dist/types/index.d.ts +363 -0
  182. package/dist/types/index.js +9 -0
  183. package/dist/util/ids.d.ts +3 -0
  184. package/dist/util/ids.js +22 -0
  185. package/dist/util/paths.d.ts +16 -0
  186. package/dist/util/paths.js +72 -0
  187. package/dist/util/pricing.d.ts +15 -0
  188. package/dist/util/pricing.js +81 -0
  189. package/dist/workspace/index.d.ts +2 -0
  190. package/dist/workspace/index.js +2 -0
  191. package/dist/workspace/memory.d.ts +28 -0
  192. package/dist/workspace/memory.js +97 -0
  193. package/dist/workspace/webcontainer.d.ts +65 -0
  194. package/dist/workspace/webcontainer.js +156 -0
  195. package/package.json +78 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hans Ade
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,295 @@
1
+ # anyclaude-sdk
2
+
3
+ Claude Code agent capabilities — tools, the tool loop, multi-turn conversations —
4
+ running **entirely in the browser** via [WebContainer](https://webcontainers.io),
5
+ against **any OpenAI- or Anthropic-compatible LLM endpoint**. No backend, no OAuth,
6
+ no native binaries.
7
+
8
+ It exposes the same `query()` async-generator interface and the same `SDKMessage`
9
+ envelope as `@anthropic-ai/claude-agent-sdk`, so code written against the official
10
+ SDK can iterate our output unchanged.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install anyclaude-sdk @webcontainer/api
16
+ ```
17
+
18
+ `@webcontainer/api` is an optional peer dependency — only needed if you use
19
+ `WebContainerWorkspace`. You can supply your own `FileSystem`/`CommandExecutor`.
20
+
21
+ ## Quick start
22
+
23
+ ```typescript
24
+ import { WebContainer } from '@webcontainer/api'
25
+ import {
26
+ query,
27
+ WebContainerWorkspace,
28
+ createOpenAIClient,
29
+ ALL_CLAUDE_CODE_TOOLS,
30
+ } from 'anyclaude-sdk'
31
+
32
+ // 1. Boot a WebContainer and wrap it as a workspace.
33
+ const wc = await WebContainer.boot()
34
+ const workspace = new WebContainerWorkspace(wc)
35
+
36
+ // 2. Point at any OpenAI-compatible endpoint.
37
+ const llm = createOpenAIClient({
38
+ apiKey: import.meta.env.VITE_OPENAI_API_KEY,
39
+ baseUrl: 'https://api.openai.com/v1', // or Groq, Together, OpenRouter, local…
40
+ model: 'gpt-4o',
41
+ })
42
+
43
+ // 3. Run the agent — same shape as the official SDK.
44
+ for await (const msg of query({ prompt: 'List the files and summarize the project', workspace, llm })) {
45
+ if (msg.type === 'assistant') {
46
+ for (const block of msg.message.content) {
47
+ if (block.type === 'text') console.log(block.text)
48
+ }
49
+ } else if (msg.type === 'result' && msg.subtype === 'success') {
50
+ console.log('Done:', msg.result)
51
+ }
52
+ }
53
+ ```
54
+
55
+ ### MCP servers (external + in-process)
56
+
57
+ Connect external MCP servers or define in-process tools. Because browsers block
58
+ direct cross-origin MCP fetches (CORS), pass a `mcpProxy` for remote servers:
59
+
60
+ ```typescript
61
+ import { createSdkMcpServer, tool } from 'anyclaude-sdk'
62
+
63
+ const calc = createSdkMcpServer({
64
+ name: 'calc',
65
+ tools: [tool('add', 'Add two numbers',
66
+ { type: 'object', properties: { a: { type: 'number' }, b: { type: 'number' } }, required: ['a', 'b'] },
67
+ (args) => ({ content: [{ type: 'text', text: String(args.a + args.b) }] }))],
68
+ })
69
+
70
+ query({
71
+ prompt, workspace, llm,
72
+ mcpServers: {
73
+ calc, // in-process, no network
74
+ docs: { type: 'http', url: 'https://mcp.example.com' }, // remote
75
+ },
76
+ // Route remote MCP through a CORS proxy (function, `{url}`/`{rawUrl}` template, or bare prefix):
77
+ mcpProxy: 'https://my-proxy.example/?url={url}',
78
+ })
79
+ ```
80
+
81
+ Remote tools are exposed as `mcp__<server>__<tool>`.
82
+
83
+ ### Providers
84
+
85
+ Three transport clients, all implementing the same `LLMClient` interface:
86
+
87
+ ```typescript
88
+ import { createOpenAIClient, createAnthropicClient, createResponsesClient } from 'anyclaude-sdk'
89
+
90
+ // OpenAI-compatible Chat Completions (OpenAI, Groq, Together, OpenRouter, xAI, Kilo, local…)
91
+ const a = createOpenAIClient({ apiKey, baseUrl: 'https://api.x.ai/v1', model: 'grok-build-0.1' })
92
+
93
+ // Anthropic Messages API
94
+ const b = createAnthropicClient({ apiKey, model: 'claude-sonnet-4-6' })
95
+
96
+ // OpenAI Responses API (POST /v1/responses)
97
+ const c = createResponsesClient({ apiKey, model: 'gpt-4o' })
98
+ ```
99
+
100
+ All three normalize tool calls, streaming, and usage to the same `StreamResult`,
101
+ and include a fallback parser for models that emit tool calls as inline text.
102
+
103
+ ## Multi-turn / interactive sessions
104
+
105
+ Use a `PromptStream` to push user turns over time:
106
+
107
+ ```typescript
108
+ import { query, PromptStream } from 'anyclaude-sdk'
109
+
110
+ const prompts = new PromptStream()
111
+ const session = query({ prompt: prompts, workspace, llm, model: 'gpt-4o' })
112
+
113
+ prompts.push('Create a hello.txt with a greeting')
114
+ // …later, based on UI input:
115
+ prompts.push('Now translate it to French')
116
+ prompts.end() // close the conversation
117
+
118
+ for await (const msg of session) {
119
+ // render msg…
120
+ }
121
+ ```
122
+
123
+ ## Tools
124
+
125
+ `ALL_CLAUDE_CODE_TOOLS` includes:
126
+
127
+ | Tool | Purpose |
128
+ |------|---------|
129
+ | `bash` | Run shell commands via jsh (`2>&1`/`/dev/null` redirects are stripped) |
130
+ | `read_file` | Read text (numbered lines, offset/limit), **images** (auto-downsampled base64), **PDFs** (document block), and **notebooks** (`.ipynb` cells + outputs); binary files are rejected with guidance |
131
+ | `write_file` | Write a file, creating parent dirs |
132
+ | `edit_file` | Exact-match string replace (requires a prior read) |
133
+ | `multi_edit` | Apply a sequence of edits to one file atomically |
134
+ | `notebook_edit` | Replace/insert/delete cells in a `.ipynb` |
135
+ | `delete_file` | Remove a file/dir |
136
+ | `glob` | Find files by glob pattern (`**`, `*`, `?`) |
137
+ | `grep` | Regex search across files |
138
+ | `list_files` | List a directory |
139
+ | `todo_write` | Track a multi-step task list across turns |
140
+ | `web_fetch` | Fetch a URL → clean Markdown via the Jina Reader (CORS-free, JS-rendered) |
141
+ | `web_search` | Web search via Jina + DuckDuckGo HTML; returns top-N title/URL/snippet |
142
+
143
+ ### File reading: images, PDFs, notebooks
144
+
145
+ `read_file` dispatches by file type. Image and PDF bytes are forwarded to the
146
+ model automatically as a follow-up user turn (Anthropic gets native
147
+ `image`/`document` blocks; OpenAI-compatible endpoints get `image_url`/`file`
148
+ parts), so the model can actually *see* the file, not just a text summary.
149
+ Tune the caps via `limits`:
150
+
151
+ ```typescript
152
+ query({ prompt, workspace, llm, limits: { maxTokens: 25000, maxImageBytes: 3_750_000, maxPdfPages: 20 } })
153
+ ```
154
+
155
+ Pass a subset, or your own `Tool[]`, via `tools:`:
156
+
157
+ ```typescript
158
+ import { readFile, writeFile, editFile } from 'anyclaude-sdk'
159
+
160
+ query({ prompt, workspace, llm, tools: [readFile, writeFile, editFile] })
161
+ ```
162
+
163
+ ## Slash commands
164
+
165
+ A user turn beginning with `/` is intercepted. Built-ins: `/help`, `/clear`,
166
+ `/compact [focus]` (summarizes history to free context), `/tools`, `/cost`,
167
+ `/model`. Define your own prompt-template commands:
168
+
169
+ ```typescript
170
+ import { query, promptCommand } from 'anyclaude-sdk'
171
+
172
+ query({
173
+ prompt: promptStream, workspace, llm,
174
+ commands: [promptCommand('review', 'Review the diff', 'Review this code and list issues: $ARGUMENTS')],
175
+ })
176
+ // user types: /review src/app.ts
177
+ ```
178
+
179
+ ## Background tasks
180
+
181
+ Enable with `background: true` to run sub-agents or long work off the critical
182
+ path. The `task` tool gains `run_in_background` (returns a task id immediately),
183
+ and `task_list` / `task_output` / `task_stop` tools let the agent poll them.
184
+ Optional off-main-thread execution via a Comlink worker harness
185
+ (`exposeBackgroundWorker` / `wrapWorker`); the in-thread manager works without it.
186
+
187
+ ```typescript
188
+ query({ prompt, workspace, llm, agents: {}, background: true })
189
+ ```
190
+
191
+ ## Pluggable backends
192
+
193
+ You aren't tied to WebContainer. A `Sandbox` is just a `FileSystem` plus a
194
+ `CommandExecutor`, and you can mix and match.
195
+
196
+ ### Any sandbox provider
197
+
198
+ Adapters wrap each provider's client structurally (no hard dependency on their
199
+ SDKs — install only the one you use):
200
+
201
+ ```typescript
202
+ import { E2BSandbox, VercelSandbox, DaytonaSandbox, CloudflareSandbox } from 'anyclaude-sdk'
203
+
204
+ // e.g. E2B
205
+ import { Sandbox } from 'e2b'
206
+ const sbx = await Sandbox.create()
207
+ const workspace = new E2BSandbox(sbx)
208
+
209
+ query({ prompt, workspace, llm })
210
+ ```
211
+
212
+ Supported: **WebContainer**, **E2B**, **Vercel Sandbox**, **Daytona**,
213
+ **Cloudflare Sandbox**, and **LocalSandbox** (real OS). All implement the same
214
+ `Sandbox` interface.
215
+
216
+ ### Local real-OS sandbox (Node)
217
+
218
+ Run the agent directly against the host machine's filesystem and shell — like
219
+ Claude Code — with automatic platform detection (Windows / macOS / Linux):
220
+
221
+ ```typescript
222
+ import { LocalSandbox, createAnthropicClient, query } from 'anyclaude-sdk'
223
+
224
+ const workspace = new LocalSandbox({ cwd: '/path/to/project' }) // defaults to process.cwd()
225
+ const llm = createAnthropicClient({ baseUrl, model: 'claude-sonnet-4-6', apiKey })
226
+
227
+ for await (const msg of query({ prompt: 'add a CLI flag and run the tests', workspace, llm })) { /* … */ }
228
+ ```
229
+
230
+ The agent's working directory is taken from the sandbox automatically. See
231
+ `examples/local-agent.mjs` for a runnable headless demo. On Windows it uses
232
+ `cmd.exe`; elsewhere `$SHELL`/`/bin/sh` (override via `shell`/`shellArgs`).
233
+
234
+ ### Persistent, full Linux-style filesystem (no server)
235
+
236
+ For a durable local filesystem in the browser, use a DB-backed FS and seed a
237
+ standard Linux tree. `DexieFileSystem` (IndexedDB) is the recommended default
238
+ — persistent across reloads, indexed for fast `readdir`/`glob`, with metadata
239
+ (mode, mtime, symlinks):
240
+
241
+ ```typescript
242
+ import {
243
+ DexieFileSystem, OpfsFileSystem, seedLinuxTree, composeWorkspace, NoopCommandExecutor,
244
+ } from 'anyclaude-sdk'
245
+
246
+ const fs = new DexieFileSystem('my-project-fs') // or: new OpfsFileSystem()
247
+ await seedLinuxTree(fs) // /bin /etc /home/user /tmp /usr …
248
+
249
+ // File-only agent (no shell):
250
+ const workspace = composeWorkspace(fs, new NoopCommandExecutor(), '/home/user')
251
+
252
+ // …or pair a persistent FS with a remote shell:
253
+ // const workspace = composeWorkspace(fs, new E2BSandbox(sbx), '/home/user')
254
+ ```
255
+
256
+ `OpfsFileSystem` (Origin Private File System) is offered alongside Dexie for
257
+ large-binary / native-handle scenarios; use `OpfsFileSystem.isSupported()` to
258
+ feature-detect.
259
+
260
+ A `MemoryFileSystem` also ships for tests:
261
+
262
+ ```typescript
263
+ import { MemoryFileSystem, NoopCommandExecutor, composeWorkspace } from 'anyclaude-sdk'
264
+
265
+ const fs = new MemoryFileSystem()
266
+ await fs.writeFile('/app/index.ts', 'export const x = 1')
267
+ const workspace = composeWorkspace(fs, new NoopCommandExecutor())
268
+ ```
269
+
270
+ ## API
271
+
272
+ - `query(options): AsyncGenerator<SDKMessage>` — main entry.
273
+ - `prompt: string | AsyncIterable<SDKUserMessage>`
274
+ - `workspace: FileSystem & CommandExecutor`
275
+ - `llm: LLMClient`
276
+ - `tools?`, `model?`, `systemPrompt?`, `maxTurns?` (default 50), `cwd?`, `abortController?`
277
+ - `createOpenAIClient(options): LLMClient`
278
+ - `createAnthropicClient(options): LLMClient`
279
+ - `WebContainerWorkspace`, `MemoryFileSystem`, `NoopCommandExecutor`
280
+ - `ALL_CLAUDE_CODE_TOOLS`, individual tools, `toolDefs`, `toolByName`
281
+ - All `SDK*` message types, `ContentBlockParam`, `LLMClient`, `ToolDef`, etc.
282
+
283
+ ## Differences from the official SDK
284
+
285
+ | Feature | Official SDK | anyclaude-sdk |
286
+ |---------|-------------|--------------------|
287
+ | Auth | OAuth token | None required |
288
+ | Backend | claude.ai API | Any OpenAI/Anthropic endpoint |
289
+ | File ops | Native filesystem | WebContainer fs (pluggable) |
290
+ | Commands | Native shell | jsh (WebContainer) |
291
+ | MCP / slash commands / background tasks | Built-in | Not included |
292
+
293
+ ## License
294
+
295
+ MIT
@@ -0,0 +1,110 @@
1
+ import type { AgentDefinition, CanUseTool, CommandExecutor, FileSystem, HookCallback, HookEvent, PermissionMode, SDKMessage, SDKUserMessage } from './types/index.js';
2
+ import type { FileReadLimits, Tool } from './tools/types.js';
3
+ import { type McpServers, type McpProxy } from './mcp/index.js';
4
+ import type { SlashCommand } from './commands/index.js';
5
+ import { BackgroundTaskManager } from './background/index.js';
6
+ import { Mailbox, TaskBoard } from './team/index.js';
7
+ import type { MemoryStore } from './memory/index.js';
8
+ import type { SessionStore } from './session/index.js';
9
+ import { type Settings } from './settings/index.js';
10
+ import { type Skill } from './skills/index.js';
11
+ export type Workspace = FileSystem & CommandExecutor;
12
+ export interface AgentOptions {
13
+ prompt: AsyncIterable<SDKUserMessage>;
14
+ workspace: Workspace;
15
+ llm: LLMClientLike;
16
+ /** Full tool set — REPLACES the builtins. Omit to keep the defaults. */
17
+ tools?: Tool[];
18
+ /** Custom tools ADDED to the builtins (or to `tools` if given). Use `defineTool`. */
19
+ extraTools?: Tool[];
20
+ model?: string;
21
+ /** Full system prompt. If omitted, the default Claude Code prompt is used. */
22
+ systemPrompt?: string;
23
+ /** Text appended after the (default or custom) system prompt. */
24
+ appendSystemPrompt?: string;
25
+ /** Allowlist of tool names. When set, only these tools are exposed. */
26
+ allowedTools?: string[];
27
+ /** Denylist of tool names, applied after allowedTools. */
28
+ disallowedTools?: string[];
29
+ maxTurns?: number;
30
+ cwd?: string;
31
+ sessionId?: string;
32
+ abortController?: AbortController;
33
+ /** Permission gate invoked before each tool call. */
34
+ canUseTool?: CanUseTool;
35
+ permissionMode?: PermissionMode;
36
+ /** Lifecycle hooks keyed by event. */
37
+ hooks?: Partial<Record<HookEvent, HookCallback[]>>;
38
+ /** File-read tuning passed through to tools. */
39
+ limits?: Partial<FileReadLimits>;
40
+ /**
41
+ * Spill oversized tool results to a file and hand the model a preview + path
42
+ * instead of the full text (keeps huge outputs out of context). Default: true.
43
+ */
44
+ persistLargeResults?: boolean;
45
+ /** Char threshold before a tool result spills to disk. Default 50,000. */
46
+ maxToolResultChars?: number;
47
+ /**
48
+ * Custom sub-agents invokable via the `task` tool, keyed by agent type name.
49
+ * When provided, the `task` tool is auto-registered.
50
+ */
51
+ agents?: Record<string, AgentDefinition>;
52
+ /** Internal: current sub-agent nesting depth. */
53
+ subagentDepth?: number;
54
+ /** Max sub-agent nesting depth (prevents runaway recursion). Default 2. */
55
+ maxSubagentDepth?: number;
56
+ /** External MCP servers (HTTP/SSE) or in-process SDK servers to load tools from. */
57
+ mcpServers?: McpServers;
58
+ /** Route remote MCP requests through a proxy (works around browser CORS). */
59
+ mcpProxy?: McpProxy;
60
+ /** Custom slash commands (merged with built-ins like /help, /compact). */
61
+ commands?: SlashCommand[];
62
+ /** Enable background tasks (task_list/task_output/task_stop + task run_in_background). */
63
+ background?: boolean;
64
+ /** Inject a shared BackgroundTaskManager so tasks persist across turns. */
65
+ backgroundManager?: BackgroundTaskManager;
66
+ /** Queue for interjecting user messages into the live loop (delivered one per turn boundary). */
67
+ messageQueue?: import('./queue.js').MessageQueue;
68
+ /** Emit `stream_event` partial-assistant messages (text deltas) as they arrive. */
69
+ includePartialMessages?: boolean;
70
+ /** Enable teammate coordination: shared mailbox + task board, team tools, coordinator prompt. */
71
+ team?: boolean;
72
+ /** Internal: shared Mailbox passed down to sub-agents (set automatically). */
73
+ mailbox?: Mailbox;
74
+ /** Internal: shared TaskBoard passed down to sub-agents (set automatically). */
75
+ board?: TaskBoard;
76
+ /** This agent's name/label for messaging (default 'coordinator'). */
77
+ agentName?: string;
78
+ /** Persist the transcript to this store (keyed by sessionId) for resume. */
79
+ sessionStore?: SessionStore;
80
+ /** Load the stored transcript for sessionId before the first turn. */
81
+ resume?: boolean;
82
+ /** Auto-compact the transcript when it approaches the context limit. */
83
+ autoCompact?: boolean;
84
+ /** Context window in tokens for auto-compaction. Default: model's window or 200k. */
85
+ contextLimit?: number;
86
+ /** Fraction of the context limit that triggers compaction. Default 0.8. */
87
+ compactThreshold?: number;
88
+ /** Persistent memory store; entries are loaded into the system prompt and editable via memory tools. */
89
+ memory?: MemoryStore;
90
+ /** Permission rules (allow/deny/ask rule strings); builds a canUseTool gate. */
91
+ permissionRules?: {
92
+ allow?: string[];
93
+ deny?: string[];
94
+ ask?: string[];
95
+ };
96
+ /** Prompt callback for 'ask' decisions; if absent, default mode allows / dontAsk denies. */
97
+ onPermissionAsk?: (toolName: string, input: Record<string, unknown>) => Promise<boolean>;
98
+ /** Load + apply `.claude/settings.json` (project/local cascade) under explicit options. true, or a Settings object. */
99
+ settings?: boolean | Settings;
100
+ /** Load `.claude/skills/*.md` as slash commands + skill registry. true, or a Skill[] array. */
101
+ skills?: boolean | Skill[];
102
+ }
103
+ type LLMClientLike = import('./types/index.js').LLMClient;
104
+ /**
105
+ * The core agent loop. Yields faithful SDKMessages as the conversation
106
+ * progresses: an init system message, assistant turns, synthetic user turns
107
+ * carrying tool_results, and a final result message per user prompt.
108
+ */
109
+ export declare function runAgent(options: AgentOptions): AsyncGenerator<SDKMessage>;
110
+ export {};