Claude Code Adapter
openharness-claude-code (Python)
Full-featured CLI agent wrapping the Claude Agent SDK with skills, hooks, MCP integration, and subagent capabilities.
Available
v0.1.0
Claude Agent SDK
Installation
pip install openharness-claude-code
Prerequisites
The Claude Agent SDK requires the Claude Code CLI to be installed:
# macOS/Linux/WSL
curl -fsSL https://claude.ai/install.sh | bash
# Or via Homebrew (macOS)
brew install --cask claude-code
# Or via WinGet (Windows)
winget install Anthropic.ClaudeCode
Authentication
Set your Anthropic API key:
# Required: Set your API key
export ANTHROPIC_API_KEY="your-api-key"
# Alternative: Use cloud providers
# Amazon Bedrock
export CLAUDE_CODE_USE_BEDROCK=1 # + AWS credentials
# Google Vertex AI
export CLAUDE_CODE_USE_VERTEX=1 # + GCP credentials
# Microsoft Azure
export CLAUDE_CODE_USE_FOUNDRY=1 # + Azure credentials
Get your API key from the Anthropic Console. For complete setup instructions, see the official Claude Agent SDK documentation.
Quick Start
from openharness_claude_code import ClaudeCodeAdapter, ClaudeCodeConfig
from openharness.types import ExecuteRequest
# Create adapter with configuration
config = ClaudeCodeConfig(
cwd="/path/to/project",
model="sonnet",
permission_mode="acceptEdits",
)
adapter = ClaudeCodeAdapter(config)
# Execute a prompt with streaming
async for event in adapter.execute_stream(
ExecuteRequest(message="Explain this codebase")
):
if event.type == "text":
print(event.content, end="")
# Or execute synchronously
result = await adapter.execute(
ExecuteRequest(message="What does the main function do?")
)
print(result.output)
Capabilities
Full Claude Code Feature Set
This adapter wraps the Claude Agent SDK, giving you access to Claude Code's complete capabilities including built-in tools, MCP servers, skills, hooks, and subagent spawning via the Task tool.
Supported
| Domain | Capability | Notes |
|---|---|---|
| Execution | execute() | Sync execution |
| Execution | execute_stream() | Streaming execution |
| Tools | 12 built-in tools | Read, Write, Edit, Bash, Glob, Grep, etc. |
| MCP | mcp_servers config | stdio and SSE servers |
| Files | File operations | Via Read, Write, Edit, Glob, Grep tools |
| Hooks | SDK hooks system | Event-driven customization |
| Planning | TodoWrite tool | Task management |
| Subagents | Task tool | Spawn specialized agents |
| Skills | Skills system | Reusable agent capabilities |
| Models | Model switching | sonnet, opus, haiku |
Not Supported
| Domain | Reason | Workaround |
|---|---|---|
| Agents | No explicit CRUD | SDK manages internally |
| Sessions | SDK handles internally | Pass context in prompts |
| Memory | No persistent memory | Use external storage |
| Custom Tools | Uses MCP | Configure via mcp_servers |
Built-in Tools
Claude Code provides 12 built-in tools for file operations, web access, and agent orchestration:
| Tool | Description |
|---|---|
Read | Read file contents from filesystem |
Write | Write content to a file |
Edit | Edit file by replacing text |
Bash | Execute bash commands |
Glob | Find files matching glob patterns |
Grep | Search file contents with regex |
WebSearch | Search the web for information |
WebFetch | Fetch and process URL content |
Task | Launch sub-agents for complex tasks |
TodoWrite | Manage task lists for planning |
NotebookEdit | Edit Jupyter notebook cells |
AskUserQuestion | Ask user questions during execution |
Listing Tools
tools = await adapter.list_tools()
for tool in tools:
print(f"{tool.name}: {tool.description}")
Streaming
from openharness.types import ExecuteRequest
async for event in adapter.execute_stream(
ExecuteRequest(message="Refactor this function")
):
if event.type == "text":
print(event.content, end="")
elif event.type == "thinking":
print(f"[Thinking: {event.thinking}]")
elif event.type == "tool_call_start":
print(f"\n[Tool: {event.name}]")
elif event.type == "tool_result":
print(f"[Result: {event.output[:100]}...]")
elif event.type == "done":
print(f"\n[Tokens: {event.usage.total_tokens}]")
Event Types
| Event | Description |
|---|---|
text | Text content chunk |
thinking | Model's thinking/reasoning |
tool_call_start | Tool invocation beginning |
tool_result | Tool execution result |
tool_call_end | Tool invocation complete |
error | Error occurred |
done | Execution complete (includes usage stats) |
MCP Integration
Add custom tools via Model Context Protocol servers:
config = ClaudeCodeConfig(
cwd="/my/project",
mcp_servers={
# stdio server (local subprocess)
"filesystem": {
"command": "npx",
"args": ["-y", "@anthropic-ai/mcp-server-filesystem", "/tmp"],
},
# SSE server (remote)
"database": {
"uri": "https://my-mcp-server.com/sse",
},
},
)
adapter = ClaudeCodeAdapter(config)
Configuration
ClaudeCodeConfig Options
config = ClaudeCodeConfig(
model="sonnet", # Model: sonnet, opus, haiku
cwd="/path/to/project", # Working directory
system_prompt="Be helpful", # Custom system prompt
allowed_tools=["Read", "Write"], # Restrict to specific tools
permission_mode="acceptEdits", # Permission mode
mcp_servers={...}, # MCP server configuration
max_turns=10, # Maximum agent turns
env={"DEBUG": "true"}, # Environment variables
)
Permission Modes
| Mode | Description |
|---|---|
default | Prompt for all tool executions |
acceptEdits | Auto-accept file edits, prompt for commands |
plan | Plan only, no execution |
bypassPermissions | Execute all tools without prompts (use with caution) |
Available Models
| Model | Description |
|---|---|
sonnet | Claude Sonnet - balanced performance |
opus | Claude Opus - maximum capability |
haiku | Claude Haiku - fast and efficient |