Token导航 LogoToken导航

Agent Skill · 研究检索

claude-agent-sdk(Claude Agent SDK 搜索)

claude-agent-sdk 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

claude-agent-sdk 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为调用外部服务;许可证信息还不明确,第三方扫描有提醒项,按安装量在研究检索类的 73,675 个 Skill 里排第 64,557。

总安装 297周安装 12GitHub Stars 18下载 93核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:claude-agent-sdk(Claude Agent SDK 搜索)
来源仓库:https://github.com/basher83/lunar-claude
仓库路径:skills/claude-agent-sdk
安装命令:
npx skills add https://github.com/basher83/lunar-claude --skill claude-agent-sdk
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/basher83/lunar-claude --skill claude-agent-sdk

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

claude-agent-sdk 提供基于 Claude Agent SDK 的应用程序构建模式和支持。支持 query() 和 ClaudeSDKClient 两种调用方式的选择指导。适用于构建生产级多代理协调应用,提供模板化项目结构和异步处理模式。

目标版本为 claude-agent-sdk>=0.1.6 (Python),需配合 uv 脚本头使用。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/claude-agent-sdk

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/basher83/lunar-claude --skill claude-agent-sdk;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要调用外部服务,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

claude-agent-sdk 怎么安装?

在终端执行 npx skills add https://github.com/basher83/lunar-claude --skill claude-agent-sdk。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

claude-agent-sdk 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

claude-agent-sdk 需要什么权限?

权限级别是调用外部服务。该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

claude-agent-sdk 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

claude-agent-sdk 用的人多吗?

公开数据是累计安装 297 次,近一周安装 12 次,下载 93 次,GitHub 18 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

claude-agent-sdk 安全吗?

第三方扫描有提醒项,说明存在需要人工确认的行为。安装前请打开源码看清它读了什么、联网到哪里。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
claude-agent-sdk

Claude Agent SDK 搜索 · 本页

29718调用外部服务未明确有提醒

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Claude Agent SDK

Build production-ready applications using the Claude Agent SDK for Python.

SDK Version: This skill targets claude-agent-sdk>=0.1.6 (Python)

Overview

This skill provides patterns, examples, and best practices for building SDK applications that orchestrate Claude agents.

Quick Start

Copy the template and customize:

cp assets/sdk-template.py my-app.py
# Edit my-app.py - customize agents and workflow
chmod +x my-app.py
./my-app.py

The template includes proper uv script headers, agent definitions, and async patterns.

Choosing Between query() and ClaudeSDKClient

The SDK provides two ways to interact with Claude: the query() function for simple one-shot tasks, and ClaudeSDKClient for continuous conversations.

Quick Comparison

Featurequery()ClaudeSDKClient
Conversation memoryNo - each call is independentYes - maintains context across queries
Use caseOne-off tasks, single questionsMulti-turn conversations, complex workflows
ComplexitySimple - one function callMore setup - context manager pattern
Hooks supportNoYes
Custom toolsNoYes
InterruptsNoYes - can interrupt ongoing operations
Session controlNew session each timeSingle persistent session
Important: Hooks and custom tools (SDK MCP servers) are only supported with ClaudeSDKClient, not with query(). If you need hooks or custom tools, you must use ClaudeSDKClient. Note on Async Runtimes: The SDK works with both asyncio and anyio. The official SDK examples prefer anyio.run() for better async library compatibility, but asyncio.run() works equally well. Use whichever fits your project's async runtime.

When to Use query()

Use query() for simple, independent tasks where you don't need conversation history:

import anyio  # or: import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

async def analyze_file():
    """One-shot file analysis - no conversation needed."""
    options = ClaudeAgentOptions(
        system_prompt="You are a code analyzer",
        allowed_tools=["Read", "Grep", "Glob"],
        permission_mode="acceptEdits"
    )

    async for message in query(
        prompt="Analyze /path/to/file.py for bugs",
        options=options
    ):
        print(message)

anyio.run(analyze_file)  # or: asyncio.run(analyze_file())

Best for:

  • Single analysis tasks
  • Independent file operations
  • Quick questions without follow-up
  • Scripts that run once and exit

Key limitation: Each query() call creates a new session with no memory of previous calls.

When to Use ClaudeSDKClient

Use ClaudeSDKClient when you need conversation context across multiple interactions:

import anyio  # or: import asyncio
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions, AssistantMessage, TextBlock

async def interactive_debugging():
    """Multi-turn debugging conversation with context."""
    options = ClaudeAgentOptions(
        system_prompt="You are a debugging assistant",
        allowed_tools=["Read", "Grep", "Bash"],
        permission_mode="acceptEdits"
    )

    async with ClaudeSDKClient(options=options) as client:
        # First query
        await client.query("Find all TODO comments in /path/to/project")
        async for message in client.receive_response():
            if isinstance(message, AssistantMessage):
                for block in message.content:
                    if isinstance(block, TextBlock):
                        print(f"Claude: {block.text}")

        # Follow-up - Claude remembers the TODOs found above
        await client.query("Now prioritize them by complexity")
        async for message in client.receive_response():
            if isinstance(message, AssistantMessage):
                for block in message.content:
                    if isinstance(block, TextBlock):
                        print(f"Claude: {block.text}")

        # Another follow-up - still in same conversation
        await client.query("Create a plan to address the top 3")
        async for message in client.receive_response():
            if isinstance(message, AssistantMessage):
                for block in message.content:
                    if isinstance(block, TextBlock):
                        print(f"Claude: {block.text}")

anyio.run(interactive_debugging)  # or: asyncio.run(interactive_debugging())

Best for:

  • Multi-turn conversations
  • Interactive workflows
  • Tasks requiring context from previous responses
  • Applications with interrupt capability
  • Orchestrators managing complex workflows

Key advantage: Claude remembers all previous queries and responses in the session.

See: examples/streaming_mode.py - Comprehensive ClaudeSDKClient examples with all patterns

Advanced: Interrupts with ClaudeSDKClient

Only ClaudeSDKClient supports interrupting ongoing operations:

import anyio  # or: import asyncio
from claude_agent_sdk import ClaudeSDKClient

async def interruptible_task():
    async with ClaudeSDKClient() as client:
        await client.query("Run a long analysis on /large/codebase")

        # Start processing in background
        async with anyio.create_task_group() as tg:
            tg.start_soon(process_messages, client)

            # Simulate user interrupt after 5 seconds
            await anyio.sleep(5)
            await client.interrupt()

async def process_messages(client):
    async for message in client.receive_response():
        print(message)

anyio.run(interruptible_task)  # or: asyncio.run(interruptible_task())

Quick Decision Guide

Use query() if:

  • Task is self-contained
  • No follow-up questions needed
  • Each execution is independent
  • Simpler code is preferred

Use ClaudeSDKClient if:

  • Need conversation memory
  • Building interactive workflows
  • Require interrupt capability
  • Managing complex multi-step processes
  • Working with orchestrators and subagents

Core Patterns

1. Orchestrator with Subagents

Define a main orchestrator that delegates work to specialized subagents.

Critical requirements:

  • Orchestrator must use system_prompt={"type": "preset", "preset": "claude_code"} (provides Task tool knowledge)
  • Register agents programmatically via agents={} parameter (SDK best practice)
  • Orchestrator must include "Task" in allowed_tools
  • Match agent names exactly between definition and usage

Example:

from claude_agent_sdk import AgentDefinition, ClaudeAgentOptions

options = ClaudeAgentOptions(
    system_prompt={"type": "preset", "preset": "claude_code"},  # REQUIRED for orchestrators
    allowed_tools=["Bash", "Task", "Read", "Write"],
    agents={
        "analyzer": AgentDefinition(
            description="Analyzes code structure and patterns",
            prompt="You are a code analyzer...",
            tools=["Read", "Grep", "Glob"],
            model="sonnet"
        ),
        "fixer": AgentDefinition(
            description="Fixes identified issues",
            prompt="You are a code fixer...",
            tools=["Read", "Edit", "Bash"],
            model="sonnet"
        )
    },
    permission_mode="acceptEdits",
    model="claude-sonnet-4-5"
)

See:

  • references/agent-patterns.md - Complete agent definition patterns
  • examples/agents.py - Official SDK agent examples with different agent types

2. System Prompt Configuration

Choose the appropriate system prompt pattern:

# Orchestrator (use claude_code preset) - dict format (official examples prefer this)
system_prompt={"type": "preset", "preset": "claude_code"}

# Shorthand format (equivalent, but less explicit)
system_prompt="claude_code"

# Custom behavior
system_prompt="You are a Python expert..."

# Extend preset with additional instructions
system_prompt={
    "type": "preset",
    "preset": "claude_code",
    "append": "Additional domain-specific instructions"
}

Note: The shorthand system_prompt="claude_code" is equivalent to {"type": "preset", "preset": "claude_code"}. Both are valid. Official examples prefer the dict format for explicitness.

See:

  • references/system-prompts.md - Complete system prompt documentation
  • examples/system_prompt.py - Official SDK system prompt examples

3. Tool Restrictions

Limit subagent tools to minimum needed:

# Read-only analyzer
tools=["Read", "Grep", "Glob"]

# Code modifier
tools=["Read", "Edit", "Bash"]

# Test runner
tools=["Bash", "Read"]

See: references/agent-patterns.md for common tool combinations

4. Hooks

Intercept SDK events to control behavior:

from claude_agent_sdk import HookMatcher

options = ClaudeAgentOptions(
    hooks={
        "PreToolUse": [
            HookMatcher(matcher="Bash", hooks=[check_bash_command])
        ],
        "PostToolUse": [
            HookMatcher(matcher="Bash", hooks=[review_output])
        ]
    }
)

See:

  • references/hooks-guide.md - Complete hook patterns documentation
  • examples/hooks.py - Official SDK hook examples with all hook types

5. Permission Callbacks

Fine-grained control over tool usage:

async def permission_callback(tool_name, input_data, context):
    # Allow read operations
    if tool_name in ["Read", "Grep", "Glob"]:
        return PermissionResultAllow()

    # Block dangerous commands
    if tool_name == "Bash" and "rm -rf" in input_data.get("command", ""):
        return PermissionResultDeny(message="Dangerous command")

    return PermissionResultAllow()

options = ClaudeAgentOptions(
    can_use_tool=permission_callback,
    permission_mode="default"
)

See:

  • references/tool-permissions.md - Complete permission patterns and decision guide
  • examples/tool_permission_callback.py - Official SDK permission callback example

Workflow Templates

Building an Orchestrator

Follow these steps to build an effective orchestrator:

1. Define agent purposes

  • What specialized tasks need delegation?
  • What tools does each agent need?
  • What constraints should apply?

2. Create agent definitions

agents={
    "agent-name": AgentDefinition(
        description="When to use this agent",
        prompt="Agent's role and behavior",
        tools=["Tool1", "Tool2"],
        model="sonnet"
    )
}

3. Configure orchestrator

options = ClaudeAgentOptions(
    system_prompt={"type": "preset", "preset": "claude_code"},  # CRITICAL
    allowed_tools=["Bash", "Task", "Read", "Write"],
    agents=agents,
    permission_mode="acceptEdits"
)

4. Implement workflow

async with ClaudeSDKClient(options=options) as client:
    await client.query("Use 'agent-name' to perform task")

    async for message in client.receive_response():
        # Process responses
        pass

See: examples/basic-orchestrator.py for complete working example

Loading Agents from Files

While programmatic registration is recommended, agent content can be stored in markdown files:

import yaml

def load_agent_definition(path: str) -> AgentDefinition:
    """Load agent from markdown file with YAML frontmatter."""
    with open(path) as f:
        content = f.read()

    parts = content.split("---")
    frontmatter = yaml.safe_load(parts[1])
    prompt = parts[2].strip()

    # Parse tools (comma-separated string or array)
    tools = frontmatter.get("tools", [])
    if isinstance(tools, str):
        tools = [t.strip() for t in tools.split(",")]

    return AgentDefinition(
        description=frontmatter["description"],
        prompt=prompt,
        tools=tools,
        model=frontmatter.get("model", "inherit")
    )

# Load and register programmatically
agent = load_agent_definition(".claude/agents/my-agent.md")
options = ClaudeAgentOptions(agents={"my-agent": agent})

See: references/agent-patterns.md for complete loading pattern

Common Anti-Patterns

Avoid these common mistakes:

❌ Missing orchestrator system prompt

# Orchestrator won't know how to use Task tool
options = ClaudeAgentOptions(agents={...})

✅ Correct orchestrator configuration

options = ClaudeAgentOptions(
    system_prompt="claude_code",
    agents={...}
)

❌ Mismatched agent names

agents={"investigator": AgentDefinition(...)}
await client.query("Use 'markdown-investigator'...")  # Wrong name

✅ Exact name matching

agents={"investigator": AgentDefinition(...)}
await client.query("Use 'investigator'...")  # Matches

❌ Tool/prompt mismatch

system_prompt="Fix bugs you find"
allowed_tools=["Read", "Grep"]  # Can't fix, only read

✅ Aligned tools and behavior

system_prompt="Analyze code for bugs"
allowed_tools=["Read", "Grep", "Glob"]

See: references/best-practices.md for complete anti-patterns list

Resources

references/

In-depth documentation loaded as needed:

  • api-reference.md - Complete Python SDK API reference (types, functions, examples)
  • agent-patterns.md - Agent definition patterns, tool restrictions, best practices
  • subagents.md - Comprehensive subagent patterns and SDK integration
  • system-prompts.md - System prompt configuration (preset, custom, append)
  • hooks-guide.md - Hook patterns for all hook types with examples
  • tool-permissions.md - Permission callback patterns and examples
  • best-practices.md - SDK best practices, anti-patterns, debugging tips
  • custom-tools.md - Creating custom tools with SDK MCP servers (Python-only)
  • sessions.md - Session management and resumption patterns (Python-only)
  • skills.md - Using Agent Skills with the SDK (Python-only)
  • slash-commands.md - Slash commands and custom command creation (Python-only)

examples/

Ready-to-run code examples from official SDK:

Getting Started:

  • quick_start.py - Basic query() usage and message handling (start here!)
  • basic-orchestrator.py - Complete orchestrator with analyzer and fixer subagents

Core Patterns:

  • agents.py - Programmatic agent definitions with different agent types
  • hooks.py - Comprehensive hook patterns (PreToolUse, PostToolUse, UserPromptSubmit, etc.)
  • system_prompt.py - System prompt patterns (preset, custom, append)
  • streaming_mode.py - Complete ClaudeSDKClient patterns with multi-turn conversations

Advanced Features:

  • mcp_calculator.py - Custom tools with SDK MCP server (in-process tool server)
  • tool_permission_callback.py - Permission callbacks with logging and control
  • setting_sources.py - Settings isolation and loading (user/project/local)
  • plugin_example.py - Using plugins with the SDK (relevant for plugin marketplace!)

assets/

Templates and validation tools:

  • sdk-template.py - Project template with uv script headers and agent structure
  • sdk-validation-checklist.md - Comprehensive checklist for validating SDK applications against best practices

When to Use This Skill

Use this skill when:

  • Creating new Claude Agent SDK applications
  • Building orchestrators with multiple subagents
  • Implementing programmatic agent definitions
  • Configuring hooks or permission callbacks
  • Validating/reviewing SDK code (use assets/sdk-validation-checklist.md)
  • Migrating from filesystem agent discovery to programmatic registration
  • Debugging SDK applications (agent not found, Task tool not working)
  • Following SDK best practices

Do not use for:

  • Claude Code slash commands or skills (different system)
  • Direct API usage without SDK
  • Non-Python implementations (TypeScript SDK has different patterns)

Next Steps

For Beginners

  1. Start with examples/quick_start.py - Learn basic query() usage
  2. Try assets/sdk-template.py - Template for new projects
  3. Review examples/basic-orchestrator.py - See orchestrator pattern

For Intermediate Users

  1. Explore core patterns:

- examples/agents.py - Agent definitions - examples/system_prompt.py - System prompt patterns - examples/streaming_mode.py - Multi-turn conversations - examples/hooks.py - Hook patterns

For Advanced Users

  1. Study advanced features:

- examples/tool_permission_callback.py - Permission control - examples/mcp_calculator.py - Custom tools - examples/setting_sources.py - Settings management - examples/plugin_example.py - Plugin integration

Validation & Quality

  1. Validate your code with assets/sdk-validation-checklist.md
  2. Review against best practices in references/best-practices.md

Reference Documentation

  1. Consult references/ as needed for detailed patterns

平台分布

Codex

38.47%
按下载量换算36

Claude

31.08%
按下载量换算29

Cursor

18.92%
按下载量换算18

Gemini CLI

9.36%
按下载量换算9

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

可疑

权限和风险

调用外部服务

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills