Install
$ agentstack add mcp-bethington-claude-code-api ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ● Network access Used
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ● Environment & secrets Used
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
Claude Code API
OpenAI-compatible API wrapper for Claude Code CLI. Enables any OpenAI-compatible client (like opencode) to use Claude Code's full capabilities including file editing, bash execution, and tool use.
Features
- OpenAI-compatible API - Works with any client that supports OpenAI's chat completions API
- Hybrid pool architecture - Hot workers for active conversations, automatic eviction of idle workers
- Conversation persistence - Sessions saved to disk, can be resumed later
- Streaming support - Real-time SSE streaming responses
- Docker ready - Easy deployment with Docker Compose
Quick Start
- Clone and configure:
``bash cd claude-code-api cp .env.example .env # Edit .env and add your ANTHROPIC_API_KEY ``
- Start with Docker Compose:
``bash docker-compose up -d ``
- Test the API:
```bash curl http://localhost:3000/health
curl -X POST http://localhost:3000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model":"claude-code","messages":[{"role":"user","content":"Hello!"}]}' ```
API Endpoints
Chat Completions (OpenAI-compatible)
POST /v1/chat/completions
Request:
{
"model": "claude-code",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}
Conversation ID: Specify via:
X-Conversation-IDheader (recommended)- Model suffix:
"model": "claude-code:my-conversation" - Auto-generated if not provided
Other Endpoints
| Endpoint | Method | Description | |----------|--------|-------------| | /health | GET | Health check and stats | | /v1/models | GET | List available models | | /conversations | GET | List active conversations | | /conversations/:id | DELETE | Evict a conversation |
Configuration with opencode
Add to your opencode.json:
{
"provider": {
"claude-code": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://localhost:3000/v1"
},
"models": {
"claude-code": {
"limit": {
"context": 200000,
"output": 64000
}
}
}
}
}
}
Environment Variables
| Variable | Default | Description | |----------|---------|-------------| | ANTHROPIC_API_KEY | (required) | Your Anthropic API key | | POOL_SIZE | 5 | Maximum concurrent workers | | IDLE_TIMEOUT_MS | 300000 | Worker idle timeout (5 min) | | PORT | 3000 | Server port | | WORKSPACE_DIR | /workspace | Working directory for Claude |
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Docker Container │
│ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Express.js API Server (server.js) │ │
│ │ POST /v1/chat/completions (OpenAI-compatible) │ │
│ └────────────────────────┬───────────────────────────┘ │
│ │ │
│ ┌────────────────────────▼───────────────────────────┐ │
│ │ Hybrid Pool Manager (pool.js) │ │
│ │ - Session affinity routing │ │
│ │ - LRU eviction when at capacity │ │
│ │ - Automatic idle cleanup │ │
│ └────────────────────────┬───────────────────────────┘ │
│ │ │
│ ┌────────────────────────▼───────────────────────────┐ │
│ │ Claude Code Workers (worker.js) │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │Worker 1 │ │Worker 2 │ │Worker 3 │ ... │ │
│ │ │conv-abc │ │conv-xyz │ │ (idle) │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │
│ │ claude -p --input-format stream-json │ │
│ │ --output-format stream-json │ │
│ │ --session-id │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Session Storage: /root/.claude/ │
└──────────────────────────────────────────────────────────────┘
Development
Run locally (without Docker):
npm install
export ANTHROPIC_API_KEY=sk-ant-...
npm start
Run with file watching:
npm run dev
License
MIT
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: bethington
- Source: bethington/claude-code-api
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.