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.

🌟1 stars β€’ 1 forks
πŸ“₯0 downloads

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 orchestrator

Signals

Avg rating⭐ 0.0
Reviews0
Favorites0

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!