@sudocode-ai/claude-code-acp 0.12.9 → 0.13.1

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Use [Claude Code](https://www.anthropic.com/claude-code) from [ACP-compatible](https://agentclientprotocol.com) clients such as [Zed](https://zed.dev)!
6
6
 
7
- This tool implements an ACP agent by using the official [Claude Code SDK](https://docs.anthropic.com/en/docs/claude-code/sdk/sdk-overview), supporting:
7
+ This tool implements an ACP agent by using the official [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview), supporting:
8
8
 
9
9
  - Context @-mentions
10
10
  - Images
@@ -32,20 +32,14 @@ Read the docs on [External Agent](https://zed.dev/docs/ai/external-agents) suppo
32
32
 
33
33
  ### Other clients
34
34
 
35
- - Emacs via [agent-shell.el](https://github.com/xenodium/agent-shell)
36
- - [marimo notebook](https://github.com/marimo-team/marimo)
37
- - Neovim
38
- - via [CodeCompanion.nvim](https://codecompanion.olimorris.dev/configuration/adapters#setup-claude-code-via-acp)
39
- - via [yetone/avante.nvim](https://github.com/yetone/avante.nvim)
40
-
41
- [Submit a PR](https://github.com/zed-industries/claude-code-acp/pulls) to add yours!
35
+ Or try it with any of the other [ACP compatible clients](https://agentclientprotocol.com/overview/clients)!
42
36
 
43
37
  #### Installation
44
38
 
45
39
  Install the adapter from `npm`:
46
40
 
47
41
  ```bash
48
- npm install @zed-industries/claude-code-acp
42
+ npm install -g @zed-industries/claude-code-acp
49
43
  ```
50
44
 
51
45
  You can then use `claude-code-acp` as a regular ACP agent:
@@ -0,0 +1,194 @@
1
+ import { Agent, AgentSideConnection, AuthenticateRequest, CancelNotification, ClientCapabilities, ForkSessionRequest, ForkSessionResponse, InitializeRequest, InitializeResponse, LoadSessionRequest, LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, SessionNotification, SetSessionModelRequest, SetSessionModelResponse, SetSessionModeRequest, SetSessionModeResponse, TerminalHandle, TerminalOutputResponse, WriteTextFileRequest, WriteTextFileResponse } from "@agentclientprotocol/sdk";
2
+ import { SettingsManager } from "./settings.js";
3
+ import { CanUseTool, Options, PermissionMode, Query, SDKPartialAssistantMessage, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
4
+ import { Pushable } from "./utils.js";
5
+ import { ContentBlockParam } from "@anthropic-ai/sdk/resources";
6
+ import { BetaContentBlock, BetaRawContentBlockDelta } from "@anthropic-ai/sdk/resources/beta.mjs";
7
+ export declare const CLAUDE_CONFIG_DIR: string;
8
+ /**
9
+ * Logger interface for customizing logging output
10
+ */
11
+ export interface Logger {
12
+ log: (...args: any[]) => void;
13
+ error: (...args: any[]) => void;
14
+ }
15
+ type Session = {
16
+ query: Query;
17
+ input: Pushable<SDKUserMessage>;
18
+ cancelled: boolean;
19
+ permissionMode: PermissionMode;
20
+ settingsManager: SettingsManager;
21
+ abortController: AbortController;
22
+ cwd: string;
23
+ /** Optional: the actual session file path (for forked sessions where filename differs from sessionId) */
24
+ sessionFilePath?: string;
25
+ };
26
+ type BackgroundTerminal = {
27
+ handle: TerminalHandle;
28
+ status: "started";
29
+ lastOutput: TerminalOutputResponse | null;
30
+ } | {
31
+ status: "aborted" | "exited" | "killed" | "timedOut";
32
+ pendingOutput: TerminalOutputResponse;
33
+ };
34
+ /**
35
+ * Extra metadata that can be given to Claude Code when creating a new session.
36
+ */
37
+ export type NewSessionMeta = {
38
+ claudeCode?: {
39
+ /**
40
+ * Options forwarded to Claude Code when starting a new session.
41
+ * Those parameters will be ignored and managed by ACP:
42
+ * - cwd
43
+ * - includePartialMessages
44
+ * - allowDangerouslySkipPermissions
45
+ * - permissionMode
46
+ * - canUseTool
47
+ * - executable
48
+ * Those parameters will be used and updated to work with ACP:
49
+ * - hooks (merged with ACP's hooks)
50
+ * - mcpServers (merged with ACP's mcpServers)
51
+ */
52
+ options?: Options;
53
+ };
54
+ };
55
+ /**
56
+ * Extra metadata that the agent provides for each tool_call / tool_update update.
57
+ */
58
+ export type ToolUpdateMeta = {
59
+ claudeCode?: {
60
+ toolName: string;
61
+ toolResponse?: unknown;
62
+ };
63
+ };
64
+ type ToolUseCache = {
65
+ [key: string]: {
66
+ type: "tool_use" | "server_tool_use" | "mcp_tool_use";
67
+ id: string;
68
+ name: string;
69
+ input: any;
70
+ };
71
+ };
72
+ export declare class ClaudeAcpAgent implements Agent {
73
+ sessions: {
74
+ [key: string]: Session;
75
+ };
76
+ client: AgentSideConnection;
77
+ toolUseCache: ToolUseCache;
78
+ backgroundTerminals: {
79
+ [key: string]: BackgroundTerminal;
80
+ };
81
+ clientCapabilities?: ClientCapabilities;
82
+ logger: Logger;
83
+ constructor(client: AgentSideConnection, logger?: Logger);
84
+ initialize(request: InitializeRequest): Promise<InitializeResponse>;
85
+ newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
86
+ /**
87
+ * Fork an existing session to create a new independent session.
88
+ * This is the ACP protocol method handler for session/fork.
89
+ * Named unstable_forkSession to match SDK expectations (session/fork routes to this method).
90
+ */
91
+ unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse>;
92
+ /**
93
+ * Get the directory where session files are stored for a given cwd.
94
+ */
95
+ private getSessionDirPath;
96
+ /**
97
+ * Extract the internal sessionId from a session JSONL file.
98
+ * The CLI stores the actual session ID inside the file, which may differ from the filename.
99
+ * For forked sessions, the filename is "agent-xxx" but the internal sessionId is a UUID.
100
+ */
101
+ private extractInternalSessionId;
102
+ /**
103
+ * Promote a sidechain session to a regular session by modifying the session file.
104
+ * Forked sessions have "isSidechain": true which prevents them from being resumed.
105
+ * This method changes it to false so the session can be resumed/forked again.
106
+ */
107
+ private promoteToFullSession;
108
+ /**
109
+ * Update the sessionId in all lines of a session JSONL file.
110
+ * This is used when we need to assign a new unique session ID to avoid collisions.
111
+ */
112
+ private updateSessionIdInFile;
113
+ /**
114
+ * Discover the CLI-assigned session ID by looking for new session files.
115
+ * Returns the CLI's session ID if found, or the original sessionId if not.
116
+ */
117
+ private discoverCliSessionId;
118
+ /**
119
+ * Alias for unstable_forkSession for convenience.
120
+ */
121
+ forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse>;
122
+ /**
123
+ * Load an existing session to resume a previous conversation.
124
+ * This is the ACP protocol method handler for session/load.
125
+ */
126
+ loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse>;
127
+ /**
128
+ * @deprecated Use loadSession instead. This is kept for backward compatibility.
129
+ */
130
+ unstable_resumeSession(params: {
131
+ sessionId: string;
132
+ _meta?: {
133
+ cwd?: string;
134
+ mcpServers?: any[];
135
+ [key: string]: unknown;
136
+ } | null;
137
+ }): Promise<LoadSessionResponse>;
138
+ authenticate(_params: AuthenticateRequest): Promise<void>;
139
+ prompt(params: PromptRequest): Promise<PromptResponse>;
140
+ cancel(params: CancelNotification): Promise<void>;
141
+ /**
142
+ * Handle extension methods from the client.
143
+ *
144
+ * Currently supports:
145
+ * - `_session/flush`: Flush a session to disk for fork-with-flush support
146
+ */
147
+ extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
148
+ /**
149
+ * Flush a session to disk by aborting its query subprocess.
150
+ *
151
+ * This is used by the fork-with-flush mechanism to ensure session data
152
+ * is persisted to disk before forking. When the Claude SDK subprocess
153
+ * exits (via abort), it writes the session data to:
154
+ * ~/.claude/projects/<cwd-hash>/<sessionId>.jsonl
155
+ *
156
+ * After this method completes, the session is removed from memory and
157
+ * must be reloaded via loadSession() to continue using it.
158
+ */
159
+ private handleSessionFlush;
160
+ /**
161
+ * Get the file path where Claude Code stores session data.
162
+ *
163
+ * Claude Code stores sessions at:
164
+ * ~/.claude/projects/<cwd-hash>/<sessionId>.jsonl
165
+ *
166
+ * Where <cwd-hash> is the cwd with `/` replaced by `-`
167
+ * Note: We resolve the real path to handle macOS symlinks like /var -> /private/var
168
+ */
169
+ private getSessionFilePath;
170
+ /**
171
+ * Wait for a session file to appear on disk.
172
+ *
173
+ * @param filePath - Path to the session file
174
+ * @param timeout - Maximum time to wait in milliseconds
175
+ * @returns true if file appears, false if timeout
176
+ */
177
+ private waitForSessionFile;
178
+ unstable_setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse | void>;
179
+ setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
180
+ readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
181
+ writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
182
+ canUseTool(sessionId: string): CanUseTool;
183
+ private createSession;
184
+ }
185
+ export declare function promptToClaude(prompt: PromptRequest): SDKUserMessage;
186
+ /**
187
+ * Convert an SDKAssistantMessage (Claude) to a SessionNotification (ACP).
188
+ * Only handles text, image, and thinking chunks for now.
189
+ */
190
+ export declare function toAcpNotifications(content: string | ContentBlockParam[] | BetaContentBlock[] | BetaRawContentBlockDelta[], role: "assistant" | "user", sessionId: string, toolUseCache: ToolUseCache, client: AgentSideConnection, logger: Logger): SessionNotification[];
191
+ export declare function streamEventToAcpNotifications(message: SDKPartialAssistantMessage, sessionId: string, toolUseCache: ToolUseCache, client: AgentSideConnection, logger: Logger): SessionNotification[];
192
+ export declare function runAcp(): void;
193
+ export {};
194
+ //# sourceMappingURL=acp-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-agent.d.ts","sourceRoot":"","sources":["../src/acp-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAEnB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EAGpB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,sB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