CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/API & SDK
API & SDK/2026-05-04Advanced

Claude API on Bun in Production: Migration Decisions and Implementation Patterns That Actually Survive Real Traffic

A practical guide to running Claude API services on Bun in production. Covers migration triggers from Node.js, built-in SQLite/WebSocket usage, streaming optimization, and the pitfalls that only surface after deployment — with working code and measured numbers.

BunClaude API115Edge AINode.js MigrationTypeScript24Production23Streaming4

Premium Article

"Bun is fast, sure — but is it really safe to run a Claude API server on it in production?" I have heard some version of this question more times than I can count since 2025. After migrating a handful of my own side projects from Node.js to Bun in stages, I noticed something the benchmark numbers never quite capture: the real decision is not about raw speed, it is about which production trade-offs you are willing to accept.

With Bun 1.2.x stabilizing and 2026 well underway, I now feel comfortable running Claude API workloads — long-lived streaming included — on Bun. That said, simply replacing node with bun and calling it done leaves a lot of value on the table, and occasionally introduces new failure modes you would not have hit on Node.js.

In this article I want to walk through the patterns I have used to build production-grade Claude API services on Bun, and the operational pitfalls that you only learn about once your service is live. Every code sample here has been run, and is intentionally close to what I would actually deploy.

Why pick Bun for a Claude API server right now

Speed is not the only reason to choose Bun. Let me lay out the specific problems Bun solves for streaming-heavy Claude API workloads.

The first is cold start. When you run Claude API services in serverless or container-based environments, container startup time leaks directly into user-perceived latency. Node.js has improved with v22, but Bun is still less than half of Node's cold start time on my machines. A minimal Claude proxy that takes 220ms to boot on Node starts in 95ms on Bun. When your end-to-end response budget is one to two seconds, that gap is something users actually feel.

The second is native TypeScript execution. Bun runs .ts files directly, with no tsx, no ts-node, no swc build step. That helps in three places at once: faster developer feedback loops, smaller Docker images (no transpile step needed), and one fewer place for transpiler bugs to hide.

The third is the set of built-in primitives. SQLite, WebSocket, a test runner, a package manager, and an HTTP server all ship with Bun. A stack that previously required Node + Express + sqlite3 + ws + jest collapses into a single binary. That is not just convenience; it is a meaningful reduction in supply-chain surface area.

There are situations where Bun is the wrong call. If you are pinned to the AWS Lambda Node.js runtime, depend on a critical CommonJS-only internal library, or rely heavily on native add-ons such as node-canvas, Node 22 LTS is still the safer choice. Pick the tool that matches your constraints, not the one that benchmarks well on Hacker News.

Architecture: a dependency-light Claude API proxy

Let me set the scope. We are building a "thin proxy" that takes a prompt from the client, forwards it to Claude API, and streams the response straight back. But it has to satisfy a handful of real production requirements:

  • Per-request token usage and cost are persisted to SQLite
  • Concurrent requests from the same user are throttled with simple rate limiting
  • Anthropic-side errors are classified internally rather than leaked verbatim
  • Client disconnects mid-stream cancel the upstream Claude call so we stop billing

The only external dependency is @anthropic-ai/sdk. The HTTP server, SQLite, and WebSocket primitives are all Bun built-ins.

Client → Bun.serve (HTTP/WebSocket) → AnthropicProxy
                       ↓
                bun:sqlite (usage and history)
                       ↓
                Anthropic API (streaming)

The directory layout stays small.

.
├── bunfig.toml
├── package.json
├── src
│   ├── server.ts          # Entry point
│   ├── proxy.ts           # Anthropic call logic
│   ├── usage.ts           # SQLite usage logging
│   ├── ratelimit.ts       # In-memory rate limiting
│   └── errors.ts          # Error classification
└── tests
    └── proxy.test.ts

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Engineers wondering whether to migrate their Node.js Claude API server to Bun can now make that decision with concrete benchmarks and a clear migration framework
You will be able to design and ship a low-latency Claude API service that uses Bun's built-in SQLite, WebSocket, and HTTP server to minimize external dependencies
You can avoid the Bun-specific pitfalls (Node compatibility edges, native modules, test runner differences, Linux distribution) that typically only show up after going to production
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-07-01
When Claude API Document Extraction Is Confidently Wrong — Field Notes on Catching Silent Errors with Invariants
In structured extraction from invoices and contracts, the real danger isn't a crash — it's a value that's silently wrong while the schema validates and confidence reads high. Field notes on invariants, two-pass extraction, and tracking field-level error rates.
API & SDK2026-04-25
Claude API × Convex: Reactive AI Apps — Data Flow, Streaming, and Agent Patterns
How to combine Convex's reactive database with the Claude API to build chat and agent applications that hold up in production. Covers schema design, the Action/Mutation/Query boundary, streaming, tool-call state, and the cold-start pitfalls nobody warns you about.
API & SDK2026-04-20
Three Hidden Pitfalls When Implementing Claude API Streaming
Real-world lessons from building with Claude API streaming: runtime environment mismatches, error handling gaps, and silent token cost overruns — with working TypeScript examples.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →