Files
cline/src/integrations/claude-code/run.ts
T
Tomás Barreiro 689afc62eb feat: Integrate Claude Code (#4111)
* Integrate Claude Code

* Add changeset

* handle exits gracefully, select models and update the path

* limit the claude-code models and update message

* expose the claudeCodePath in the apiConfiguration and proto

* remove log

* Update proto settings and properly map the provider
2025-06-18 00:51:07 +05:30

46 lines
872 B
TypeScript

import * as vscode from "vscode"
import Anthropic from "@anthropic-ai/sdk"
import { execa } from "execa"
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
export function runClaudeCode({
systemPrompt,
messages,
path,
modelId,
}: {
systemPrompt: string
messages: Anthropic.Messages.MessageParam[]
path?: string
modelId?: string
}) {
const claudePath = path || "claude"
// TODO: Is it worh using sessions? Where do we store the session ID?
const args = [
"-p",
JSON.stringify(messages),
"--system-prompt",
systemPrompt,
"--verbose",
"--output-format",
"stream-json",
// Cline will handle recursive calls
"--max-turns",
"1",
]
if (modelId) {
args.push("--model", modelId)
}
return execa(claudePath, args, {
stdin: "ignore",
stdout: "pipe",
stderr: "pipe",
env: process.env,
cwd,
})
}