Bun with Claude Code
Learn about Bun using Claude Code. Practical tips and code examples included.
Accelerating Bun Adoption With Claude Code
Bun is an all-in-one runtime for JavaScript/TypeScript. It bundles a package manager, bundler, and test runner, and runs several times faster than Node.js. Let’s use Claude Code to efficiently adopt Bun’s powerful features.
Starting a Project
> Create a new web app project with Bun.
> Include TypeScript, the Hono framework, and a test setup.
bun init my-app
cd my-app
bun add hono
// src/index.ts
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from 'hono/logger';
const app = new Hono();
app.use('*', logger());
app.use('/api/*', cors());
app.get('/api/health', (c) => {
return c.json({ status: 'ok', runtime: 'bun' });
});
app.get('/api/users/:id', async (c) => {
const id = c.req.param('id');
const user = await getUser(id);
return c.json(user);
});
export default {
port: 3000,
fetch: app.fetch,
};
Leveraging Bun’s Built-in APIs
> Implement a simple data store using Bun's file APIs and SQLite.
// src/db.ts
import { Database } from 'bun:sqlite';
const db = new Database('app.db', { create: true });
db.run(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
export const createUser = db.prepare(
'INSERT INTO users (name, email) VALUES ($name, $email)'
);
export const getUser = db.prepare(
'SELECT * FROM users WHERE id = $id'
);
// Bun file operations
export async function saveUpload(file: File) {
const path = `./uploads/${file.name}`;
await Bun.write(path, file);
return path;
}
export async function readConfig() {
const file = Bun.file('./config.json');
return await file.json();
}
Running Tests
Bun ships with a fast built-in test runner.
> Write tests for the API endpoints.
> Use Bun's test runner.
// src/index.test.ts
import { describe, expect, it, beforeAll, afterAll } from 'bun:test';
describe('API endpoints', () => {
it('GET /api/health returns ok', async () => {
const res = await fetch('http://localhost:3000/api/health');
const data = await res.json();
expect(res.status).toBe(200);
expect(data.status).toBe('ok');
});
it('GET /api/users/:id returns user', async () => {
const res = await fetch('http://localhost:3000/api/users/1');
expect(res.status).toBe(200);
const user = await res.json();
expect(user).toHaveProperty('name');
});
});
# Run tests
bun test
# Watch mode
bun test --watch
# Coverage
bun test --coverage
Bundling and Building
> Bundle the front-end code with Bun.
> Enable tree shaking and minification.
// build.ts
await Bun.build({
entrypoints: ['./src/client/index.tsx'],
outdir: './dist',
target: 'browser',
minify: true,
splitting: true,
sourcemap: 'external',
define: {
'process.env.NODE_ENV': '"production"',
},
});
console.log('Build complete!');
Summary
With its blazing speed and integrated toolchain, Bun can significantly improve developer experience. Combine it with Claude Code to rapidly get up to speed on Bun-specific APIs and patterns. See also the API development guide and testing strategies.
For details about Bun, see the official Bun documentation.
Free PDF: Claude Code Cheatsheet in 5 Minutes
Just enter your email and we'll send you the single-page A4 cheatsheet right away.
We handle your data with care and never send spam.
Level up your Claude Code workflow
50 battle-tested prompt templates you can copy-paste into Claude Code right now.
About the Author
Masa
Engineer obsessed with Claude Code. Runs claudecode-lab.com, a 10-language tech media with 2,000+ pages.
Related Posts
7 Deployment Checks Before You Publish a Multilingual Claude Code Article Every Day
A practical checklist for publishing daily multilingual Claude Code articles without missing locales, breaking CTAs, or shipping stale pages.
Codex Automations for Content Ops: A Daily Revenue Workflow for Claude Code Sites
Use Codex Automations to turn analytics, article updates, CTA improvements, deployment, and verification into a daily revenue workflow.
Claude Code × GCP Cloud Functions Complete Guide | Rapid Serverless Function Development
Streamline GCP Cloud Functions with Claude Code. Implement HTTP/Pub/Sub/Firestore triggers, local testing, and deployment automation with real-world code examples from Masa's experience.
Related Products
50 Battle-Tested Claude Code Prompt Templates
Copy, paste, ship. 50 production-ready prompts.
Use proven prompts for code review, refactoring, testing, documentation, debugging, architecture, and incident response.
The Complete Claude Code Setup & Configuration Guide
From install to team-ready workflow.
A practical guide to installation, CLAUDE.md, hooks, MCP servers, permissions, IDE setup, and CI/CD workflows.