Anthropic has developed the ultimate coding agent, Claude Code, which stands out as the premier tool for learning about agents. My previous methods of reading documentation and source code are now vastly inferior and significantly less efficient than utilizing this powerful tool.
Here is a demo on how it helps me learn two agents SDKs, one is Claude the other is OpenAI.
๐ Claude Agent SDK for Python – Quick Learning Guide
๐ฏ What is it?
The Claude Agent SDK is a Python library that lets you build AI agents powered by Claude. It’s built on top of the same infrastructure that powers Claude Code (the CLI tool you’re using right now).
Key Difference from OpenAI Agents SDK:
- OpenAI SDK: You manage everything (conversation, tools, state)
- Claude SDK: Built-in context management, integrated with Claude Code, hooks system
๐ Two Ways to Use It
- Simple Mode: query() – One-off Questions, no conversation history needed
- Conversation Mode: ClaudeSDKClient – Multi-turn Chat, keep context across queries
๐ ๏ธ Custom Tools – The Power Feature
What are Tools? Functions that Claude can call to do things (like your MCP tools: RBICS, NSS, etc.) key benefits is in-progress, no subprocess management like my current MCP server, type-safe, easy to debug and better performance.
๐ฃ Hooks – Intercept Agent Behavior
Hooks let you run code at specific points in the agent’s execution: there are preToolUse, PosttoolUse, UserPromptSubmit these hook events
โ๏ธ Configuration: ClaudeAgentOptions
๐ Connecting to Your Existing MCP Server
๐ Comparison: Claude SDK vs OpenAI Agents SDK
| Feature | Claude Agent SDK | OpenAI Agents SDK |
|---|---|---|
| Context Management | Built-in | Manual (SQLiteSession) |
| Tool Definition | @tool decorator | @function_tool |
| MCP Integration | Native, in-process | Via subprocess (stdio) |
| Streaming | Built-in AsyncIterator | Manual setup |
| Hooks | Yes (PreTool, PostTool) | Via Agent lifecycle |
| Conversation State | ClaudeSDKClient manages | You manage Sessions |
| Azure Support | Standard Claude API | Custom client needed |
First test run simple query
import anyio
from claude_agent_sdk import query
async def main():
print("Testing Claude Agent SDK...")
print("="*60)
async for message in query(prompt="What is 2 + 2? Just give me the number."):
print(message)
print("="*60)
print("Success! SDK is working.")
if __name__ == "__main__":
anyio.run(main)
succeeded:
Response:
------------------------------------------------------------
SystemMessage(subtype='init', data={'type': 'system', 'subtype': 'init', 'cwd': 'C:\\Users\\ncarucci\\Documents\\Gitfolder\\index-solution-agent-claude', 'session_id': '1f0172a1-9607-4c95-a94b-aa2a9ad2708c', 'tools': ['Task', 'Bash', 'Glob', 'Grep', 'ExitPlanMode', 'Read', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'BashOutput', 'KillShell', 'SlashCommand'], 'mcp_servers': [], 'model': 'claude-sonnet-4-5-20250929', 'permissionMode': 'default', 'slash_commands': ['compact', 'context', 'cost', 'init', 'output-style:new', 'pr-comments', 'release-notes', 'todos', 'review', 'security-review'], 'apiKeySource': 'none', 'output_style': 'default', 'agents': ['general-purpose', 'statusline-setup', 'output-style-setup'], 'uuid': '6941aa07-3eb4-4ced-9793-a22e67da4dae'})
AssistantMessage(content=[TextBlock(text='4')], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
29', parent_tool_use_id=None)
ResultMessage(subtype='success', duration_ms=1812, duration_api_ms=1745, is_error=False, num_turns=1, session_id='1f0172a1-9607-4c95-a94b-aa2a9ad2708c', total_cost_usd=0.0361536, usage={'input_tokens': 3, 'cache_creation_input_tokens': 9184, 'cache_read_input_tokens': 5432, 'output_tokens': 5, 'server_tool_use': {'web_search_requests': 0}, 'service_tier': 'standard', 'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 9184}}, result='4')