Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
An introduction to Claude Code SDK
Search
Akihiro Okuno
July 17, 2025
Technology
4.8k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
An introduction to Claude Code SDK
Akihiro Okuno
July 17, 2025
More Decks by Akihiro Okuno
See All by Akihiro Okuno
My 4 months with Nix
choplin
0
95
Hack Claude Code with Claude Code
choplin
8
3.8k
Introduction to ScalarDB and ScalarDB Analytics
choplin
0
460
Walk around functional web frontend programming
choplin
2
1.1k
Pre ScalaMatsuri 2020
choplin
2
200
Other Decks in Technology
See All in Technology
AIエージェントを雇う前に決める5つのこと
knishioka
1
130
いかに伝えるか 〜新卒エンジニアの教育のための、ライトノベル活用の一例
ikedon
1
140
VPCでもFloatingIPを使いたいんだ
y_kotani
1
140
本番に近いテストをもっと手軽に - Postmanで広がるAPIテストの世界 / Expanding the World of API Testing with Postman
yokawasa
1
200
どんな手を使っても絶対間に合わせるスケジューラ
asari194617
0
1.5k
20260903 Tokyo Jazug Night #62 | Azure エンジニアよ、 その環境は本当にセキュアか?
olivia_0707
0
230
Does an AI Watermark Survive Translation?
machinetranslation
0
510
Hub & Spoke 環境のネットワークルーティングを分解してみる
tsuyataku
1
490
指示待ちから変化に応じるClaude Codeへ!~環境からAgentへの帰り道を作る~
gotalab555
9
1.8k
Kiro Crewしか勝たん!?
miu_crescent
PRO
0
100
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
330
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.5k
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
480
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
230
Scaling GitHub
holman
464
140k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
WENDY [Excerpt]
tessaabrams
12
39k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
570
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
290
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
YesSQL, Process and Tooling at Scale
rocio
174
15k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.6k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Transcript
Claude Code SDKの話 2025年7月17日 - #claudecode_findy Akihiro Okuno (@choplin) 1
Akihiro Okuno 株式会社Scalar 何をしている人? データベースの中の技術が好き データベース関連のミドルウェアウェア開 発 Links X: twitter.com/choplin
GitHub: github.com/choplin Claude Code活動 6月にClaude Maxで利用開始 Claude Codeが色々足りてないので周辺ツ ールを作り始める 作ったツール cclog: セッションログ管理CLI code-review.nvim: Neovimプラグイン mcp-gemini-cli: Gemini連携MCP amux(WIP): tmux+worktree管理 vault.md(WIP): Context Engineeringのため の文書管理 自己紹介 2
1. Opus 4の自走力 高度な推論能力と実装力 2. エージェントとしての自律性 計画・実行・修正の自動化 3. CLIの親和性 既存の開発フローに統合
+ 月額固定 コストを気にせず使い放題 Claude Codeの何がすごいのか? 参考: 「Claude CodeでClaude Codeをハックする」 https://speakerdeck.com/choplin/hack-claude-code-with-claude-code 3
既存の開発フローとの親和性 シェル: alias, function, スクリプト化 セッション: tmux/screenで並行作業 CI/CD: GitHub Actions,
Jenkins統合 テキストベースでの連携 履歴: ~/.claude/ にjsonl保存 検索: grep, jq, awkで自在に処理 再利用: セッション再開、プロンプト共有 コミュニティの拡張例 sniffle (Chip Huyen) / vibe-kanban (BloopAI) / cclog (自作) / code-review.nvim (自作) CLIの強み 4
Claude Codeをアプリケーションに統合するためのライブラリ https://docs.anthropic.com/en/docs/claude-code/sdk Claude Codeをサブプロセスとして実行 Claude Code SDKとは? ...SDK? 🤔
5
CLI SDK claude -p " コードをレビューして" TypeScript SDK import {
query } from "@anthropic-ai/claude-code"; for await (const message of query({ prompt: " コードをレビューして" })) { console.log(message); } Python SDK from claude_code_sdk import query async for message in query(prompt=" コードをレビューして"): print(message) SDKの使い方 6
@anthropic-ai/claude-code/sdk.mjs function query({ prompt, options: { // ... executable =
isRunningWithBun() ? "bun" : "node", // ... pathToClaudeCodeExecutable = join(__dirname2, "cli.js"), // ← claude コマンドの実体 } = {}, }) { // ... const child = spawn( executable, [...executableArgs, pathToClaudeCodeExecutable, ...args], { /* spawn options */ }, ); } TypeScript SDKの内部実装 CLIをサブプロセスとして実行している 7
非インタラクティブモードの必要性 通常のClaude Code: 対話的なセッションを開始 SDKやスクリプトから使う場合: ユーザー入力を待たない -p, --print オプション: 応答を出力して対話モードに入らない
# 通常(インタラクティブ) claude " コードを分析して" # → 対話セッションが開始 # -p オプション(非インタラクティブ) claude -p " コードを分析して" # → 応答を出力(対話モードなし) # パイプで他のコマンドと連携 echo "Explain this code" | claude -p CLI SDKの最重要オプション 8
出力形式オプション # JSON 形式で出力(スクリプティングに最適) claude -p " ファイルを読んで" --output-format json
# JSON Lines 形式でストリーミング出力 claude -p " コードを分析して" --output-format stream-json # 入出力を両方JSON Lines に claude -p --output-format stream-json --input-format stream-json セッション管理オプション # 最新の会話を継続 claude --continue # 特定のセッションID から再開 claude --resume abc123def456 CLI SDKのオプション 9
その他のオプション --system-prompt : カスタムシステムプロンプトを設定 --permission-prompt-tool : ツール使用の許可をプロンプトで確認 --max-turns : エージェントのターン数を制限
CLIのSDKのオプション 10
Claude Code CLI 強み: 既存の開発フローとの親和性 プログラマブル: JSON出力、セッション管理 拡張性: シェルスクリプト、CI/CD統合 Claude
Code SDK 実体: CLIをサブプロセスとして実行するラッパー 利点: 既存のCLI機能をそのまま活用可能 対応言語: TypeScript, Python (CLIを直接使えば何でも) まとめ 11