跳到正文
DEV Community· Adrian Issac·· 3 小時前AI 評分52

ccapi 將 Claude Code 工作階段轉為 localhost 上的 Anthropic 相容 API

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

AI 導讀

Adrian Issac 開發 ccapi,讓支援 Anthropic Messages API 的用戶端可透過 localhost 上的 `/v1/messages` 連接 Claude Code 工作階段。

正文

Adrian Issac

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.

來源:DEV Community · dev.to