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

DomainCapabilityNotes
Executionexecute()Sync execution
Executionexecute_stream()Streaming execution
Tools12 built-in toolsRead, Write, Edit, Bash, Glob, Grep, etc.
MCPmcp_servers configstdio and SSE servers
FilesFile operationsVia Read, Write, Edit, Glob, Grep tools
HooksSDK hooks systemEvent-driven customization
PlanningTodoWrite toolTask management
SubagentsTask toolSpawn specialized agents
SkillsSkills systemReusable agent capabilities
ModelsModel switchingsonnet, opus, haiku

Not Supported

DomainReasonWorkaround
AgentsNo explicit CRUDSDK manages internally
SessionsSDK handles internallyPass context in prompts
MemoryNo persistent memoryUse external storage
Custom ToolsUses MCPConfigure via mcp_servers

Built-in Tools

Claude Code provides 12 built-in tools for file operations, web access, and agent orchestration:

ToolDescription
ReadRead file contents from filesystem
WriteWrite content to a file
EditEdit file by replacing text
BashExecute bash commands
GlobFind files matching glob patterns
GrepSearch file contents with regex
WebSearchSearch the web for information
WebFetchFetch and process URL content
TaskLaunch sub-agents for complex tasks
TodoWriteManage task lists for planning
NotebookEditEdit Jupyter notebook cells
AskUserQuestionAsk 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

EventDescription
textText content chunk
thinkingModel's thinking/reasoning
tool_call_startTool invocation beginning
tool_resultTool execution result
tool_call_endTool invocation complete
errorError occurred
doneExecution 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

ModeDescription
defaultPrompt for all tool executions
acceptEditsAuto-accept file edits, prompt for commands
planPlan only, no execution
bypassPermissionsExecute all tools without prompts (use with caution)

Available Models

ModelDescription
sonnetClaude Sonnet - balanced performance
opusClaude Opus - maximum capability
haikuClaude Haiku - fast and efficient