DEV Community

Adrian Issac
Adrian Issac

Posted on AI-assisted

I turned a Claude Code session into a local Anthropic-compatible API

I wanted tools like LiteLLM and Hermes Agent to talk to my Claude Code session as if it were a normal Anthropic API. So I built ccapi.

What it does

ccapi exposes /v1/messages on localhost. Any client that speaks the Anthropic Messages API (the Anthropic SDK, LiteLLM, Hermes Agent) can point at it. Streaming, tool calls, images, PDFs and thinking come through.

How it works

  • Two Claude Code mods plus a small Bun server.
  • Each incoming request runs as a Claude Code subagent.
  • Client tools are registered as native Claude Code tools. When the client sends back a tool result, it resumes the same subagent.
  • A systemd user unit keeps the tmux session alive for 24/7 use.

What I learned

  • The Claude Code mods API is early access, so anything can change.
  • Keeping it up 24/7 needed a supervisor that restarts the session when it dies.
  • Tool calls are the hard part: parked calls need deadlines and slot cleanup, or failures leak sessions.

Limits

  • max_tokens is approximate; temperature, top_p and top_k are ignored.
  • If the server restarts, native continuation is lost and history is rendered as text.
  • The system prompt always starts with the Agent SDK line.

Important caveat

This is a personal experiment, localhost only. Anthropic's terms do not allow routing third-party traffic through Free/Pro/Max plan credentials, so please do not expose or share it. ccapi never touches your OAuth token; it only uses Claude Code primitives (subagents, plugin tools, hooks).

Repo: https://github.com/S-kkipie/ccapi

Feedback welcome, especially on the subagent-per-request design.

Top comments (0)