# Bun

> SKILL: Bun Development

- Skill: `rcarmo/bun` (Agent Skill)
- Install (CLI): `npx skillmds@latest add rcarmo/bun`
- Raw SKILL.md: https://api.skillmd.com/api/skills/rcarmo/bun/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: rcarmo (https://skillmd.com/u/rcarmo)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/rcarmo/bun

---

# SKILL: Bun Development

## Description

This project uses Bun as the JavaScript/TypeScript runtime, package manager, bundler, and test runner.

## Key Commands

```bash
# Package management
bun install              # Install deps from package.json
bun add <pkg>            # Add dependency
bun add -d <pkg>         # Add dev dependency
bun remove <pkg>         # Remove dependency
bun update               # Update dependencies

# Running code
bun run <script>         # Run package.json script
bun <file.ts>            # Run TypeScript directly
bun --watch <file.ts>    # Run with auto-reload

# Testing
bun test                 # Run tests
bun test --watch         # Watch mode
bun test --coverage      # With coverage

# Building
bun build ./src/index.ts --outdir=./dist
```

## Server Pattern

```typescript
Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello!");
  },
  websocket: {
    open(ws) { /* ... */ },
    message(ws, message) { /* ... */ },
    close(ws) { /* ... */ },
  },
});
```

## Testing Pattern

```typescript
import { describe, it, expect } from "bun:test";

describe("feature", () => {
  it("should work", () => {
    expect(1 + 1).toBe(2);
  });
});
```

## Environment Variables

Bun auto-loads `.env` files. Access via:
- `process.env.VAR_NAME`
- `Bun.env.VAR_NAME`

