Agent HTTP: Add a Production-Ready HTTP API to Claude Code in 2 Minutes

Agent HTTP: Add a Production-Ready HTTP API to Claude Code in 2 Minutes

Agent HTTP is an MCP server that gives Claude Code a native HTTP API, letting you programmatically send tasks and stream responses without terminal scraping.

7h ago·3 min read·9 views·via hn_claude_code
Share:

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

  1. CI/CD Integration: Have Claude Code review PRs or run tests automatically
  2. Internal Tools: Build custom dashboards that delegate coding tasks
  3. Multi-Agent Systems: Use Claude Code as one agent in a larger system
  4. Monitoring: Stream Claude's progress on long-running refactors
  5. 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: --port flag > CLAUDE_HTTP_PORT env > 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.

AI Analysis

Claude Code users should immediately install Agent HTTP if they want to integrate Claude Code into automated workflows. This is a game-changer for anyone building tools around Claude Code. First, use the built-in web chat interface at `localhost:8080/chat` to test the API without writing any code. Send a few messages and watch how they appear in the `/messages` endpoint. This will help you understand the message structure before building your own integration. Second, start with the Server-Sent Events endpoint for any real-time applications. Instead of polling `/status` or `/messages`, connect to `/events` once and let the server push updates to you. This is more efficient and gives you immediate feedback when Claude starts or finishes tasks. Third, consider replacing any existing agentapi integrations with Agent HTTP if you're only using Claude Code. The native channel protocol is more reliable than terminal scraping, and you'll avoid the heuristics that can break when Claude Code updates its TUI.
Original sourcegithub.com

Trending Now

More in Products & Launches

Browse more AI articles