claude-code-sdk

claude-code-sdk is a skill for Claude Code, Codex from miles990/claude-software-skills. It costs 20 tokens per session (3,887 once invoked), scanned A, original, MIT.

A Python software development kit for adding Claude AI agent features to applications. It supports OAuth login through Claude and API-key authentication.

In plain words
What is it for?
Use it for applications that need Claude to generate code, work with files, run terminal commands, search files, fetch web pages, or handle multi-step conversations.
Why use it?
It provides an application interface for sending requests to Claude and receiving responses without building the integration from scratch.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: reads .claude/ paths; mentions Claude Code.

Good fit Use it for applications that need Claude to generate code, work with files, run terminal commands, search files, fetch web pages, or handle multi-step conversations.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/miles990/claude-software-skills/claude-code-sdk
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add miles990/claude-software-skills --skill claude-code-sdk
Clone the repo
git clone --depth 1 https://github.com/miles990/claude-software-skills

Made for: Claude Code, Codex.

Its marketplace also offers this one on its own, as the plugin claude-code-sdk/plugin install claude-code-sdk after adding the marketplace above.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for claude-code-sdk

README.md
[![agentmods](https://agentmods.dev/badge/skills/miles990/claude-software-skills/claude-code-sdk.svg)](https://agentmods.dev/skills/miles990/claude-software-skills/claude-code-sdk)
Your own site
<a href="https://agentmods.dev/skills/miles990/claude-software-skills/claude-code-sdk"><img src="https://agentmods.dev/badge/skills/miles990/claude-software-skills/claude-code-sdk.svg" alt="Measured on agentmods" height="20"></a>
Per session 20 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,887 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. ✓ AI security review Sonnet 5 · 7 Sept 2026 📄 Read the review
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00020 $0.03887
Opus 5 $0.00010 $0.01944
Sonnet 5 $0.00004 $0.00777
Haiku 4.5 $0.00002 $0.00389

Measured 8d ago against content hash 58501bf8aee8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

claude-code-sdk scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

tools-integrations/claude-code-sdk/SKILL.md · 513 lines

How it starts

The opening of the file, as written. The whole thing — 513 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Claude Code SDK Integration

Overview

Claude Code SDK (claude-code-sdk) 是 Anthropic 官方提供的 Python 套件,用於在應用程式中整合 Claude AI Agent 功能。它支援 OAuth 認證(透過 claude login)和 API Key 認證,讓開發者可以利用 Claude Max/Pro 訂閱或 API 計費方案。這個 SDK 是建立 AI-powered 應用程式的關鍵工具,特別適合需要程式碼生成、檔案操作、或多輪對話的場景。

Key Concepts

認證方式

Description: Claude Code SDK 支援兩種認證方式 Key Features:

  • OAuth 認證: 使用 claude login 後存儲在 ~/.claude/ 的憑證
  • API Key 認證: 透過 ANTHROPIC_API_KEY 環境變數

Use Cases:

  • OAuth:個人開發、有 Max/Pro 訂閱的用戶
  • API Key:生產環境、需要計量計費的服務

SDK 核心 API

Description: query() 函數是主要的非同步介面 Key Features:

  • 非同步迭代器回傳訊息
  • 支援 streaming 和完整回應
  • 可配置工具權限和執行限制

Use Cases: 程式碼生成、檔案操作、研究任務、唯讀分析

工具類型 (ToolType)

Description: SDK 支援多種內建工具 Key Features:

  • READ, WRITE, EDIT - 檔案操作
  • BASH - 終端命令執行
  • GLOB, GREP - 檔案搜尋
  • WEB_FETCH - 網頁抓取

Best Practices

  1. 雙重認證檢查
    • 同時支援 OAuth 和 API Key
    • 優先使用 OAuth(免費使用 Max/Pro 配額)
    • API Key 作為後備方案
def check_auth_status() -> dict:
    status = {
        'api_key_set': bool(os.environ.get('ANTHROPIC_API_KEY')),
        'oauth_logged_in': False,
    }

    # 檢查 OAuth 登入狀態
    claude_dir = os.path.expanduser('~/.claude')
    if os.path.exists(claude_dir):
        auth_files = ['credentials.json', 'settings.json', '.credentials.json']
        for auth_file in auth_files:
            if os.path.exists(os.path.join(claude_dir, auth_file)):
                status['oauth_logged_in'] = True
                break

    # 只需要其中一種認證
    status['auth_available'] = status['api_key_set'] or status['oauth_logged_in']
    return status
  1. 增加 Buffer Size
    • 預設 buffer 太小,處理大型回應會出錯
    • 建議增加到 50MB
try:
    from claude_code_sdk._internal.transport import subprocess_cli
    subprocess_cli._MAX_BUFFER_SIZE = 50 * 1024 * 1024  # 50MB
except Exception as e:
    print(f"Failed to patch SDK buffer size: {e}")
  1. 使用 Singleton Pattern
    • 避免重複初始化
    • 共享狀態和配置
_claude_service: Optional['ClaudeCodeService'] = None

def get_claude_code() -> 'ClaudeCodeService':
    global _claude_service
    if _claude_service is None:
        _claude_service = ClaudeCodeService()
    return _claude_service

Read the full file on GitHub · 513 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 513 lines · 20 tokens per session scan F 58501bf8aee8

Subscribe to this mod's changes

claude-code-sdk is a skill published in the GitHub repository miles990/claude-software-skills (20 stars, last pushed 7mo ago), licensed MIT. It adds 20 tokens to every session and 3,887 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.