Skip to main content
skill CX Codex

bun-tanstack-start — Claude Code skill: TanStack Start on Bun

A skill that tells your agent how to build a TanStack Start app on the Bun runtime: routing, server functions, build config.

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

What bun-tanstack-start does

The skill covers the TanStack Start and Bun pairing: file-based routing with @tanstack/react-router, server functions from @tanstack/start, and API routes. It ships working config examples — app.config.ts with the bun preset, plus vinxi dev, vinxi build and vinxi start scripts in package.json. Route templates include loaders, dynamic paths like $userId.tsx, a root layout and error handling.

Server functions are shown against bun:sqlite: inserting a row, listing users, checking a session from cookies. A separate section walks through API routes built with createAPIFileRoute and GET/POST handlers. If your project runs on a different runtime, the bun preset in the config has to change — otherwise the build hits a mismatch between environments.

The skill opens with a secure-install section. The bunx create-tanstack-start scaffolder downloads and runs remote code, so the author suggests blocking post-install scripts (Bun disables them by default; allow specific packages through trustedDependencies), setting minimumReleaseAge in bunfig.toml to wait 7 days, and scoring packages with the Socket CLI. For the full setup it points to the dependency-upgrade skill.

What it helps with

  • scaffold a TanStack Start project and run it on Bun
  • write a route loader and read the result with useLoaderData
  • add a server function that reads and writes bun:sqlite
  • split GET and POST handlers across API routes in one file
  • switch the build preset to Bun in app.config.ts

Example prompts for the agent

  • Scaffold a new TanStack Start project on Bun and show me the app/routes layout
  • Add a createUser server function backed by bun:sqlite and wire it to the form
  • The build fails on the bun preset — check app.config.ts and package.json

How to install bun-tanstack-start

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill bun-tanstack-start -a claude-code

2Manually: put the files in place

~/.claude/skills/bun-tanstack-start/SKILL.md

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

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

Questions about bun-tanstack-start

How do I install bun-tanstack-start in Claude?

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

What does bun-tanstack-start do?

It gives the agent a reference for TanStack Start on the Bun runtime: file-based routing, server functions, API routes, build config and loader error handling.

What should I do before running the scaffolder?

The skill suggests blocking post-install scripts and allowing packages through trustedDependencies, setting minimumReleaseAge in bunfig.toml, and checking packages with the Socket CLI.

Source text

SKILL.md · MIT
---
name: bun-tanstack-start
description: TanStack Start full-stack React framework with Bun runtime. Use for TanStack Router, server functions, vinxi, or encountering SSR, build, preset errors.
license: MIT
---

# Bun TanStack Start

Run TanStack Start (full-stack React framework) with Bun.

## Quick Start

```bash
# Create new TanStack Start project
bunx create-tanstack-start@latest my-app
cd my-app

# Install dependencies
bun install

# Development
bun run dev

# Build
bun run build

# Preview
bun run start
```

## Secure Installation

Scaffolding tools like `bunx create-tanstack-start` download and execute remote code. Before running, follow supply chain security best practices:

- **Block post-install scripts** — Bun disables them by default; allow specific packages via `trustedDependencies` in `package.json`
- **Cooldown period** — Configure `minimumReleaseAge` in `bunfig.toml` to wait 7 days for new versions
- **Audit before installing** — Run `socket package score npm <pkg>` or use `socket npm install <pkg>` to check packages

Load the `dependency-upgrade` skill for full security configuration including Socket CLI integration, cooldown setup, lockfile validation, and CI enforcement.

## Project Setup

### package.json

```json
{
  "scripts": {
    "dev": "vinxi dev",
    "build": "vinxi build",
    "start": "vinxi start"
  },
  "dependencies": {
    "@tanstack/react-router": "^1.170.18",
    "@tanstack/start": "^1.120.0",
    "react": "^19.2.0",
    "react-dom": "^19.2.0",
    "vinxi": "^0.5.10"
  }
}
```

### app.config.ts

```typescript
import { defineConfig } from "@tanstack/start/config";

export default defineConfig({
  server: {
    preset: "bun",
  },
});
```

## File-Based Routing

```
app/
├── routes/
│   ├── __root.tsx       # Root layout
│   ├── index.tsx        # /
│   ├── about.tsx        # /about
│   ├── users/
│   │   ├── index.tsx    # /users
│   │   └── $userId.tsx  # /users/:userId
│   └── api/
│       └── users.ts     # /api/users
└── client.tsx
```

## Route Components

### Basic Route

```tsx
// app/routes/index.tsx
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/")({
  component: Home,
});

function Home() {
  return <h1>Welcome Home</h1>;
}
```

### Route with Loader

```tsx
// app/routes/users/index.tsx
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/users/")({
  loader: async () => {
    const response = await fetch("/api/users");
    return response.json();
  },
  component: Users,
});

function Users() {
  const users = Route.useLoaderData();

  return (
    <ul>
      {users.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}
```

### Dynamic Routes

```tsx
// app/routes/users/$userId.tsx
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/users/$userId")({
  loader: async ({ params }) => {
    const response = await fetch(`/api/users/${params.userId}`);
    return response.json();
  },
  component: UserDetail,
});

function UserDetail() {
  const user = Route.useLoaderData();
  const { userId } = Route.useParams();

  return (
    <div>
      <h1>{user.name}</h1>
      <p>User ID: {userId}</p>
    </div>
  );
}
```

## Server Functions

### Define Server Function

```tsx
// app/routes/users/index.tsx
import { createFileRoute } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/start";
import { Database } from "bun:sqlite";

const getUsers = createServerFn("GET", async () => {
  const db = new Database("data.sqlite");
  const users = db.query("SELECT * FROM users").all();
  db.close();
  return users;
});

const createUser = createServerFn("POST", async (name: string) => {
  const db = new Database("data.sqlite");
  db.run("INSERT INTO users (name) VALUES (?)", [name]);
  db.close();
  return { success: true };
});

export const Route = createFileRoute("/users/")({
  loader: () => getUsers(),
  component: Users,
});

function Users() {
  const users = Route.useLoaderData();

  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();
    const formData = new FormData(e.currentTarget);
    const name = formData.get("name") as string;
    await createUser(name);
    // Refetch or update state
  };

  return (
    <div>
      <form onSubmit={handleSubmit}>
        <input name="name" placeholder="Name" />
        <button type="submit">Add User</button>
      </form>
      <ul>
        {users.map((user) => (
          <li key={user.id}>{user.name}</li>
        ))}
      </ul>
    </div>
  );
}
```

### Server Function with Context

```tsx
import { createServerFn } from "@tanstack/start";
import { getWebRequest } from "@tanstack/start/server";

const getSession = createServerFn("GET", async () => {
  const request = getWebRequest();
  const cookies = request.headers.get("Cookie");
  // Parse and validate session
  return { userId: "123", role: "admin" };
});

const protectedAction = createServerFn("POST", async (data: any) => {
  const session = await getSession();

  if (session.role !== "admin") {
    throw new Error("Unauthorized");
  }

  // Perform action
  return { success: true };
});
```

## API Routes

```typescript
// app/routes/api/users.ts
import { createAPIFileRoute } from "@tanstack/start/api";
import { Database } from "bun:sqlite";

export const Route = createAPIFileRoute("/api/users")({
  GET: async ({ request }) => {
    const db = new Database("data.sqlite");
    const users = db.query("SELECT * FROM users").all();
    db.close();

    return Response.json(users);
  },

  POST: async ({ request }) => {
    const { name } = await request.json();

    const db = new Database("data.sqlite");
    db.run("INSERT INTO users (name) VALUES (?)", [name]);
    db.close();

    return Response.json({ success: true });
  },
});
```

## Root Layout

```tsx
// app/routes/__root.tsx
import { createRootRoute, Link, Outlet } from "@tanstack/react-router";

export const Route = createRootRoute({
  component: Root,
});

function Root() {
  return (
    <html>
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>My App</title>
      </head>
      <body>
        <nav>
          <Link to="/">Home</Link>
          <Link to="/users">Users</Link>
          <Link to="/about">About</Link>
        </nav>
        <main>
          <Outlet />
        </main>
      </body>
    </html>
  );
}
```

## Error Handling

```tsx
// app/routes/users/$userId.tsx
export const Route = createFileRoute("/users/$userId")({
  loader: async ({ params }) => {
    const response = await fetch(`/api/users/${params.userId}`);
    if (!response.ok) {
      throw new Error("User not found");
    }
    return response.json();
  },
  errorComponent: ({ error }) => (
    <div>
      <h1>Error</h1>
      <p>{error.message}</p>
    </div>
  ),
  pendingComponent: () => <div>Loading...</div>,
  component: UserDetail,
});
```

## Search Params

```tsx
// app/routes/users/index.tsx
import { createFileRoute } from "@tanstack/react-router";
import { z } from "zod";

const searchSchema = z.object({
  page: z.number().default(1),
  limit: z.number().default(10),
  search: z.string().optional(),
});

export const Route = createFileRoute("/users/")({
  validateSearch: searchSchema,
  loader: async ({ search }) => {
    const { page, limit, search: query } = search;
    // Fetch with pagination
    return fetchUsers({ page, limit, query });
  },
  component: Users,
});
```

## Deployment

### Build for Bun

```bash
NITRO_PRESET=bun bun run build
bun .output/server/index.mjs
```

### Docker

```dockerfile
FROM oven/bun:1 AS builder

WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

COPY . .
RUN bun run build

FROM oven/bun:1

WORKDIR /app
COPY --from=builder /app/.output ./output

EXPOSE 3000

CMD ["bun", ".output/server/index.mjs"]
```

## Common Errors

| Error | Cause | Fix |
|-------|-------|-----|
| `Cannot find bun:sqlite` | Wrong preset | Set `server.preset: "bun"` |
| `Server function failed` | Network error | Check function definition |
| `Route not found` | File naming | Check route file location |
| `Hydration mismatch` | Server/client diff | Check loader data |

## When to Load References

Load `references/router-api.md` when:
- Advanced routing patterns
- Route guards
- Nested layouts

Load `references/forms.md` when:
- Form handling
- Mutations
- Optimistic updates

© secondsky · MIT · secondsky/claude-skills

Similar skills

Everything for Frontend and UI →

From the same set89

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 bun-runtime A skill that teaches your agent the Bun runtime: running files, watch and hot modes, env vars, CLI flags and module resolution. CX Codex +1 414installs 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-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 nuxt-ui-v4 A skill that gives your agent the Nuxt UI v4 component library: 125+ accessible components, Tailwind v4, dark mode. Useful for Nuxt dashboards, forms and chat UIs. CX Codex +1 410installs api-gateway-configuration A skill that walks through API gateway setup for microservices: routing, auth, rate limiting and request transformation. CX Codex +1 408installs health-check-endpoints A coding-agent skill for wiring up liveness, readiness and startup probes, plus dependency checks against your database and Redis. CX Codex +1 406installs

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