Official程式設計與開發github.com

claude-api

協助你使用 Claude 建構 LLM 應用程式。根據你的需求選擇合適的介面,偵測專案語言,並閱讀對應語言的 SDK 文件。

claude-api 是什麼?

這個技能(claude-api) 是專為開發者設計的 AI Agent 技能,用於建構基於 Claude/Anthropic SDK 的 LLM 應用程式。它能自動偵測專案語言(Python、TypeScript 等),引導開發者閱讀對應語言的 SDK 文件,並強制執行一系列規則:避免混用 Anthropic SDK 與原始 HTTP 呼叫、確保使用正確的 API 形狀(例如延伸思考的 `thinking: {type: "adaptive"}` 而非已被棄用的 `budget_tokens`)、以及針對非 Anthropic 供應商程式碼提供明確的處理流程。此技能支援 Claude Code、Cursor、Codex 等開發者工具,並提供多個子命令(如 migrate、prompt-audit、upgrade、cost-optimize、build-eval 等)來執行特定的工作流程,例如模型遷移、提示審計、SDK 升級或成本最佳化。其知識庫涵蓋多種語言(Python、TypeScript、Java、Go 等)的 SDK 使用模式、工具使用概念、模型遷移指南、提示審計方法與評估建置指南,並包含 API 漂移警告,提醒開發者注意 2025-2026 年間發生的 API 形狀變更。

相容平台✓Claude Code✓Codex CLI~Cursor✓Antigravity✓Gemini CLI
npx skills add https://github.com/anthropics/skills/tree/main/skills/claude-api

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

使用 Claude 建構 LLM 應用程式

此技能協助你使用 Claude 建構 LLM 應用程式。根據你的需求選擇合適的介面,偵測專案語言,並閱讀對應語言的 SDK 文件。

開始之前

掃描目標檔案(或,如果沒有目標檔案,則掃描提示與專案)中是否有非 Anthropic 供應商標記 - import openai、from openai、langchain_openai、OpenAI(、gpt-4、gpt-5、類似 agent-openai.py 或 *-generic.py 的檔名,或任何明確指示要求保持程式碼供應商中立的指令。如果發現任何此類標記,請停止並告知使用者:此技能會產生 Claude/Anthropic SDK 程式碼;詢問他們是否要將檔案切換為 Claude,或是想要非 Claude 的實作。請勿以 Anthropic SDK 呼叫編輯非 Anthropic 的檔案。(例外情況:prompt-audit 子命令是非互動式的,不會在此處停止 - 它會在其報告的陳述假設中記錄非 Anthropic 供應商標記,且絕不會提議將非 Anthropic 檔案切換為 Anthropic SDK。)

輸出要求

當使用者要求你新增、修改或實作 Claude 功能時,你的程式碼必須透過以下其中一種*方式呼叫 Claude:

  1. 專案語言的官方 Anthropic SDK(anthropic、@anthropic-ai/sdk、com.anthropic.* 等)。只要專案有支援的 SDK,這是預設選項。
  2. 原始 HTTP(curl、requests、fetch、httpx 等)- 僅在使用者明確要求使用 cURL/REST/原始 HTTP、專案是 shell/cURL 專案,或該語言沒有官方 SDK 時使用。

絕不要混用兩者 - 即使感覺較輕量,也請勿在 Python 或 TypeScript 專案中使用 requests/fetch。絕不要退而求其次使用 OpenAI 相容的 shim。

絕不要猜測 SDK 用法。 函數名稱、類別名稱、命名空間、方法簽章與匯入路徑必須來自明確的文件 - 可以是此技能中的 {lang}/ 檔案,也可以是 shared/live-sources.md 中列出的官方 SDK 儲存庫或文件連結。如果所需的繫結未在技能檔案中明確記載,請在撰寫程式碼前,從 shared/live-sources.md 中 WebFetch 相關的 SDK 儲存庫。不要從 cURL 形狀或其他語言的 SDK 推斷 Ruby/Java/Go/PHP/C# 的 API。

如果 WebFetch 或儲存庫存取失敗(網路限制、超時、clone 被封鎖):不要持續重試 - 根據 {lang}/ 檔案中的模式與命名空間/套件表格撰寫程式碼,對其執行編譯器或直譯器,並根據錯誤輸出進行迭代。對於靜態型別 SDK(C#、Java、Go),編譯-修復迴圈針對本機錯誤比被封鎖的網路研究能更快得到可運作的程式碼。

預設值

除非使用者另有要求:

對於 Claude 模型版本,請使用 Claude Opus 5.5,你可以透過確切的模型字串 claude-opus-5-5 來存取。對於任何稍微複雜的情況,請預設使用自適應思考(thinking: {type: "adaptive"})。最後,對於任何可能涉及長輸入、長輸出或高 max_tokens 的請求,請預設使用串流 - 這可以防止請求超時。如果你不需要處理個別串流事件,請使用 SDK 的 .get_final_message() / .finalMessage() 輔助函數來取得完整回應。當串流請求定義使用者定義的(用戶端)工具時,請在每個此類工具上設定 eager_input_streaming: true,以便大的工具輸入(檔案內容、程式碼、文件)在產生時立即串流,而不是在伺服器緩衝完畢後才一次性到達;然後客戶端負責驗證:SDK 的寬容剖析器可能會傳回一個被靜默截斷的輸入而不是拋出錯誤,因此在執行每個剖析後的工具輸入之前,請根據其 schema 對其進行驗證(型別的執行器輔助函數,例如 betaZodTool / 型別的 @beta_tool 會執行此操作;betaTool() JSON-Schema 工具與手動迴圈必須自行驗證),將失敗視為無效的 JSON(當你持有該區塊時,傳回 INVALID_JSON 錯誤 tool_result,否則重新發出),在執行工具前檢查 max_tokens / refusal 停止原因,並且只捕獲 SDK 的 JSON 錯誤,絕不捕獲其型別的 API 錯誤 - 模式詳見 shared/tool-use-concepts.md -> 急切輸入串流。對於非串流請求、伺服器工具,以及當請求通過代理或較舊的 Bedrock 模型部署(會拒絕該欄位)時,請關閉此設定。

警告:API 漂移 - 你的訓練先驗知識可能已過時

幾個常見的 Claude API 形狀在 2025-2026 年間發生了變化。如果你從訓練中回憶起某個模式,請在撰寫程式碼前根據此技能中的 {lang}/ 檔案對其進行驗證 - 下表列出了最常見的漂移點:

領域過時的先驗知識目前的 API
延伸思考thinking: {type: "enabled", budget_tokens: N}在 Claude 4.6+ 模型上:thinking: {type: "adaptive"}。budget_tokens 在 Opus 4.6 / Sonnet 4.6 上已棄用,並在 Fable 5/5.1 / Sonnet 5.5 / Sonnet 5 / Opus 5.5 / 5 / 4.8 / 4.7 上拒絕並回傳 400 錯誤。4.6 之前的模型仍使用 budget_tokens。
網路搜尋 / 網路擷取工具類型web_search_20250305、web_fetch_20250910web_search_20260209、web_fetch_20260209(動態過濾)適用於 Opus 5.5/5/4.8/4.7/4.6、Sonnet 5.5、Sonnet 5 和 Sonnet 4.6。較舊的模型保留基本變體;在 Vertex AI 上僅提供基本的 web_search_20250305(Vertex 上無網路擷取)- 請參閱下面的伺服器工具 QR。
PHP 參數名稱底線分隔的 wire 名稱作為具名引數 (max_tokens)頂層具名引數是駝峰式 (maxTokens)。巢狀陣列鍵因功能而異(例如 'taskBudget'、'skillID'、'mcp_server_name')- 直接複製文件範例中的確切鍵;不要大量轉換。
受管代理程式憑證透過自訂工具在主機端保管密碼(在 vault 推出前唯一的選項)Vault environment_variable 憑證 - 由 Anthropic 儲存,在出口時替換,永遠不會在沙箱中顯示(shared/managed-agents-tools.md -> Vault)。對於自託管沙箱,主機端自訂工具仍是備用方案。
Files API / Skillsclient.beta.files.* / client.beta.skills.*,帶有 beta files-api-2025-04-14 / skills-2025-10-02已脫離 Beta:client.files.* / client.skills.*,無需 beta 標頭。在目前的 SDK 中,client.beta.files / client.beta.skills 與先前版本相比有破壞性的形狀變更,以匹配穩定的命名空間 - 請依照 shared/live-sources.md -> Files API / Skills 指南進行遷移。

此技能中的 {lang}/ 檔案對於回憶的模式具有權威性。


子命令

如果此提示底部的使用者請求是一個純粹的子命令字串(無文字說明),則搜尋此文件中的所有 子命令 表格 - 包括下面附加章節中的內容 - 並直接按照匹配的動作欄執行。這允許使用者透過 /claude-api <子命令> 來呼叫特定流程。如果文件中沒有表格匹配,則將請求視為一般的文字說明。

子命令動作
migrate將現有的 Claude API 程式碼遷移到較新的模型。立即閱讀 shared/model-migration.md 並依序執行:步驟 0(確認範圍 - 在任何編輯前詢問要遷移哪些檔案/目錄)、步驟 1(分類每個檔案),然後是針對目標模型的破壞性變更章節。不要總結指南 - 直接執行它。如果使用者沒有指定目標模型,請在同一次交流中,在提出範圍問題後一併詢問要遷移到哪個模型。在套用針對目標模型的變更後,根據 shared/prompt-audit.md 稽核範圍內的提示文字、工具描述和請求程式碼 - 為原始模型編寫的提示是每次遷移的一部分,並且它不會自行宣告。
prompt-audit稽核現有的提示、工具描述、技能和代理組態檔案(CLAUDE.md、規則檔案、命令、子代理)中是否有過時的模式(「cruft」):為較舊模型編寫的文字,以及儲存庫已不再需要或彼此矛盾的指令。立即閱讀 shared/prompt-audit.md 並依序執行:步驟 0(根據請求與儲存庫建立範圍與目標模型 - 在報告中陳述假設,不要停下來詢問)、盤點、來源,然後是模式掃描。完整產出兩項交付物 - 稽核報告(包含 檔案:行號、模式、為何過時、信心水準的發現)與提議的 diff - 無需暫停等待確認;僅當請求明確要求時才套用編輯。不要總結指南 - 直接執行它。
upgrade將專案的 Anthropic SDK 相依套件升級到主要版本 - 目前是 Python SDK anthropic 0.x -> 1.x。尾隨的字詞可以指定語言和/或範圍(upgrade python、upgrade python sdk src/)。立即閱讀 python/claude-api/sdk-upgrade.md 並依序執行:步驟 0(確認範圍,然後確定當前與目標版本 - 在寫入固定版本號碼之前必須存在已發布的 1.x 版本)、步驟 1 的盤點、每個編號章節、然後是驗證與報告。不要總結指南 - 直接執行它。如果偵測到或指定語言的此技能中沒有 sdk-upgrade.md,則表示該 SDK 尚未附帶主要版本升級指南,並引導使用者前往該 SDK 的 CHANGELOG(儲存庫位於 shared/live-sources.md);不要根據 Python 指南即興創作一個。這不是模型遷移 - 要將程式碼移動到更新的 Claude 模型,請使用 migrate。
cost-optimize在不犧牲輸出品質的情況下,降低現有 Claude API 程式碼的執行成本。立即閱讀 shared/cost-optimization.md 並依序執行:步驟 0(建立範圍、品質基準與基線)、Token 概況 - 當使用者有 Admin API 金鑰時,透過 Usage and Cost Admin API 測量;當應用程式有自己的 response.usage 日誌時,從中測量(詢問使用者);否則從程式碼中估計 - 然後是按節省成本排序的槓桿短清單(根據你擁有的資料來源,以美元、帳單百分比或相對級距報價)、免費收益(快取、輸入 Token 衛生、迴圈衛生、輸出 Token 衛生、批次),然後是權衡(預算、工作量、模型選擇、多模型);任何獲得地位的槓桿都會變成它自己的 diff - 預設提議,在使用者要求並批准時套用,並針對其所影響流量的評估進行測量 - 而「不建議變更」也是一個有效的結果。兩個常設規則:每次執行模型都會花費真實金錢,因此先獲得使用者的批准;且當缺乏某個槓桿的情境脈絡時,與使用者互動式地處理 - 此工作流程不預期一次完成稽核。不要總結指南 - 直接執行它;向使用者呈現概況與排名計畫是執行的一部分。
build-eval協助使用者為其 Claude 驅動的應用程式建立評估集。立即閱讀 shared/evals/build-eval.md 並執行其訪談:步驟 0(要評估什麼)、步驟 1(獲取提示 - 現有評估 / 逐字稿 / 合成)、步驟 2(評分方法)、步驟 3(可執行程式腳本 + 測量成本)。在產生評估之前,獲得使用者對輸入、評分方法和成本的明確同意。
preserved-thinking-migration使現有的整合相容於保留思考 - 這項檢查確保思考區塊僅在產生它的對話中有效。立即閱讀 shared/preserved-thinking-migration.md 並依序執行:步驟 0(範圍、流量類別、平台與模型、執行狀態、品質基準、基線)、步驟 0.5(使用三請求自我測試證明檢查正在執行)、步驟 1(捕獲請求主體、使用 shared/preserved-thinking-migration/prefix_diff.py 比對連續成對請求、掃描程式碼以尋找原因、命名每個編輯及其是否為蓄意)、步驟 2(在 thinking-binding-controls-2026-08-01 標頭下以 prefix_mismatch_behavior: "drop_block" 重播一個測試切片、計算每個對話中新丟棄的區塊、在存在時讀取診斷標頭)、步驟 3(每個原因一個 diff,按推理遺失的順序 - 預設提議,在使用者要求時套用 - 然後重新測量、保留或復原;當存在評估時使用三臂協議)、當主幹在不同模型間路由時,參考模型切換章節(位於 shared/preserved-thinking-migration/causes.md,包含原因表格與保留清單)、步驟 4(中斷概況與變更)。兩個常設規則:每次重播花費真實金錢,因此先獲得使用者對測量預算的批准;且「不建議變更」- 切片重播了思考且沒有任何內容被丟棄 - 是一個有效的結果。只有在較新的 beta 版本下才有僅附加形式的原因(保留尾部與背景壓縮:compact-2026-09-04;同名工具變更:inline-tools-2026-09-15)在該 beta 版本不可用時,進行測量與決定,而不是重寫。關於原因(三步驟檢查、僅附加編輯表),它連結到 shared/model-migration.md -> 破壞性變更 3;不要總結指南 - 直接執行它。
hillclimb針對現有的評估,迭代式地改善使用者的應用程式。立即閱讀 shared/evals/eval-hillclimb.md 並遵循它:步驟 0(確認存在可執行的評估 - 如果沒有,導向 build-eval)、步驟 1(要改變什麼 / 哪些不可改動)、步驟 2(根據測量的每次執行成本設定預算 + 停止條件)、獲得計畫批准,然後進行讀取->提議->套用->執行->記錄的迴圈,包含磁碟狀態與訓練/驗證/測試分割。

語言偵測

在閱讀程式碼範例之前,請判斷使用者使用的語言(例外情況:對於 prompt-audit 子命令,跳過此章節的詢問步驟 - 稽核是非互動式的,其盤點與語言無關;當無法推斷語言時,直接進行而不詢問,並在報告中陳述此假設):

  1. 查看專案檔案 以推斷語言:
  • *.py、requirements.txt、pyproject.toml、setup.py、Pipfile -> Python - 從 python/ 讀取
  • *.ts、*.tsx、package.json、tsconfig.json、yarn.lock、pnpm-lock.yaml -> TypeScript - 從 typescript/ 讀取

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists

anthropics/template-skill

Replace with description of the skill and when Claude should use it.

brand-guidelines

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

canvas-design

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists

discernment-nudge

After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

docx

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of

frontend-design

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

internal-comms

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

pdf

Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.

pptx

Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions \

skill-creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill

slack-gif-creator

Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like

theme-factory

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

web-artifacts-builder

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

xlsx

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \

相關技能