一键导入
bun-init
Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Win32 FFI binding lifecycle for @bun-win32/* packages (Win32 DLL bindings via bun:ffi on Windows). Use when generating a new package from a DLL, auditing FFI↔TS↔header consistency, fixing nullability (| NULL / | 0n), or understanding the bootstrap→catalog→stub→audit→nullcheck pipeline. Covers 117 packages; strict TypeScript; Bun runtime; Biome formatting.
Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, or chat applications. Covers Agent class, state management, callable RPC, Workflows integration, and React hooks.
Suite of tools for creating elaborate, multi-component HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.
Builds AI agents on Cloudflare using the Agents SDK with state management, real-time WebSockets, scheduled tasks, tool integration, and chat capabilities. Generates production-ready agent code deployed to Workers. Use when: user wants to "build an agent", "AI agent", "chat agent", "stateful agent", mentions "Agents SDK", needs "real-time AI", "WebSocket AI", or asks about agent "state management", "scheduled tasks", or "tool calling".
Builds remote MCP (Model Context Protocol) servers on Cloudflare Workers with tools, OAuth authentication, and production deployment. Generates server code, configures auth providers, and deploys to Workers. Use when: user wants to "build MCP server", "create MCP tools", "remote MCP", "deploy MCP", add "OAuth to MCP", or mentions Model Context Protocol on Cloudflare. Also triggers on "MCP authentication" or "MCP deployment".
Create optimized production bundles with Bun's native bundler. Use when building applications for production, optimizing bundle sizes, setting up multi-environment builds, or replacing webpack/esbuild/rollup.
| name | bun-init |
| description | Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project. |
| compatibility | Requires Bun 1.0+ |
| allowed-tools | ["Bash","Write","Read"] |
| metadata | {"author":"dale","category":"bun-runtime","tags":["bun","javascript","typescript","initialization","setup"]} |
You are assisting with initializing a new Bun project. Follow these steps to create a well-structured project with optimal configurations.
First, verify Bun is installed:
bun --version
If Bun is not installed, provide installation instructions for the user's platform.
Ask the user which type of project they want to create:
Execute the initialization command:
bun init -y
This creates:
package.json with Bun-optimized scriptstsconfig.json with recommended TypeScript settingsindex.ts as the entry pointREADME.md with basic project infoRead the generated tsconfig.json and enhance it based on project type:
For CLI Tools:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
For Web Apps:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
For API Servers:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true,
"paths": {
"@/*": ["./src/*"]
}
}
}
For Libraries:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
Generate appropriate directory structure and files:
CLI Tool:
project/
├── src/
│ ├── index.ts # Main CLI entry point
│ ├── commands/ # Command handlers
│ └── utils/ # Shared utilities
├── tests/
│ └── index.test.ts
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
Create src/index.ts:
#!/usr/bin/env bun
console.log("Hello from Bun CLI!");
// Example: Parse command line arguments
const args = process.argv.slice(2);
console.log("Arguments:", args);
Update package.json to add bin field:
{
"bin": {
"your-cli-name": "./src/index.ts"
}
}
Web App:
project/
├── src/
│ ├── index.tsx # App entry point
│ ├── components/ # React components
│ ├── styles/ # CSS/styles
│ └── utils/ # Utilities
├── public/
│ └── index.html
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
API Server:
project/
├── src/
│ ├── index.ts # Server entry point
│ ├── routes/ # Route handlers
│ ├── middleware/ # Express/Hono middleware
│ ├── services/ # Business logic
│ └── types/ # TypeScript types
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
Create src/index.ts:
const server = Bun.serve({
port: 3000,
fetch(request) {
return new Response("Welcome to Bun!");
},
});
console.log(`Server running at http://localhost:${server.port}`);
Library:
project/
├── src/
│ ├── index.ts # Main export
│ └── types.ts # Type definitions
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
└── README.md
Generate a comprehensive .gitignore:
# Bun
node_modules
bun.lockb
*.bun
# Environment
.env
.env.local
.env.*.local
# Build outputs
dist/
build/
*.tsbuildinfo
# Logs
logs
*.log
npm-debug.log*
# OS
.DS_Store
Thumbs.db
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# Test coverage
coverage/
.nyc_output/
Create .env.example:
# Application
NODE_ENV=development
PORT=3000
# Add your environment variables here
# DATABASE_URL=
# API_KEY=
Add project-type-specific scripts:
CLI Tool:
{
"scripts": {
"dev": "bun run src/index.ts",
"test": "bun test",
"lint": "bun run --bun eslint src",
"typecheck": "bun run --bun tsc --noEmit"
}
}
Web App:
{
"scripts": {
"dev": "bun run --hot src/index.tsx",
"build": "bun build src/index.tsx --outdir=dist --minify",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit"
}
}
API Server:
{
"scripts": {
"dev": "bun run --hot src/index.ts",
"start": "bun run src/index.ts",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit"
}
}
Library:
{
"scripts": {
"build": "bun build src/index.ts --outdir=dist --minify --sourcemap=external",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit",
"prepublishOnly": "bun run build && bun test"
}
}
Suggest installing common dependencies based on project type:
CLI Tool:
bun add commander chalk ora
bun add -d @types/node
Web App:
bun add react react-dom
bun add -d @types/react @types/react-dom
API Server:
bun add hono
bun add -d @types/node
Library:
# No default dependencies - user will add as needed
Create a basic test file in tests/:
import { describe, expect, test } from "bun:test";
describe("Initial test", () => {
test("basic assertion", () => {
expect(1 + 1).toBe(2);
});
});
After completing the setup, provide the user with:
.env.example to .env and configurebun install if dependencies were suggestedbun dev to start developmentbun test to verify tests work"moduleResolution": "bundler" for Bun's native resolution"types": ["bun-types"]"noEmit": true since Bun runs TypeScript directly"allowImportingTsExtensions": true for .ts importsIf user wants workspaces (monorepo):
Add to package.json:
{
"workspaces": ["packages/*"]
}
If user wants path aliases:
Add to tsconfig.json:
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"]
}
}
}
If user wants JSX without React:
Update tsconfig.json:
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact" // or other JSX runtime
}
}
Once all files are created, inform the user that initialization is complete and provide a summary of: