mirror of
https://github.com/cline/cline.git
synced 2026-09-19 02:05:44 +08:00
* 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
46 lines
872 B
TypeScript
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,
|
|
})
|
|
}
|