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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akihiro Okuno
July 17, 2025
Technology
4.7k
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
72
Hack Claude Code with Claude Code
choplin
8
3.7k
Introduction to ScalarDB and ScalarDB Analytics
choplin
0
440
Walk around functional web frontend programming
choplin
2
1.1k
Pre ScalaMatsuri 2020
choplin
2
200
Other Decks in Technology
See All in Technology
LayerX コーポレートエンジニアリング室におけるサプライチェーンセキュリティへの取り組み / Supply Chain Security at LayerX Corporate Engineering
yuyatakeyama
2
590
AIの性能が向上しても未解決な組織の重大問題は何か?/An Unsolved Organizational Problem in the Age of AI
moriyuya
4
680
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
0
2.3k
2026年6月23日 Syncable Tech + Start Python Club にて
hamukazu
0
120
SONiCで構築・運用する生成AI向けパブリッククラウドネットワーク ~実装編~
sonic
0
220
GitHub Copilot 最新アップデート – 「一歩先」の実践活用術
moulongzhang
4
1.1k
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
4
2.4k
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
1.1k
データサイエンスを価値につなげるプロジェクト設計 〜 DS一年目が現場で得た気づき 〜
ysd113
1
260
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
7k
SONiCの統計情報を取得したい
sonic
0
180
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
1.1k
Featured
See All Featured
Navigating Team Friction
lara
192
16k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
710
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
140
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
Embracing the Ebb and Flow
colly
88
5.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
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