claude-agent-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude Agent Ruby SDK
Claude Agent Ruby SDK
Overview
概述
Use this skill to build or refactor Ruby integrations with Claude Code via , favoring the gem's README and types for exact APIs.
claude-agent-sdk使用此技能通过构建或重构与Claude Code的Ruby集成,优先参考gem的README和类型定义以获取准确的API信息。
claude-agent-sdkDecision Guide
决策指南
- Choose for one-shot queries or streaming input. Internally uses the control protocol (streaming mode) since v0.7.0.
ClaudeAgentSDK.query - Choose for multi-turn sessions, hooks, permission callbacks, or dynamic model switching; wrap in
ClaudeAgentSDK::Client.Async do ... end.wait - Choose SDK MCP servers (,
create_tool) for in-process tools; choose external MCP configs for subprocess/HTTP servers.create_sdk_mcp_server
- 对于一次性查询或流式输入,选择。自v0.7.0版本起,其内部使用控制协议(流式模式)。
ClaudeAgentSDK.query - 对于多轮会话、钩子、权限回调或动态模型切换,选择;需将其包裹在
ClaudeAgentSDK::Client中执行。Async do ... end.wait - 对于进程内工具,选择SDK MCP服务器(、
create_tool);对于子进程/HTTP服务器,选择外部MCP配置。create_sdk_mcp_server
Implementation Checklist
实施检查清单
- Confirm prerequisites (Ruby 3.2+, Node.js, Claude Code CLI).
- Build and pass it to
ClaudeAgentSDK::ClaudeAgentOptionsorquery.Client.new - Handle messages by type (,
AssistantMessage,ResultMessage, etc.) and content blocks (UserMessage,TextBlock, etc.).ToolUseBlock - Use and read
output_formattool-use blocks for JSON schema responses.StructuredOutput - Use with
thinking:,ThinkingConfigAdaptive, orThinkingConfigEnabled(budget_tokens:)to control extended thinking. UseThinkingConfigDisabled(effort:,'low','medium') for effort level.'high' - Define hooks and permission callbacks as Ruby procs/lambdas; do not combine with
can_use_tool. Hook inputs includepermission_prompt_tool_nameontool_use_idandPreToolUseHookInput.PostToolUseHookInput - For SDK MCP tools, include in
mcp__<server>__<tool>. Useallowed_toolsonannotations:for MCP tool annotations.create_tool - Use or
toolsfor base tool selection; useToolsPresetwhen extending defaults.append_allowed_tools - Configure sandboxing via and
SandboxSettingswhen requested.SandboxNetworkConfig - Use ,
resume, andsession_idfor session handling; enable file checkpointing only when explicitly needed.fork_session - Note: when is nil (default), the SDK passes
system_promptto suppress the default Claude Code system prompt.--system-prompt ""
- 确认前置条件(Ruby 3.2+、Node.js、Claude Code CLI)。
- 构建并将其传入
ClaudeAgentSDK::ClaudeAgentOptions或query。Client.new - 按类型处理消息(、
AssistantMessage、ResultMessage等)和内容块(UserMessage、TextBlock等)。ToolUseBlock - 使用并读取
output_format工具使用块以获取JSON Schema响应。StructuredOutput - 使用参数搭配
thinking:、ThinkingConfigAdaptive或ThinkingConfigEnabled(budget_tokens:)来控制扩展思考功能。使用ThinkingConfigDisabled参数(effort:、'low'、'medium')设置努力级别。'high' - 将钩子和权限回调定义为Ruby proc/λ表达式;不要将与
can_use_tool结合使用。钩子输入在permission_prompt_tool_name和PreToolUseHookInput中包含PostToolUseHookInput。tool_use_id - 对于SDK MCP工具,需在中包含
allowed_tools。在mcp__<server>__<tool>上使用create_tool参数添加MCP工具注解。annotations: - 使用或
tools选择基础工具;扩展默认工具时使用ToolsPreset。append_allowed_tools - 当需要时,通过和
SandboxSettings配置沙箱。SandboxNetworkConfig - 使用、
resume和session_id处理会话;仅在明确需要时启用文件检查点。fork_session - 注意:当为nil(默认值)时,SDK会传递
system_prompt以禁用默认的Claude Code系统提示。--system-prompt ""
Where To Look For Exact Details
详细信息查询位置
- Locate the gem path with or
bundle show claude-agent-sdk.ruby -e 'puts Gem::Specification.find_by_name(\"claude-agent-sdk\").full_gem_path' - Read for canonical usage and option examples.
<gem_path>/README.md - Inspect for the full options and type list.
<gem_path>/lib/claude_agent_sdk/types.rb - Inspect for error classes and handling.
<gem_path>/lib/claude_agent_sdk/errors.rb - Use for a README section map and minimal skeletons.
references/usage-map.md
- 使用或
bundle show claude-agent-sdk查找gem的路径。ruby -e 'puts Gem::Specification.find_by_name("claude-agent-sdk").full_gem_path' - 阅读获取标准用法和选项示例。
<gem_path>/README.md - 查看获取完整的选项和类型列表。
<gem_path>/lib/claude_agent_sdk/types.rb - 查看获取错误类和处理方式。
<gem_path>/lib/claude_agent_sdk/errors.rb - 使用获取README章节映射和最小化代码骨架。
references/usage-map.md
Resources
资源
references/
references/
Use to map tasks to README sections and gem paths.
references/usage-map.md使用将任务映射到README章节和gem路径。",
references/usage-map.md