
roasbeef/claude-agent-sdk-go
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
Claude Code SDK – 도구 사용, MCP 통합 및 스트리밍으로 AI 에이전트 구축
개요
Claude의 대리인 기능을 위한 순수한 Go SDK. claude-agent-sdk-go는 CLI를 서브프로세스로 관리함으로써 Claude Code에 Native Go 인터페이스를 제공합니다. 그것은 stdin/stdout에 line-delimited JSON을 통해 통신합니다. Claude의 도구 사용, 확장 된 사고, 세션 관리 및 후크 시스템에 액세스합니다. 이 저장소는 API 모양이 다릅니다 Go idioms를 사용하여 v0.3.296 catchup 작업을 통해 공식 TypeScript Agent SDK 표면을 추적합니다. Query() 또는 Stream()을 호출할 때, SDK는 CLI를 종료하고, 여러분의 프롬프트를 보내며, 도착한 대로 메시지를 출력합니다. MCP 도구의 경우 유량은 양방향 제어 메시지가 포함되어 있습니다. 요구 사항 : - 이동 1.23 + ( iter.Seq) - 클로드 코드 CLI : npm install -g @anthropic-ai/claude-code - ANTHROPIC API KEY 또는 CLAUDE CODE OAUTH TOKEN 환경 설정은 설정 파일 경로 또는 인라인 JSON으로 공급될 수 있습니다. Claude가 대화 중에 사용할 수있는 도구 정의 : MCP 정보 Typed 응답, 바이너리 서버 및 더 많은 도구.
개요(AI 번역)
Claude의 대리인 기능을 위한 순수한 Go SDK.
개요
claude-agent-sdk-go는 Claude Code에 기본 Go 인터페이스를 제공하여 관리합니다. CLI는 하위 프로세스입니다. line-delimited JSON을 통해 전달합니다. stdin/stdout, Claude의 도구 사용, 확장 된 생각에 액세스, 세션 관리 및 후크 시스템.
이 저장소는 공식 TypeScript Agent SDK 표면을 통해 추적합니다. v0.3.310 catchup 작업, API 모양이 다릅니다 Go idioms를 사용하여.
Query() 또는 Stream()를 호출할 때, SDK는 CLI를 스팸으로 보냅니다.
신속하게, 그들은 도착으로 메시지 수율. MCP 도구의 경우, 유량은 포함
양방향 제어 메시지:
설치
명세서:
- 이동 1.23+ ([T2]])
- 클로드 코드 CLI:
npm install -g @anthropic-ai/claude-code ANTHROPIC_API_KEY또는CLAUDE_CODE_OAUTH_TOKEN]
빠른 시작
스트리밍
멀티턴 대화를 위해:
구성
설정은 설정 파일 경로 또는 인라인 JSON으로 공급될 수 있습니다.
사용자 정의 도구 (MCP)
Claude가 대화 중에 사용할 수있는 도구 정의 :
MCP 정보 Typed 응답, 바이너리 서버 및 더 많은 도구.
Ralph Wiggum 루프
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
claude-agent-sdk-go
A pure Go SDK for Claude’s agentic capabilities.
Overview
claude-agent-sdk-go provides a native Go interface to Claude Code by managing the CLI as a subprocess. It communicates via line-delimited JSON over stdin/stdout, giving you access to Claude’s tool use, extended thinking, session management, and hook system.
This repository tracks the official TypeScript Agent SDK surface through the v0.3.316 catchup work, using Go idioms where the API shape differs.
flowchart TB
subgraph SDK[Go SDK]
Client --> Protocol --> Transport
MCP[SDK MCP] |tool calls| Protocol
end
Transport |stream-json| CLI[Claude CLI]
CLI API[Claude API]
When you call Query() or Stream(), the SDK spawns the CLI, sends your
prompt, and yields messages as they arrive. For MCP tools, the flow includes
bidirectional control messages:
sequenceDiagram
participant App as Go App
participant CLI as Claude CLI
participant API as Claude API
App->>CLI: prompt (stdin)
CLI->>API: API request
API-->>CLI: response stream
CLI-->>App: messages (stdout)
CLI->>App: mcp_message (tool call)
App-->>CLI: mcp_response
CLI-->>App: result
Installation
go get github.com/roasbeef/claude-agent-sdk-go
Requirements:
- Go 1.23+ (for
iter.Seq) - Claude Code CLI:
npm install -g @anthropic-ai/claude-code ANTHROPIC_API_KEYorCLAUDE_CODE_OAUTH_TOKENin your environment
Quick Start
package main
import (
"context"
"fmt"
"log"
"github.com/roasbeef/claude-agent-sdk-go"
)
func main() {
client, err := claudeagent.NewClient(
claudeagent.WithSystemPrompt("You are a helpful assistant."),
)
if err != nil {
log.Fatal(err)
}
defer client.Close()
ctx := context.Background()
for msg := range client.Query(ctx, "What is the capital of France?") {
switch m := msg.(type) {
case claudeagent.AssistantMessage:
fmt.Println(m.ContentText())
case claudeagent.ResultMessage:
fmt.Printf("Cost: $%.4f\n", m.TotalCostUSD)
}
}
}
Streaming
For multi-turn conversations:
stream, _ := client.Stream(ctx)
defer stream.Close()
stream.Send(ctx, "Let's plan a trip to Japan.")
for msg := range stream.Messages() {
if m, ok := msg.(claudeagent.AssistantMessage); ok {
fmt.Println(m.ContentText())
}
}
// Continue the conversation
stream.Send(ctx, "What about Kyoto?")
Configuration
client, _ := claudeagent.NewClient(
claudeagent.WithModel("claude-sonnet-4-5-20250929"),
claudeagent.WithSystemPrompt("You are an expert Go developer."),
claudeagent.WithPermissionMode(claudeagent.PermissionModeAcceptEdits),
claudeagent.WithMaxTurns(20),
)
설치
This server does not publish a one-line install command.
Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →