Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K

    第一步

    Claude 介紹快速入門

    模型與定價

    模型概覽選擇模型Claude 4.5 的新功能遷移到 Claude 4.5模型棄用定價

    使用 Claude 建構

    功能概覽使用 Messages API上下文視窗提示詞最佳實踐

    功能

    提示詞快取上下文編輯延伸思考串流訊息批次處理引用多語言支援Token 計數嵌入向量視覺PDF 支援Files API搜尋結果Google Sheets 附加元件

    工具

    概述如何實現工具使用代幣高效工具使用細粒度工具串流Bash 工具代碼執行工具電腦使用工具文字編輯工具網頁擷取工具網路搜尋工具記憶工具

    代理技能

    概述在 API 中開始使用 Agent Skills技能編寫最佳實踐使用 Agent Skills 與 API

    Agent SDK

    概述Agent SDK 參考 - TypeScriptPython SDK

    指南

    串流輸入處理權限會話管理託管 Agent SDK修改系統提示SDK 中的 MCP自訂工具SDK 中的子代理SDK 中的斜線命令SDK 中的代理技能追蹤成本和使用量待辦事項清單SDK 中的外掛程式

    API 中的 MCP

    MCP 連接器遠端 MCP 伺服器

    Claude 在第三方平台上

    Amazon BedrockVertex AI

    提示工程

    概述提示詞生成器使用提示模板提示詞改進器保持清晰和直接使用範例(多樣提示)讓 Claude 思考(思維鏈)使用 XML 標籤給 Claude 分配角色(系統提示詞)預填 Claude 的回應串接複雜提示長文本技巧延伸思考技巧

    測試與評估

    定義成功標準開發測試案例使用評估工具降低延遲

    加強防護措施

    減少幻覺提高輸出一致性防範越獄handle-streaming-refusals減少提示詞洩漏保持 Claude 的角色特性

    管理和監控

    Admin API 概述使用量和成本 APIClaude Code 分析 API
    Console
    指南

    SDK 中的外掛程式

    透過 Agent SDK 載入自訂外掛程式,以使用命令、代理、技能和掛鉤來擴展 Claude Code

    外掛程式可讓您使用可在專案間共享的自訂功能來擴展 Claude Code。透過 Agent SDK,您可以以程式設計方式從本機目錄載入外掛程式,以將自訂斜線命令、代理、技能、掛鉤和 MCP 伺服器新增到您的代理工作階段。

    什麼是外掛程式?

    外掛程式是 Claude Code 擴充功能的套件,可以包括:

    • 命令:自訂斜線命令
    • 代理:用於特定任務的專門子代理
    • 技能:Claude 自主使用的模型叫用功能
    • 掛鉤:回應工具使用和其他事件的事件處理程式
    • MCP 伺服器:透過模型上下文協議的外部工具整合

    如需有關外掛程式結構以及如何建立外掛程式的完整資訊,請參閱外掛程式。

    載入外掛程式

    透過在選項設定中提供外掛程式的本機檔案系統路徑來載入外掛程式。SDK 支援從不同位置載入多個外掛程式。

    TypeScript
    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    for await (const message of query({
      prompt: "Hello",
      options: {
        plugins: [
          { type: "local", path: "./my-plugin" },
          { type: "local", path: "/absolute/path/to/another-plugin" }
        ]
      }
    })) {
      // Plugin commands, agents, and other features are now available
    }
    Python
    import asyncio
    from claude_agent_sdk import query
    
    async def main():
        async for message in query(
            prompt="Hello",
            options={
                "plugins": [
                    {"type": "local", "path": "./my-plugin"},
                    {"type": "local", "path": "/absolute/path/to/another-plugin"}
                ]
            }
        ):
            # Plugin commands, agents, and other features are now available
            pass
    
    asyncio.run(main())

    路徑規格

    外掛程式路徑可以是:

    • 相對路徑:相對於您目前工作目錄解析(例如,"./plugins/my-plugin")
    • 絕對路徑:完整檔案系統路徑(例如,"/home/user/plugins/my-plugin")

    路徑應指向外掛程式的根目錄(包含 .claude-plugin/plugin.json 的目錄)。

    驗證外掛程式安裝

    當外掛程式成功載入時,它們會出現在系統初始化訊息中。您可以驗證您的外掛程式是否可用:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    for await (const message of query({
      prompt: "Hello",
      options: {
        plugins: [{ type: "local", path: "./my-plugin" }]
      }
    })) {
      if (message.type === "system" && message.subtype === "init") {
        // Check loaded plugins
        console.log("Plugins:", message.plugins);
        // Example: [{ name: "my-plugin", path: "./my-plugin" }]
    
        // Check available commands from plugins
        console.log("Commands:", message.slash_commands);
        // Example: ["/help", "/compact", "my-plugin:custom-command"]
      }
    }

    使用外掛程式命令

    來自外掛程式的命令會自動以外掛程式名稱作為命名空間,以避免衝突。格式為 plugin-name:command-name。

    import { query } from "@anthropic-ai/claude-agent-sdk";
    
    // Load a plugin with a custom /greet command
    for await (const message of query({
      prompt: "/my-plugin:greet",  // Use plugin command with namespace
      options: {
        plugins: [{ type: "local", path: "./my-plugin" }]
      }
    })) {
      // Claude executes the custom greeting command from the plugin
      if (message.type === "assistant") {
        console.log(message.content);
      }
    }

    如果您透過 CLI 安裝了外掛程式(例如,/plugin install my-plugin@marketplace),您仍然可以透過提供其安裝路徑在 SDK 中使用它。檢查 ~/.claude/plugins/ 以查找 CLI 安裝的外掛程式。

    完整範例

    以下是示範外掛程式載入和使用的完整範例:

    import { query } from "@anthropic-ai/claude-agent-sdk";
    import * as path from "path";
    
    async function runWithPlugin() {
      const pluginPath = path.join(__dirname, "plugins", "my-plugin");
    
      console.log("Loading plugin from:", pluginPath);
    
      for await (const message of query({
        prompt: "What custom commands do you have available?",
        options: {
          plugins: [
            { type: "local", path: pluginPath }
          ],
          maxTurns: 3
        }
      })) {
        if (message.type === "system" && message.subtype === "init") {
          console.log("Loaded plugins:", message.plugins);
          console.log("Available commands:", message.slash_commands);
        }
    
        if (message.type === "assistant") {
          console.log("Assistant:", message.content);
        }
      }
    }
    
    runWithPlugin().catch(console.error);

    外掛程式結構參考

    外掛程式目錄必須包含 .claude-plugin/plugin.json 資訊清單檔案。它可以選擇性地包括:

    my-plugin/
    ├── .claude-plugin/
    │   └── plugin.json          # Required: plugin manifest
    ├── commands/                 # Custom slash commands
    │   └── custom-cmd.md
    ├── agents/                   # Custom agents
    │   └── specialist.md
    ├── skills/                   # Agent Skills
    │   └── my-skill/
    │       └── SKILL.md
    ├── hooks/                    # Event handlers
    │   └── hooks.json
    └── .mcp.json                # MCP server definitions

    如需有關建立外掛程式的詳細資訊,請參閱:

    • 外掛程式 - 完整外掛程式開發指南
    • 外掛程式參考 - 技術規格和結構描述

    常見使用案例

    開發和測試

    在開發期間載入外掛程式,無需全域安裝:

    plugins: [
      { type: "local", path: "./dev-plugins/my-plugin" }
    ]

    專案特定擴充功能

    在您的專案存放庫中包含外掛程式,以確保團隊範圍內的一致性:

    plugins: [
      { type: "local", path: "./project-plugins/team-workflows" }
    ]

    多個外掛程式來源

    結合來自不同位置的外掛程式:

    plugins: [
      { type: "local", path: "./local-plugin" },
      { type: "local", path: "~/.claude/custom-plugins/shared-plugin" }
    ]

    疑難排解

    外掛程式未載入

    如果您的外掛程式未出現在初始化訊息中:

    1. 檢查路徑:確保路徑指向外掛程式根目錄(包含 .claude-plugin/)
    2. 驗證 plugin.json:確保您的資訊清單檔案具有有效的 JSON 語法
    3. 檢查檔案權限:確保外掛程式目錄可讀

    命令不可用

    如果外掛程式命令不起作用:

    1. 使用命名空間:外掛程式命令需要 plugin-name:command-name 格式
    2. 檢查初始化訊息:驗證命令是否以正確的命名空間出現在 slash_commands 中
    3. 驗證命令檔案:確保命令 markdown 檔案位於 commands/ 目錄中

    路徑解析問題

    如果相對路徑不起作用:

    1. 檢查工作目錄:相對路徑從您目前的工作目錄解析
    2. 使用絕對路徑:為了可靠性,請考慮使用絕對路徑
    3. 正規化路徑:使用路徑公用程式正確建構路徑

    另請參閱

    • 外掛程式 - 完整外掛程式開發指南
    • 外掛程式參考 - 技術規格
    • 斜線命令 - 在 SDK 中使用斜線命令
    • 子代理 - 使用專門代理
    • 技能 - 使用 Agent 技能
      © 2025 ANTHROPIC PBC

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

      • AI agents
      • Code modernization
      • Coding
      • Customer support
      • Education
      • Financial services
      • Government
      • Life sciences

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      Learn

      • Blog
      • Catalog
      • Courses
      • Use cases
      • Connectors
      • Customer stories
      • Engineering at Anthropic
      • Events
      • Powered by Claude
      • Service partners
      • Startups program

      Company

      • Anthropic
      • Careers
      • Economic Futures
      • Research
      • News
      • Responsible Scaling Policy
      • Security and compliance
      • Transparency

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

      • Privacy policy
      • Responsible disclosure policy
      • Terms of service: Commercial
      • Terms of service: Consumer
      • Usage policy

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

      • AI agents
      • Code modernization
      • Coding
      • Customer support
      • Education
      • Financial services
      • Government
      • Life sciences

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      Learn

      • Blog
      • Catalog
      • Courses
      • Use cases
      • Connectors
      • Customer stories
      • Engineering at Anthropic
      • Events
      • Powered by Claude
      • Service partners
      • Startups program

      Company

      • Anthropic
      • Careers
      • Economic Futures
      • Research
      • News
      • Responsible Scaling Policy
      • Security and compliance
      • Transparency

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

      • Privacy policy
      • Responsible disclosure policy
      • Terms of service: Commercial
      • Terms of service: Consumer
      • Usage policy
      © 2025 ANTHROPIC PBC