A skill specializing in implementing agent integrations using the Claude Agent SDK (@anthropic-ai/claude-agent-sdk) and directly using the Anthropic SDK (@anthropic-ai/sdk). It assists with the query() API, the Hooks system, Permission Control, Electron integration, streaming handling, and Direct SDK patterns. Anchors: • Claude Agent SDK Official Docs / Applicability: SDK API, Hooks, Permissions / Purpose: Implementations that follow official patterns • Anthropic SDK (@anthropic-ai/sdk) / Applicability: Direct SDK calls / Purpose: Simple main-process integration • Electron IPC Best Practices / Applicability: Main–Renderer communication / Purpose: Secure inter-process communication • TypeScript Handbook / Applicability: Type definitions, generics / Purpose: Type-safe SDK integration Trigger: Use when implementing agent features with the Claude Agent SDK, handling streaming from the query() API, implementing a Hooks system (PreToolUse/PostToolUse), integrating with Electron, designing Permission Control, integrating MCP, or using the Direct SDK integration pattern. claude-agent-sdk, query API, PreToolUse, PostToolUse, PermissionRequest, Electron IPC, MCP, streaming, permission control, @anthropic-ai/sdk, Direct SDK
Claude Agent SDK(@anthropic-ai/claude-agent-sdk)を使用したエージェント統合の実装を専門とするスキル。query() API、Hooksシステム、Permission Control、Electron統合、ストリーミング処理を支援します。
対象言語: TypeScript のみ
SDK情報は頻繁に更新されるため、実装前に最新情報を確認してください。
# 最新情報を取得
node .claude/skills/claude-agent-sdk/scripts/fetch-latest-info.mjs
# npmパッケージ情報のみ
node .claude/skills/claude-agent-sdk/scripts/fetch-latest-info.mjs --category npm
詳細なURL一覧は references/official-urls.md を参照してください。
目的: エージェント統合の要件を理解し、適切なパターンを選定する
アクション:
references/query-api.md で基礎パターンを確認references/permission-control.md で権限設計を確認Task: agents/analyze-agent-requirements.md を参照
目的: query() APIとHooksを実装し、エージェント機能を構築する
アクション:
assets/agent-handler-template.ts を参照してIPCハンドラを実装references/hooks-system.md でHooksパターンを確認references/electron-ipc.md でElectron統合パターンを確認Task: agents/implement-agent-integration.md を参照
目的: 成果物の品質を確認し、ナレッジを記録する
アクション:
scripts/validate-agent-setup.mjs で設定の検証Task: agents/validate-agent-setup.md を参照
| Task | 概要 | 対応する Phase | リソース | | ---------------------------- | ------------------------------------------------- | -------------- | ----------------------------------------------------------------- | | query() API基本実装 | ストリーミングメッセージ処理の基本 | Phase 1, 2 | query-api.md, agent-handler-template.ts | | Verify Engine実装 | SkillCreatorVerificationEngine Layer 1-4 チェック | Phase 5, 6 | implementation-artifacts.md, electron-ipc.md | | Hooks実装 | PreToolUse/PostToolUse/Permission | Phase 2 | hooks-system.md | | Hooks Factory | createHooks, セキュリティチェック | Phase 2 | hooks-system.md(TASK-3-1-B) | | Governance Hooks Factory | Phase別 createGovernanceHooks, AuditSink連携 | Phase 2 | hooks-system.md(TASK-P0-09), permission-control.md(TASK-P0-09)| | Approval Request Producer | PreToolUse での pushApprovalRequest() 発火接続 | Phase 2 | hooks-system.md(UT-IMP-SAFETY-GOV-PUSH-REQUEST-PRODUCER-001) | | Permission Control設計 | 権限ルールの設計と実装 | Phase 1, 2 | permission-control.md | | Phase-Based Policy | plan/execute/verify/improve 別ポリシー定義 | Phase 2 | permission-control.md(TASK-P0-09) | | Electron IPC統合 | Main-Renderer間のAgent通信 | Phase 2 | electron-ipc.md | | エラーハンドリング | AbortSignal、タイムアウト、リトライ | Phase 2 | error-handling.md, hooks-system.md | | リトライ機構 | Exponential Backoff, Jitter, エラー分類 | Phase 2 | error-handling.md, retry-patterns.md | | MCP統合 | MCPサーバーとの連携 | Phase 2, 3 | mcp-integration.md | | セキュリティ設計 | サンドボックス、ホスティング | Phase 2, 3 | security-sandboxing.md | | パス制限・セキュリティ | resolvePathSafely, null byte チェック, path traversal対策 | Phase 2, 3 | security-sandboxing.md(TASK-P0-09) | | External API IPC統合 | RequestExternalApiConfig custom tool, 並行フロー, 秘匿化 | Phase 2 | electron-ipc.md(TASK-SDK-SC-03) | | Skill Output Integration | output-ready / overwrite-approved / open-skill IPC, SkillCreatorOutputHandler, SkillRegistry, SkillCreatorResultPanel | Phase 2, 3 | electron-ipc.md(TASK-SDK-SC-04) | | Persist統合(execute→SkillFileWriter) | execute() Step 3.5-3.6 で parseLlmResponseToContent → SkillFileWriter.persist、二重パイプライン設計(A経路/B経路) | Phase 2, 3 | implementation-artifacts.md(TASK-P0-05) | | Session Resume(checkpoint-based recovery) | IPC 4層統合パターン(main/ipc → service/facade → preload → renderer/hook)でセッション復元。listSessions / getSessionDetail / resumeSessionWithResult / deleteSession / cleanupExpiredSessions の5チャネル | Phase 2, 3 | electron-ipc.md(TASK-P0-08) |
| 要件 | claude-agent-sdk | 直接SDK (@anthropic-ai/sdk) |
| -------------------- | ---------------- | ----------------------------- |
| Hooks (PreToolUse等) | ✅ 必要 | ❌ 不要 |
| Permission Control | ✅ 必要 | ❌ 不要 |
| ストリーミングUI | ✅ 複雑 | ⚪ シンプル |
| Main Process専用 | ⚪ 可能 | ✅ 推奨 |
| バッチ処理 | ⚪ 可能 | ✅ 推奨 |
推奨:
@anthropic-ai/claude-agent-sdk@anthropic-ai/sdk 直接使用Main Processでシンプルなクエリを実行する場合のパターン。
import Anthropic from "@anthropic-ai/sdk";
import { safeStorage } from "electron";
import Store from "electron-store";
// APIキー管理(safeStorage + 環境変数フォールバック)
async function getApiKey(): Promise<string> {
const store = new Store<{ anthropic_api_key?: string }>();
const encrypted = store.get("anthropic_api_key");
if (encrypted && safeStorage.isEncryptionAvailable()) {
return safeStorage.decryptString(Buffer.from(encrypted, "base64"));
}
const envKey = process.env.ANTHROPIC_API_KEY;
if (envKey) return envKey;
throw new Error("API key not configured");
}
// 直接SDK呼び出し
async function executeQuery(
prompt: string,
systemPrompt?: string,
timeout = 30000,
): Promise<string> {
const client = new Anthropic({ apiKey: await getApiKey() });
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);
try {
const response = await client.messages.create(
{
model: "claude-sonnet-4-20250514",
max_tokens: 8192,
...(systemPrompt ? { system: systemPrompt } : {}),
messages: [{ role: "user", content: prompt }],
},
{ signal: controller.signal },
);
const textContent = response.content.find((b) => b.type === "text");
return textContent?.type === "text" ? textContent.text : "";
} finally {
clearTimeout(timeoutId);
}
}
📖 実装参照: apps/desktop/src/main/slide/agent-client.ts
フェーズベースのスキル実行パターン。進捗コールバック、キャンセル機能を含む。
interface SkillExecutor {
execute(
phase: SkillPhase,
projectPath: string,
): Promise<SkillExecutionResult>;
cancel(): void;
onProgress(callback: (progress: number) => void): void;
isExecuting(): boolean;
}
// スキルフェーズマッピング
const skillMap: Record<SkillPhase, string> = {
hearing: "hearing-facilitator",
structure: "structure-designer",
html: "html-generator",
modifier: "slide-modifier",
};
📖 実装参照: apps/desktop/src/main/slide/skill-executor.ts
Electron環境でのセキュアな認証キー管理パターン。Main Processでキーを安全に保持し、SkillExecutorにDIで注入する。
// AuthKeyService - 認証キーの暗号化保存・取得
interface AuthKeyService {
setKey(key: string): Promise<void>;
getKey(): Promise<string | null>;
deleteKey(): Promise<void>;
hasKey(): Promise<boolean>;
validateKey(): Promise<{ valid: boolean; error?: string }>;
}
// SkillExecutor への DI パターン
const skillExecutor = new SkillExecutor({
authKeyService, // DI で注入
retryConfig: { maxRetries: 3 },
});
// query() 呼び出し時に自動でキーを取得
const result = await skillExecutor.execute("hearing", projectPath);
認証キー解決優先順位:
options.apiKey で直接指定AuthKeyService.getKey() からの取得(Electron環境)ANTHROPIC_API_KEY📖 実装参照: apps/desktop/src/main/services/auth/AuthKeyService.ts
📖 IPC参照: apps/desktop/src/main/ipc/authKeyHandlers.ts
pnpm add @anthropic-ai/claude-agent-sdk
import { query } from "@anthropic-ai/claude-agent-sdk";
const conversation = query({
prompt: "Hello, Claude!",
options: {
tools: ["Read", "Edit"],
permissionMode: "default",
env: { ANTHROPIC_API_KEY: apiKey },
abortController: new AbortController(),
},
});
for await (const message of conversation) {
console.log(message);
}
const options = {
hooks: {
PreToolUse: async (input, toolUseID, { signal }) => {
if (input.toolName === "Bash" && input.args.command?.includes("rm -rf")) {
return {
proceed: false,
message: "危険なコマンドは許可されていません",
};
}
return { proceed: true };
},
},
};
# query() API、SDKMessage型、ストリーミング
cat .claude/skills/claude-agent-sdk/references/query-api.md
# Hooksシステム(全イベント、実装パターン)
cat .claude/skills/claude-agent-sdk/references/hooks-system.md
# Permission Control(4層システム、ルール)
cat .claude/skills/claude-agent-sdk/references/permission-control.md
# Electron IPC統合
cat .claude/skills/claude-agent-sdk/references/electron-ipc.md
# エラーハンドリング(AbortSignal、タイムアウト)
cat .claude/skills/claude-agent-sdk/references/error-handling.md
# リトライパターン(Exponential Backoff, Jitter, エラー分類)
cat .claude/skills/claude-agent-sdk/references/retry-patterns.md
# MCP統合
cat .claude/skills/claude-agent-sdk/references/mcp-integration.md
# セキュリティとサンドボックス
cat .claude/skills/claude-agent-sdk/references/security-sandboxing.md
# 公式URL一覧
cat .claude/skills/claude-agent-sdk/references/official-urls.md
# タスク別実装成果物・ファイル一覧
cat .claude/skills/claude-agent-sdk/references/implementation-artifacts.md
cat .claude/skills/claude-agent-sdk/assets/agent-handler-template.ts
cat .claude/skills/claude-agent-sdk/assets/use-agent-hook-template.ts
# 最新情報取得
node .claude/skills/claude-agent-sdk/scripts/fetch-latest-info.mjs --help
# 設定検証
node .claude/skills/claude-agent-sdk/scripts/validate-agent-setup.mjs --help
| ドキュメント | パス | 説明 |
| ----------------------------- | ------------------------------------------------------------------------------------ | ----------------------------------- |
| Agent SDKインターフェース仕様 | .claude/skills/aiworkflow-requirements/references/interfaces-agent-sdk.md | 統合システム設計仕様(型定義、IPC) |
| 実装ガイド | docs/30-workflows/claude-code-integration/outputs/phase-12/implementation-guide.md | 概念的・技術的実装ガイド |
| 実装成果物一覧 | references/implementation-artifacts.md | タスク別の成果物・実装ファイル |
タスク別の成果物・実装ファイル詳細は references/implementation-artifacts.md を参照。
下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer