Development
bun-best-practices - Claude MCP Skill
When to use Bun, patterns, and anti-patterns. Covers Bun as package manager vs runtime, workspace configuration, compatibility considerations. Invoke for: bun adoption decision, bun vs pnpm, bun migration planning.
SEO Guide: Enhance your AI agent with the bun-best-practices tool. This Model Context Protocol (MCP) server allows Claude Desktop and other LLMs to when to use bun, patterns, and anti-patterns. covers bun as package manager vs runtime, workspace co... Download and configure this skill to unlock new capabilities for your AI workflow.
Documentation
SKILL.md# Bun Best Practices
Foundational knowledge for Bun adoption decisions. Bun serves two distinct rolesβunderstand when each applies.
## Two Distinct Roles
### Bun as Package Manager
Replaces pnpm/npm/yarn for dependency management:
- `bun install` β Install dependencies (fast, binary lockfile)
- `bun add <pkg>` β Add dependency
- `bun remove <pkg>` β Remove dependency
- `bun --filter <workspace>` β Run in specific workspace
**Key differences from pnpm:**
- Lockfile: `bun.lock` (binary) vs `pnpm-lock.yaml` (YAML)
- Workspaces: Defined in root `package.json`, no separate `pnpm-workspace.yaml`
- Speed: Significantly faster installs due to binary lockfile and caching
### Bun as Runtime
Replaces Node.js for executing JavaScript/TypeScript:
- `bun run script.ts` β Execute TypeScript directly (no tsc)
- `bun test` β Built-in test runner (Jest-compatible API)
- `bun build` β Bundle for production
- Native SQLite, file I/O, HTTP server optimizations
**Key differences from Node.js:**
- TypeScript: Transpilation, not full tsc checking (use `tsc --noEmit` for types)
- APIs: Some Node.js APIs missing or behave differently
- Performance: Often 2-10x faster for I/O-heavy workloads
## Decision Tree: When to Use Bun
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Consider Bun When: β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
CLI tools (fast startup, no cold boot) β
β β
Edge functions (lightweight runtime) β
β β
Internal dev tools (team controls deployment) β
β β
New greenfield projects (no legacy constraints) β
β β
Scripts/automation (fast execution) β
β β
Projects with simple dependency trees β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Prefer pnpm When: β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β οΈ Expo/EAS builds (Node.js required) β
β β οΈ Vercel serverless (limited Bun support) β
β β οΈ Complex native module dependencies β
β β οΈ Team unfamiliar with Bun quirks β
β β οΈ Production apps needing maximum stability β
β β οΈ Projects with extensive Node.js API usage β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## Hybrid Setup Pattern
Many projects benefit from using both:
```
monorepo/
βββ apps/
β βββ web/ # Next.js app β pnpm (Vercel deployment)
β βββ mobile/ # Expo app β pnpm (EAS requires Node)
βββ packages/
β βββ shared/ # Shared utilities β either works
βββ tools/
β βββ cli/ # Internal CLI β Bun (fast startup)
βββ scripts/ # Build/deploy scripts β Bun (fast execution)
```
**Rule of thumb:**
- External-facing production apps β pnpm (stability)
- Internal tools and scripts β Bun (speed)
## Workspace Configuration
### pnpm (separate file)
```yaml
# pnpm-workspace.yaml
packages:
- 'apps/*'
- 'packages/*'
```
### Bun (in package.json)
```json
{
"workspaces": ["apps/*", "packages/*"]
}
```
**Migration note:** Remove `pnpm-workspace.yaml` when switching to Bun; add `workspaces` to root `package.json`.
## Anti-Patterns
### 1. Assuming Full Node.js Compatibility
**Wrong:**
```typescript
// Assuming all Node.js APIs work identically
import { fork } from 'child_process';
fork('./worker.js'); // May behave differently in Bun
```
**Right:**
```typescript
// Test critical Node.js API usage before migration
// Check: https://bun.sh/docs/runtime/nodejs-apis
```
### 2. Mixing Lockfiles
**Wrong:**
```
project/
βββ bun.lock
βββ pnpm-lock.yaml # Both present = confusion
βββ package.json
```
**Right:**
```
project/
βββ bun.lock # OR pnpm-lock.yaml, not both
βββ package.json
```
### 3. Skipping CI Migration
**Wrong:**
```yaml
# Still using pnpm in CI
- uses: pnpm/action-setup@v4
- run: pnpm install
```
**Right:**
```yaml
# Match local tooling
- uses: oven-sh/setup-bun@v2
- run: bun install
```
### 4. Ignoring Platform Support
**Wrong:**
```typescript
// Deploying to platform that doesn't support Bun runtime
export default async function handler(req, res) {
// Assumes Bun runtime features
}
```
**Right:**
```typescript
// Verify deployment target supports Bun
// Vercel: experimental Bun runtime flag
// Netlify: Node.js only (as of 2025)
// Fly.io: Full Bun support
```
## Performance Benchmarking
Before migrating, benchmark your specific workflows:
```bash
# Install time comparison
time pnpm install
time bun install
# Script execution comparison
time pnpm run build
time bun run build
# Test runner comparison
time pnpm test
time bun test
```
Only migrate if Bun provides measurable benefit for YOUR project.
## Related References
- `references/workspace-config.md` β Workspace migration details
- `references/compatibility-matrix.md` β Framework/tool compatibility
- `references/ci-cd-patterns.md` β CI/CD configuration patterns
- `references/hybrid-setup.md` β Running Bun + pnpm together
## Related Skills
- `/check-bun` β Audit project for Bun compatibility
- `/fix-bun` β Fix Bun migration issues
- `/bun` β Full Bun migration orchestratorSignals
Information
- Repository
- phrazzld/claude-config
- Author
- phrazzld
- Last Sync
- 3/2/2026
- Repo Updated
- 3/1/2026
- Created
- 2/3/2026
Reviews (0)
No reviews yet. Be the first to review this skill!
Related Skills
Related Guides
Bear Notes Claude Skill: Your AI-Powered Note-Taking Assistant
Learn how to use the bear-notes Claude skill. Complete guide with installation instructions and examples.
Mastering tmux with Claude: A Complete Guide to the tmux Claude Skill
Learn how to use the tmux Claude skill. Complete guide with installation instructions and examples.
OpenAI Whisper API Claude Skill: Complete Guide to AI-Powered Audio Transcription
Learn how to use the openai-whisper-api Claude skill. Complete guide with installation instructions and examples.