Claude Agent SDK: Recommended PocketPaw Backend
The Claude Agent SDK backend is the recommended choice for PocketPaw. It uses Anthropic’s official SDK with built-in tools and native MCP support.
Overview
This backend leverages the claude-agent-sdk package, which provides:
- Built-in tools: Bash, Read, Write, Edit — managed by the SDK
- Tool execution hooks:
PreToolUsehooks for dangerous command blocking - MCP integration: Native Model Context Protocol server support
- Streaming: Real-time token-by-token response streaming
Authentication
An Anthropic API key is required when using this backend with the Anthropic provider. This is a hard requirement — PocketPaw will not process messages without one.
OAuth tokens are not permitted. Anthropic’s authentication policy prohibits third-party applications from using OAuth tokens obtained through Claude Free, Pro, or Max plans. PocketPaw must authenticate using an API key from Claude Console.
Get an API key
Go to console.anthropic.com/api-keys and create a new key.
Set the key
Add it as an environment variable, in the dashboard Settings, or in ~/.pocketpaw/config.json:
export POCKETPAW_ANTHROPIC_API_KEY="sk-ant-..."This requirement only applies to the Anthropic provider. If you use Ollama (local models), no API key is needed.
Configuration
export POCKETPAW_AGENT_BACKEND="claude_agent_sdk"export POCKETPAW_ANTHROPIC_API_KEY="sk-ant-..."Claude SDK Settings
These settings apply specifically to the Claude Agent SDK backend:
| Setting | Env Variable | Default | Description |
|---|---|---|---|
claude_sdk_model | POCKETPAW_CLAUDE_SDK_MODEL | "" (auto) | Model override. Leave empty to let Claude Code auto-select the best model (recommended). |
claude_sdk_max_turns | POCKETPAW_CLAUDE_SDK_MAX_TURNS | 25 | Maximum tool-use turns per query. Safety net against runaway tool loops. |
# Let Claude Code auto-select the model (recommended — no override needed)export POCKETPAW_CLAUDE_SDK_MODEL=""
# Or force a specific modelexport POCKETPAW_CLAUDE_SDK_MODEL="claude-sonnet-4-5-20250929"
# Increase max turns for complex multi-step tasksexport POCKETPAW_CLAUDE_SDK_MAX_TURNS=50Why let Claude Code auto-select? Claude Code has its own sophisticated model routing that picks the best model for each task. Setting an explicit model override disables this. Only override if you have a specific reason (e.g., cost control or testing).
Smart Model Routing conflict: PocketPaw’s Smart Model Router (in Settings → Behavior) is disabled by default because it conflicts with Claude Code’s built-in routing. Enabling it will override Claude Code’s model selection, which may produce worse results.
Provider Support
| Provider | How |
|---|---|
| Anthropic | Native (default) |
| Ollama | Ollama v0.14+ Anthropic API support |
| LiteLLM | Routes through proxy via ANTHROPIC_BASE_URL |
| OpenAI-Compatible | Only if endpoint speaks Anthropic format |
Using with Ollama
export POCKETPAW_AGENT_BACKEND="claude_agent_sdk"export POCKETPAW_LLM_PROVIDER="ollama"export POCKETPAW_OLLAMA_MODEL="qwen2.5:7b"See Ollama (Local LLMs) for full setup instructions.
Using with LiteLLM
export POCKETPAW_AGENT_BACKEND="claude_agent_sdk"export POCKETPAW_CLAUDE_SDK_PROVIDER="litellm"export POCKETPAW_LITELLM_API_BASE="http://localhost:4000"export POCKETPAW_LITELLM_MODEL="gpt-4o"The adapter sets ANTHROPIC_BASE_URL to point at the LiteLLM proxy, so the Claude SDK sends Anthropic-format requests to the proxy which translates them for the target provider.
Built-in Tools
The Claude Agent SDK provides these tools natively:
| SDK Tool | Description |
|---|---|
Bash | Execute shell commands |
Read | Read files from the filesystem |
Write | Write/create files |
Edit | Edit existing files with search/replace |
Skill | Execute skills from SKILL.md files |
Tool Name Mapping
The SDK uses capitalized tool names internally. PocketPaw maps these to the policy system’s snake_case names:
| SDK Name | Policy Name |
|---|---|
Bash | shell |
Read | read_file |
Write | write_file |
Edit | edit_file |
Skill | skill |
This mapping is handled by _TOOL_POLICY_MAP in the backend’s info() method.
Safety Hooks
The backend uses PreToolUse hooks to intercept and block dangerous commands before execution:
# Example: Blocking destructive shell commandsasync def pre_tool_use(tool_name, tool_input): if tool_name == "Bash": command = tool_input.get("command", "") if is_dangerous_command(command): return BlockedResponse("This command has been blocked for safety.")MCP Server Integration
The Claude Agent SDK has native MCP support. PocketPaw’s _get_mcp_servers() function translates MCP server configurations into the SDK’s expected format:
# MCP servers are loaded from ~/.pocketpaw/mcp.json# and passed to the SDK during initializationservers = _get_mcp_servers()MCP tools are subject to the tool policy system. Use mcp:<server>:* patterns in allow/deny lists:
# Allow all tools from a specific MCP serverexport POCKETPAW_TOOLS_ALLOW="mcp:filesystem:*"
# Deny all MCP toolsexport POCKETPAW_TOOLS_DENY="group:mcp"Custom Tools
In addition to the SDK’s built-in tools, PocketPaw registers its own tools (web_search, image_gen, etc.) as custom tool definitions passed to the SDK.
Skill Auto-Discovery
The backend passes setting_sources=["user", "project"] to the SDK, enabling automatic discovery of SKILL.md files from:
~/.claude/skills/— User-level skills.claude/skills/— Project-level skills
This means skills created by the skill_gen tool (which writes to ~/.claude/skills/) are automatically available to the SDK without additional configuration.
Response Format
The backend yields standardized AgentEvent objects (not raw dicts):
AgentEvent(type="message", content="Here's the result...")AgentEvent(type="tool_use", content="", metadata={"tool": "Bash", "input": {"command": "ls"}})AgentEvent(type="tool_result", content="file1.txt\nfile2.txt", metadata={"tool": "Bash"})AgentEvent(type="done", content="")All backends use the same AgentEvent format, defined in agents/backend.py.
Related
Ollama: Run with Free Local Models
Use the Claude Agent SDK with local models via Ollama — no API keys needed.
OpenAI Agents SDK
Alternative backend using OpenAI’s agent framework with GPT models.
All Agent Backends
Compare all six backends side by side with capability badges.
Self-Host PocketPaw
Deploy PocketPaw on your own server with the Claude Agent SDK backend.