AIToday
Large Language ModelsAI Coding AssistantsZenn AI/MLPublished: Oct 16, 2026, 22:01 JST

Run Claude Code for free with a mock model server

Run Claude Code for free with a mock model server

3 Key Points

  1. What happened

    The walkthrough points the CLI at a local mock via the ANTHROPIC_BASE_URL environment variable. The mock implements only the /v1/messages endpoint, returning scripted SSE answers, including tool_use blocks that call Bash.

  2. Why it matters

    Because only the model is billed, developers building Claude Code hooks and MCP servers can test them repeatedly at no cost and see exactly what the CLI passes in, since the CLI stays real.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, in your inbox every morning.

Context & Analysis

Claude Code separates into two halves: the CLI running on your own machine and the model running on Anthropic's servers. Billing applies only to the model's work of reading requests and producing answers, so swapping just that half for a small server that returns scripted responses leaves the CLI's real behavior intact while removing the cost. Requests are sent as HTTP calls to the Messages API, and the mock only needs to implement the /v1/messages endpoint, since answers come back as replies to those requests rather than as separate calls.

The write-up uses the setup to inspect what the CLI actually transmits. A request captured during a run includes a system prompt the CLI adds, tool definitions, and the prior conversation. As an example, the author adds a UserPromptSubmit hook and finds its output delivered inside the CLI's added preamble, under a heading that reads 'UserPromptSubmit hook success:'. The same method was used previously to check how /compact replaces a conversation with a summary, how MCP server descriptions and skills reach the model, and how MCP tools are moved to the background after 120 seconds.

Beyond inspection, the piece shows the mock can simulate failures. Returning HTTP 529 responses a set number of times lets you observe how the CLI retries, with the number of retries controlled by CLAUDE_CODE_MAX_RETRIES. The author also runs this pattern at a larger scale for their own macOS app tanacode, driving the real CLI with the mock every day in GitHub Actions to catch breakage when Claude Code updates.

FAQ
How does the mock avoid needing a real API key?
The mock does not check the key, so ANTHROPIC_API_KEY only needs to be non-empty. Any value works because the mock never verifies it.
What can't be tested with this mock?
The model's own judgment is not observable, since answers follow a fixed script. Features that require logging in with a claude.ai account, such as Remote Control or /usage, do not work, and the ToDo tools TodoWrite and TaskCreate do not appear when running with an API key.
Can it be used in CI?
Yes. A GitHub Actions job pins @anthropic-ai/claude-code@2.1.300, installs Node 22, and runs node --test claude.test.mjs without a real API key.

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleBillionaires dump Apple, Microsoft, other AI stocks in Q2