Skip to main content
skill CX Codex

bun-runtime · secondsky — Claude Code skill: Bun CLI flags and bunfig.toml

A skill that teaches your agent the Bun runtime: running files, watch and hot modes, env vars, CLI flags and module resolution.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill bun-runtime -a claude-code
Open on GitHub

What bun-runtime does

The skill hands your agent a reference for Bun, the JavaScriptCore-based runtime. It covers running files (bun run index.ts and the shorthand), the --watch, --hot, --smol, --inspect, --preload, --env-file and -e flags, and package.json scripts including bun run --bun vite. One section spells out flag placement: put them right after bun, or they get forwarded to your script instead.

Tables cover globals (Bun, Buffer, process, fetch, WebSocket), the difference between watch and hot, environment file loading, and common errors such as Cannot find module and top-level await. For deeper work the skill points to references/bunfig.md, references/cli-flags.md and references/module-resolution.md — load those when you configure bunfig.toml, set path aliases or debug import failures.

No API keys, no extra services. You need Bun in the project. If you are on Node.js and staying there, this skill has nothing for you — it describes Bun's behaviour, not Node's.

What it helps with

  • run TypeScript or JSX without a separate build step
  • restart the server when files change
  • keep connections alive across reloads with hot mode
  • load .env.production instead of the auto-detected file
  • figure out why --watch never fires

Example prompts for the agent

  • Why doesn't bun run dev --watch restart my server?
  • How do I load env vars from .env.production in Bun?
  • Set up bunfig.toml with a preload script at ./setup.ts

How to install bun-runtime

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill bun-runtime -a claude-code

2Manually: put the files in place

~/.claude/skills/bun-runtime/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/bun-runtime/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about bun-runtime

How do I install bun-runtime in Claude?

Run npx skills add secondsky/claude-skills --skill bun-runtime -a claude-code. The skill file then lives at ~/.claude/skills/bun-runtime/SKILL.md.

What does bun-runtime do?

It tells your agent how to run code under Bun: CLI flags, watch and hot modes, environment variables, preload scripts, workspaces and module resolution.

What is the difference between --watch and --hot?

--watch restarts the whole process on file changes. --hot swaps modules and preserves state, so open connections and in-memory data survive.

Source text

SKILL.md · MIT
---
name: bun-runtime
description: Use for Bun runtime, bunfig.toml, watch/hot modes, env vars, CLI flags, and module resolution.
metadata:
  version: "1.0.0"
license: MIT
---

# Bun Runtime

Bun is a fast all-in-one JavaScript runtime built on JavaScriptCore (Safari's engine). It provides 4x faster startup than Node.js on Linux.

## Quick Start

```bash
# Run a file
bun run index.ts
bun index.ts  # shorthand

# Run with watch mode
bun --watch run index.ts

# Run package.json script
bun run dev

# Run with hot reloading
bun --hot run server.ts
```

## Core CLI Flags

| Flag | Purpose |
|------|---------|
| `--watch` | Restart on file changes |
| `--hot` | Hot module replacement (preserves state) |
| `--smol` | Reduce memory usage (slower GC) |
| `--inspect` | Enable debugger |
| `--preload` | Load modules before execution |
| `--env-file` | Load specific .env file |
| `-e, --eval` | Evaluate code string |

## Running Files

Bun transpiles TypeScript and JSX on-the-fly:

```bash
bun run index.js
bun run index.ts
bun run index.jsx
bun run index.tsx
```

**Important**: Put Bun flags immediately after `bun`:
```bash
bun --watch run dev    # Correct
bun run dev --watch    # Wrong - flag passed to script
```

## Package.json Scripts

```bash
# Run script
bun run dev
bun dev  # shorthand (if no Bun command conflicts)

# List available scripts
bun run

# Run with Bun instead of Node
bun run --bun vite
```

Bun respects lifecycle hooks (`preclean`, `postclean`, etc.).

## Watch Mode vs Hot Reloading

| Mode | Flag | Behavior |
|------|------|----------|
| Watch | `--watch` | Full process restart on changes |
| Hot | `--hot` | Replace modules, preserve state |

```bash
# Watch mode - full restart
bun --watch run server.ts

# Hot reloading - preserves connections/state
bun --hot run server.ts
```

## Environment Variables

Bun automatically loads `.env` files:

```bash
# Loads automatically: .env, .env.local, .env.development
bun run index.ts

# Specify env file
bun --env-file .env.production run index.ts

# Disable auto-loading
# In bunfig.toml: env = false
```

Access in code:
```typescript
const apiKey = process.env.API_KEY;
const bunEnv = Bun.env.NODE_ENV;
```

## Globals Available

| Global | Source | Notes |
|--------|--------|-------|
| `Bun` | Bun | Main API object |
| `Buffer` | Node.js | Binary data |
| `process` | Node.js | Process info |
| `fetch` | Web | HTTP requests |
| `Request/Response` | Web | HTTP types |
| `WebSocket` | Web | WebSocket client |
| `crypto` | Web | Cryptography |
| `console` | Web | Logging |
| `__dirname` | Node.js | Current directory |
| `__filename` | Node.js | Current file |

## Preload Scripts

Load modules before your main script:

```bash
bun --preload ./setup.ts run index.ts
```

Or in `bunfig.toml`:
```toml
preload = ["./setup.ts"]
```

Use cases: polyfills, global setup, instrumentation.

## Stdin Execution

```bash
# Pipe code to Bun
echo "console.log('Hello')" | bun run -

# Redirect file
bun run - < script.js
```

## Workspaces & Monorepos

```bash
# Run script in specific packages
bun run --filter 'pkg-*' build

# Run in all workspaces
bun run --filter '*' test
```

## Debugging

```bash
# Start debugger
bun --inspect run index.ts

# Wait for debugger connection
bun --inspect-wait run index.ts

# Break on first line
bun --inspect-brk run index.ts
```

Connect via Chrome DevTools or VS Code.

## Common Errors

| Error | Cause | Fix |
|-------|-------|-----|
| `Cannot find module` | Missing dependency | Run `bun install` |
| `Top-level await` | Using await outside async | Wrap in async function or use `.mts` |
| `--watch not working` | Flag in wrong position | Put flag before `run` |

## When to Load References

Load `references/bunfig.md` when:
- Configuring bunfig.toml
- Setting up test configuration
- Configuring package manager behavior
- Setting JSX options

Load `references/cli-flags.md` when:
- Need complete CLI flag reference
- Configuring advanced runtime options
- Setting up debugging

Load `references/module-resolution.md` when:
- Troubleshooting import errors
- Configuring path aliases
- Understanding Bun's resolution algorithm

© secondsky · MIT · secondsky/claude-skills

Similar skills

All skills for Programming languages →

bun-runtime by other authors comes first.

From the same set89

api-filtering-sorting A skill that walks your coding agent through building API filtering and sorting: query parsing, validation, and injection safety. CX Codex +1 418installs bun-drizzle-integration A skill that walks your agent through wiring Drizzle ORM to the bun:sqlite driver: schema, migrations, CRUD and transactions. CX Codex +1 420installs drizzle-orm-d1 A skill that gives your agent working knowledge of Drizzle ORM on Cloudflare D1: schemas, typed queries, Drizzle Kit migrations and the usual D1 errors. CX Codex +1 416installs push-notification-setup A skill that walks your agent through push notification setup with Firebase Cloud Messaging and native services. Useful when you add notifications to an app or debug background messages. CX Codex +1 418installs defense-in-depth-validation A skill that pushes your agent to validate data at every layer it passes through, so the bug becomes structurally impossible. Useful when bad data fails deep in execution. CX Codex +1 413installs ultracite A skill for setting up Ultracite: linting and formatting for JS/TS through Biome, ESLint or Oxlint. Handles migrations and config errors. CX Codex +1 415installs bun-tanstack-start A skill that tells your agent how to build a TanStack Start app on the Bun runtime: routing, server functions, build config. CX Codex +1 414installs bun-docker A skill that hands you Dockerfile and docker-compose patterns for Bun apps: oven/bun images, multi-stage builds, hot reload in development. CX Codex +1 408installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor