Agent HTTP: Add a Production-Ready HTTP API to Claude Code in 2 Minutes
What It Does
Agent HTTP is an open-source MCP server that exposes Claude Code as a proper HTTP API. Instead of screen-scraping terminal output or parsing TUI artifacts, it uses Claude Code's native channel protocol to send messages directly and receive responses cleanly.
This means you can now:
- Send coding tasks to Claude Code via HTTP requests
- Get structured JSON responses back
- Stream responses in real-time via Server-Sent Events
- Integrate Claude Code into your existing tools and workflows
Setup
First, install the prerequisites:
# Install Bun if you don't have it
curl -fsSL https://bun.sh/install | bash
# Clone and install agent-http
git clone https://github.com/mberg/agent-http.git
cd agent-http
bun install
Then configure Claude Code to load the channel. Create or update .mcp.json in your project root:
{
"mcpServers": {
"http-router": {
"command": "bun",
"args": ["./http.ts", "--port", "8080"]
}
}
}
Start Claude Code with the channel loaded:
claude --dangerously-load-development-channels server:http-router
The HTTP API will start on port 8080 (or 3284 if you don't specify a port).
API Endpoints You Can Use Right Now
Send a Message
# Send structured JSON
curl -X POST localhost:8080/message \
-H "Content-Type: application/json" \
-d '{"content": "Refactor this function to use async/await", "type": "user"}'
# Or send plain text
curl -X POST localhost:8080/message -d "What files are in this directory?"
Both return immediately with {"ok": true, "chat_id": "1"} once Claude starts processing.
Get Message History
curl localhost:8080/messages
Returns an array of all messages in the conversation with timestamps and roles.
Stream Real-Time Responses
curl -N localhost:8080/events
This Server-Sent Events stream broadcasts message and status events as they happen. Perfect for building chat interfaces or monitoring long-running tasks.
Check Status
curl localhost:8080/status
Returns {"status": "stable"} when idle or {"status": "running"} when processing.
Why This Beats Terminal Scraping
Traditional approaches like agentapi work by running CLI tools in virtual terminals and parsing screen output. This breaks when:
- Terminal UI artifacts appear in output
- CLI tools update their formatting
- ANSI escape sequences change
- You need exact message boundaries
Agent HTTP uses Claude Code's native channel protocol, so messages are exact. No terminal diffing, no TUI artifact stripping, no heuristics that break on updates.
Built-in Web Chat Interface
For testing and demos, navigate to:
http://localhost:8080/chat
This web interface connects to the same API endpoints. Messages sent from the chat UI show up in /messages and vice versa, making it perfect for debugging your integrations.
Use Cases
- CI/CD Integration: Have Claude Code review PRs or run tests automatically
- Internal Tools: Build custom dashboards that delegate coding tasks
- Multi-Agent Systems: Use Claude Code as one agent in a larger system
- Monitoring: Stream Claude's progress on long-running refactors
- Education: Build interactive coding tutorials with Claude as the tutor
Compatibility Notes
- Requires Claude Code v2.1.80+
- Compatible with agentapi's API format (POST
/message, GET/messages, etc.) - Can serve as a drop-in replacement for agentapi in projects that only need Claude Code support
- Priority for port:
--portflag >CLAUDE_HTTP_PORTenv > 3284 default
Next Steps
The repository includes TypeScript examples for programmatic usage. Since it's open source, you can fork it to add authentication, rate limiting, or custom endpoints specific to your workflow.
This changes Claude Code from a terminal-only tool to a programmable service you can integrate into any system that speaks HTTP.





