Skip to content

Commit 25c9004

Browse files
authored
Migrate to @anthropic-ai/claude-agent-sdk (#1257)
1 parent 4d3ad14 commit 25c9004

File tree

12 files changed

+34
-29
lines changed

12 files changed

+34
-29
lines changed

.esbuild.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ const sanityTestBundlePlugin: esbuild.Plugin = {
112112
};
113113

114114
const importMetaPlugin: esbuild.Plugin = {
115-
name: 'claudeCodeImportMetaPlugin',
115+
name: 'claudeAgentSdkImportMetaPlugin',
116116
setup(build) {
117-
// Handle import.meta.url in @anthropic-ai/claude-code package
118-
build.onLoad({ filter: /node_modules[\/\\]@anthropic-ai[\/\\]claude-code[\/\\].*\.mjs$/ }, async (args) => {
117+
// Handle import.meta.url in @anthropic-ai/claude-agent-sdk package
118+
build.onLoad({ filter: /node_modules[\/\\]@anthropic-ai[\/\\]claude-agent-sdk[\/\\].*\.mjs$/ }, async (args) => {
119119
const contents = await fs.promises.readFile(args.path, 'utf8');
120120
return {
121121
contents: contents.replace(

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"search.exclude": {
5252
"src/base/util/tokenizer_*.json": true,
5353
"src/base/util/*.bpe": true,
54+
"src/extension/chatSessions/vscode-node/test/fixtures/**": true,
5455
"src/extension/prompts/node/test/fixtures/**/*": true,
5556
"src/extension/test/node/fixtures/**/*": true,
5657
"src/platform/parser/test/node/fixtures/**/*": true,

package-lock.json

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,7 +4263,7 @@
42634263
"yaml": "^2.8.0"
42644264
},
42654265
"dependencies": {
4266-
"@anthropic-ai/claude-code": "^1.0.120",
4266+
"@anthropic-ai/claude-agent-sdk": "^0.1.9",
42674267
"@anthropic-ai/sdk": "^0.63.0",
42684268
"@humanwhocodes/gitignore-to-minimatch": "1.0.2",
42694269
"@microsoft/tiktokenizer": "^1.0.10",
@@ -4291,4 +4291,4 @@
42914291
"string_decoder": "npm:[email protected]",
42924292
"node-gyp": "npm:[email protected]"
42934293
}
4294-
}
4294+
}

script/postinstall.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ async function main() {
140140
}
141141

142142
await copyStaticAssets([
143-
`node_modules/@anthropic-ai/claude-code/cli.js`,
144-
`node_modules/@anthropic-ai/claude-code/yoga.wasm`,
145-
// `node_modules/@anthropic-ai/claude-code/vendor/ripgrep/${process.arch}-${process.platform}/ripgrep`,
143+
`node_modules/@anthropic-ai/claude-agent-sdk/cli.js`,
144+
`node_modules/@anthropic-ai/claude-agent-sdk/yoga.wasm`,
146145
], 'dist');
147146
}
148147

src/extension/agents/claude/node/claudeCodeAgent.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Options, Query, SDKAssistantMessage, SDKResultMessage, SDKUserMessage } from '@anthropic-ai/claude-code';
6+
import { Options, Query, SDKAssistantMessage, SDKResultMessage, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
77
import Anthropic from '@anthropic-ai/sdk';
88
import type * as vscode from 'vscode';
99
import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService';
@@ -234,7 +234,6 @@ export class ClaudeCodeSession extends Disposable {
234234
*/
235235
private async _startSession(): Promise<void> {
236236
// Build options for the Claude Code SDK
237-
// process.env.DEBUG = '1'; // debug messages from sdk.mjs
238237
const isDebugEnabled = this.configService.getConfig(ConfigKey.Internal.ClaudeCodeDebugEnabled);
239238
this.logService.trace(`appRoot: ${this.envService.appRoot}`);
240239
const pathSep = isWindows ? ';' : ':';
@@ -244,7 +243,6 @@ export class ClaudeCodeSession extends Disposable {
244243
executable: process.execPath as 'node', // get it to fork the EH node process
245244
env: {
246245
...process.env,
247-
...(isDebugEnabled ? { DEBUG: '1' } : {}),
248246
ANTHROPIC_BASE_URL: `http://localhost:${this.serverConfig.port}`,
249247
ANTHROPIC_API_KEY: this.serverConfig.nonce,
250248
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
@@ -257,10 +255,20 @@ export class ClaudeCodeSession extends Disposable {
257255
this.canUseTool(name, input, this._currentRequest.toolInvocationToken) :
258256
{ behavior: 'deny', message: 'No active request' };
259257
},
260-
appendSystemPrompt: 'Your responses will be rendered as markdown, so please reply with properly formatted markdown when appropriate. When replying with code or the name of a symbol, wrap it in backticks.'
258+
systemPrompt: {
259+
type: 'preset',
260+
preset: 'claude_code',
261+
append: 'Your responses will be rendered as markdown, so please reply with properly formatted markdown when appropriate. When replying with code or the name of a symbol, wrap it in backticks.'
262+
},
263+
settingSources: ['user', 'project', 'local'],
264+
...(isDebugEnabled && {
265+
stderr: data => {
266+
this.logService.trace(`claude-agent-sdk stderr: ${data}`);
267+
}
268+
})
261269
};
262270

263-
this.logService.trace(`Claude CLI SDK: Starting query with options: ${JSON.stringify(options)}`);
271+
this.logService.trace(`claude-agent-sdk: Starting query with options: ${JSON.stringify(options)}`);
264272
this._queryGenerator = await this.claudeCodeService.query({
265273
prompt: this._createPromptIterable(),
266274
options
@@ -323,7 +331,7 @@ export class ClaudeCodeSession extends Disposable {
323331
throw new Error('Request was cancelled');
324332
}
325333

326-
this.logService.trace(`Claude CLI SDK Message: ${JSON.stringify(message, null, 2)}`);
334+
this.logService.trace(`claude-agent-sdk Message: ${JSON.stringify(message, null, 2)}`);
327335
if (message.session_id) {
328336
this.sessionId = message.session_id;
329337
}

src/extension/agents/claude/node/claudeCodeSdkService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Options, Query, SDKUserMessage } from '@anthropic-ai/claude-code';
6+
import { Options, Query, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
77
import { createServiceIdentifier } from '../../../../util/common/services';
88

99
export interface IClaudeCodeSdkService {
@@ -32,7 +32,7 @@ export class ClaudeCodeSdkService implements IClaudeCodeSdkService {
3232
prompt: AsyncIterable<SDKUserMessage>;
3333
options: Options;
3434
}): Promise<Query> {
35-
const { query } = await import('@anthropic-ai/claude-code');
35+
const { query } = await import('@anthropic-ai/claude-agent-sdk');
3636
return query(options);
3737
}
3838
}

src/extension/agents/claude/node/claudeCodeSessionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { SDKMessage, SDKUserMessage } from '@anthropic-ai/claude-code';
6+
import { SDKMessage, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
77
import Anthropic from '@anthropic-ai/sdk';
88
import type { CancellationToken } from 'vscode';
99
import { INativeEnvService } from '../../../../platform/env/common/envService';

src/extension/agents/claude/node/test/claudeCodeSessionService.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
67
import { readFile } from 'fs/promises';
78
import * as path from 'path';
89
import { beforeEach, describe, expect, it } from 'vitest';
@@ -19,7 +20,6 @@ import { URI } from '../../../../../util/vs/base/common/uri';
1920
import { IInstantiationService } from '../../../../../util/vs/platform/instantiation/common/instantiation';
2021
import { createExtensionUnitTestingServices } from '../../../../test/node/services';
2122
import { ClaudeCodeSessionService } from '../claudeCodeSessionService';
22-
import { SDKUserMessage } from '@anthropic-ai/claude-code';
2323

2424
function computeFolderSlug(folderUri: URI): string {
2525
return folderUri.path.replace(/\//g, '-');

src/extension/agents/claude/node/test/mockClaudeCodeSdkService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Options, Query, SDKAssistantMessage, SDKResultMessage, SDKUserMessage } from '@anthropic-ai/claude-code';
6+
import { Options, Query, SDKAssistantMessage, SDKResultMessage, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
77
import { IClaudeCodeSdkService } from '../claudeCodeSdkService';
88

99
/**

0 commit comments

Comments
 (0)