@go-hare/claude-agent-sdk 0.3.177

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.md ADDED
@@ -0,0 +1 @@
1
+ © Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Claude Agent SDK
2
+
3
+ ![](https://img.shields.io/badge/Node.js-18%2B-brightgreen?style=flat-square) [![npm]](https://www.npmjs.com/package/@go-hare/claude-agent-sdk)
4
+
5
+ [npm]: https://img.shields.io/npm/v/@go-hare/claude-agent-sdk.svg?style=flat-square
6
+
7
+ The Claude Agent SDK enables you to programmatically build AI agents with Claude Code's capabilities. Create autonomous agents that can understand codebases, edit files, run commands, and execute complex workflows.
8
+
9
+ **Learn more in the [official documentation](https://platform.claude.com/docs/en/agent-sdk/overview)**.
10
+
11
+ ## Get started
12
+
13
+ Install the Claude Agent SDK:
14
+
15
+ ```sh
16
+ npm install @go-hare/claude-agent-sdk
17
+ ```
18
+
19
+ ## Compiled binaries (`bun build --compile`)
20
+
21
+ When bundling your application into a single executable with `bun build --compile`, the SDK cannot resolve the native CLI binary at runtime — `require.resolve` doesn't work from inside the compiled `$bunfs` (or `B:\~BUN\...` on Windows) virtual filesystem.
22
+
23
+ Embed the platform-specific binary as a file asset, extract it to a real path, and pass it explicitly:
24
+
25
+ ```js
26
+ import binPath from '@go-hare/claude-code-darwin-arm64/claude' with { type: 'file' }
27
+ import { extractFromBunfs } from '@go-hare/claude-agent-sdk/extract'
28
+ import { query } from '@go-hare/claude-agent-sdk'
29
+
30
+ const cliPath = extractFromBunfs(binPath)
31
+
32
+ for await (const message of query({
33
+ prompt: '…',
34
+ options: { pathToClaudeCodeExecutable: cliPath },
35
+ })) { /* … */ }
36
+ ```
37
+
38
+ Each compiled executable embeds one platform's binary, matching your `--target`. Cross-compiling requires installing the non-matching platform package (e.g. `npm install @go-hare/claude-code-linux-x64 --force`). On Windows the binary subpath is `/claude.exe` (e.g. `@go-hare/claude-code-win32-x64/claude.exe`).
39
+
40
+ ## Migrating from the Claude Code SDK
41
+
42
+ The Claude Code SDK is now the Claude Agent SDK. Please check out the [migration guide](https://platform.claude.com/docs/en/agent-sdk/migration-guide) for details on breaking changes.
43
+
44
+ ## Reporting Bugs
45
+
46
+ We welcome your feedback. File a [GitHub issue](https://github.com/go-hare/claude-agent-sdk-typescript/issues) to report bugs or request features.
47
+
48
+ ## Connect on Discord
49
+
50
+ Join the [Claude Developers Discord](https://anthropic.com/discord) to connect with other developers building with the Claude Agent SDK. Get help, share feedback, and discuss your projects with the community.
51
+
52
+ ## Data collection, usage, and retention
53
+
54
+ When you use the Claude Agent SDK, we collect feedback, which includes usage data (such as code acceptance or rejections), associated conversation data, and user feedback submitted via the /bug command.
55
+
56
+ ### How we use your data
57
+
58
+ See our [data usage policies](https://docs.anthropic.com/en/docs/claude-code/data-usage).
59
+
60
+ ### Privacy safeguards
61
+
62
+ We have implemented several safeguards to protect your data, including limited retention periods for sensitive information and restricted access to user session data.
63
+
64
+ For full details, please review our [Commercial Terms of Service](https://www.anthropic.com/legal/commercial-terms) and [Privacy Policy](https://www.anthropic.com/legal/privacy).
@@ -0,0 +1 @@
1
+ export * from './sdk.js'
package/assistant.d.ts ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * API surface definition for @anthropic-ai/claude-agent-sdk/assistant.
3
+ *
4
+ * Source of truth for the /assistant export's public types. Imports ONLY
5
+ * from agentSdkTypes.ts so the compiled .d.ts has exactly one import to
6
+ * rewrite (./agentSdkTypes → ./sdk) for the flat package layout.
7
+ *
8
+ * Compiled by scripts/build-ant-sdk-typings.sh; runtime in
9
+ * agentSdkAssistant.ts (bun-built to assistant.mjs).
10
+ *
11
+ * Type definitions below are copied from src/assistant/worker.ts and
12
+ * src/assistant/daemonBridge.ts. Keep in sync — those are the
13
+ * implementation source of truth.
14
+ */
15
+ import type { CanUseTool, ConnectRemoteControlOptions, InboundPrompt, Options, PermissionResult, SDKMessage, SDKUserMessage } from './agentSdkTypes.js';
16
+ export type { ConnectRemoteControlOptions, InboundPrompt };
17
+ /**
18
+ * Worker-persisted state. Checkpointed on turn boundaries, bridge
19
+ * reconnects, and teardown.
20
+ * @alpha
21
+ */
22
+ export type WorkerState = {
23
+ claudeSessionId?: string;
24
+ lastSSESequenceNum?: number;
25
+ bridgeSessionId?: string;
26
+ };
27
+ /** @alpha */
28
+ export type WorkerStateAdapter = {
29
+ load(): Promise<WorkerState | null>;
30
+ save(state: WorkerState): Promise<void>;
31
+ };
32
+ /**
33
+ * Third argument to the SDK's CanUseTool callback.
34
+ * @alpha
35
+ */
36
+ export type CanUseToolContext = Parameters<CanUseTool>[2];
37
+ /**
38
+ * Structured failure from `runAssistantWorker`. `kind` lets callers branch
39
+ * on handling — conflict UI, retry with backoff, or bail.
40
+ * @alpha
41
+ */
42
+ export type AssistantWorkerError = {
43
+ kind: 'conflict' | 'auth' | 'network' | 'unknown';
44
+ detail: string;
45
+ };
46
+ /** @alpha */
47
+ export type AssistantWorkerResult = {
48
+ ok: true;
49
+ handle: AssistantWorkerHandle;
50
+ } | {
51
+ ok: false;
52
+ error: AssistantWorkerError;
53
+ };
54
+ /** @alpha */
55
+ export type AssistantWorkerOptions = {
56
+ /**
57
+ * Bridge connection config — passed through to `connectRemoteControl`.
58
+ * `initialSSESequenceNum` is seeded from `stateAdapter.load()` if unset.
59
+ */
60
+ bridge: ConnectRemoteControlOptions;
61
+ /**
62
+ * Runs in a sandbox (VM, container) where the sandbox boundary IS the
63
+ * trust boundary. Injects `CLAUDE_CODE_SANDBOXED=1` so the CLI's
64
+ * directory trust check passes. Default false.
65
+ */
66
+ sandboxed?: boolean;
67
+ /**
68
+ * Cron-horizon polling. Worker reads `<dir>/.claude/scheduled_tasks.json`
69
+ * every 10s and spawns the child ~5s before a fire is due. Omit to
70
+ * disable cron-driven spawn.
71
+ */
72
+ scheduling?: {
73
+ dir: string;
74
+ horizonMs?: number;
75
+ leadMs?: number;
76
+ };
77
+ /**
78
+ * Called each time the worker spawns query(). `base` carries
79
+ * `assistant:true`, `cwd`, `resume`, `stderr`, and the worker's
80
+ * bridge-wired `canUseTool`. Spread over `base` to add MCP servers,
81
+ * VM spawn, env vars, system prompt, tool lists.
82
+ *
83
+ * May be async — dispatch awaits VM spawn, system prompt build, and
84
+ * OAuth token fetch before each query() spawn.
85
+ */
86
+ buildQueryOptions: (base: Options) => Options | Promise<Options>;
87
+ /**
88
+ * Called BEFORE the bridge permission prompt. Return a PermissionResult
89
+ * to short-circuit; undefined to fall through to the bridge.
90
+ */
91
+ canUseToolPreFilter?: (toolName: string, input: Record<string, unknown>, ctx: CanUseToolContext) => Promise<PermissionResult | undefined>;
92
+ /**
93
+ * Called AFTER the bridge resolves (or pre-filter short-circuits).
94
+ * Lets callers persist "always allow" to their own cache.
95
+ */
96
+ onPermissionResolved?: (toolName: string, result: PermissionResult) => void;
97
+ /**
98
+ * Applied to every SDKMessage after the worker's own filter, before
99
+ * bridge write. Return null to drop. Used for VM→host path translation.
100
+ */
101
+ transformOutbound?: (msg: SDKMessage) => SDKMessage | null;
102
+ /**
103
+ * Where to persist WorkerState. Omit to run stateless — fresh
104
+ * claudeSessionId and SSE seq on every restart.
105
+ */
106
+ stateAdapter?: WorkerStateAdapter;
107
+ /**
108
+ * Pushed into the input queue at worker start. Daemon passes install.md
109
+ * on first-run; dispatch passes seed messages or omits.
110
+ */
111
+ initialPrompt?: string;
112
+ /** Despawn child after this much quiet. Default 5 minutes. */
113
+ userIdleMs?: number;
114
+ signal: AbortSignal;
115
+ log?: (msg: string) => void;
116
+ };
117
+ /** @alpha */
118
+ export type AssistantWorkerHandle = {
119
+ readonly sessionUrl: string;
120
+ readonly bridgeSessionId: string;
121
+ readonly claudeSessionId: string | undefined;
122
+ /** Push a prompt into the input queue without going through the bridge. */
123
+ pushPrompt(content: string | SDKUserMessage['message']['content']): void;
124
+ interrupt(): Promise<void>;
125
+ /** Resolves when the fan-in loop exits and teardown completes. */
126
+ done: Promise<void>;
127
+ teardown(): Promise<void>;
128
+ };
129
+ /**
130
+ * Run a single-session assistant worker: connect to the claude.ai bridge,
131
+ * spawn query() on demand (inbound prompt or cron due), proxy permissions
132
+ * through the bridge, despawn on idle.
133
+ * @alpha
134
+ */
135
+ export declare function runAssistantWorker(opts: AssistantWorkerOptions): Promise<AssistantWorkerResult>;