Bun macros let you run JavaScript at bundle time and inline the results directly into your output code. Think embedding environment variables, reading files, generating code from schemas, or pulling git commit hashes without any runtime overhead. The macro runs once during bundling and vanishes, leaving only its return value. It's genuinely useful for things like pre-computing build metadata or eliminating dead code branches based on compile-time conditions. The catch is macros only work during `bun build`, not `bun run`, so you're committing to a bundling step. If you're already bundling and want to move work from runtime to build time, this handles the common cases cleanly.

skills.sh installs
322
GitHub stars
248
last updated
Aug 21, 2026

Install

$ npx -y skills add secondsky/claude-skills --skill bun-macros --agent claude-code

Installs into .claude/skills of the current project.

Files

Bun Macros

Bun macros run JavaScript at bundle time and inline the results into the output.

Quick Start

// src/config.ts (macro file)
export function getVersion() {
  return "1.0.0";
}

export function getBuildTime() {
  return new Date().toISOString();
}

// src/index.ts (consumer)
import { getVersion, getBuildTime } from "./config" with { type: "macro" };

// At bundle time, these become:
const version = "1.0.0";
const buildTime = "2024-01-15T12:00:00.000Z";

Macro Syntax

// Import with macro attribute
import { fn } from "./macro-file" with { type: "macro" };

// Call the macro (evaluated at build time)
const result = fn();

Common Use Cases

Environment Inlining

// macros/env.ts
export function env(key: string): string {
  return process.env[key] ?? "";
}

// src/index.ts
import { env } from "./macros/env" with { type: "macro" };

const apiUrl = env("API_URL");
// Becomes: const apiUrl = "https://api.example.com";

Git Information

// macros/git.ts
export function gitCommit(): string {
  return Bun.spawnSync(["git", "rev-parse", "HEAD"])
    .stdout.toString().trim();
}

Sponsors

Details

Repository
github.com/secondsky/claude-skills
Category
AI & Agent Building
First seen
Jun 3, 2026

More from secondsky/claude-skills

All 146
1davila7 avatarconstitutional-aidavila7/claude-code-templatesAnthropic's method for training harmless AI through self-improvement. Two-phase approach - supervised learning with self-critique/revision, then RLAIF (RL from 321skills.sh installs
2syncfusion avatarsyncfusion-angular-chat-uisyncfusion/angular-ui-components-skillsImplement the Syncfusion Angular Chat UI component. Use this skill whenever users need to implement messaging, real-time conversations, file attachments, typing321skills.sh installs
3hughyau avatararming-thoughthughyau/qiushi-skill触发:在每次新的顶层对话开始时自动调用,用于建立“实事求是”的总原则,并在明确适用时为后续任务选择下游 skill;如果你是被派遣执行单一具体任务的子 agent,则跳过此 skill。 English: Trigger at the start of each new top-level conversation t319skills.sh installs
4agricidaniel avatarwiki-cliagricidaniel/claude-obsidianDefault vault-mutation transport for claude-obsidian v1.7+. Wraps the Obsidian CLI (Obsidian 1.12+) as the preferred way to read, write, search, and modify vaul317skills.sh installs
5ndpvt-web avatarlatex-documentndpvt-web/latex-document-skillUniversal LaTeX document skill: create, compile, and convert any document to professional PDF with PNG previews. Supports resumes, reports, cover letters, invoi317skills.sh installs
6pr-pm avatarhuman-writingpr-pm/prpmWrite content that sounds natural, conversational, and authentically human - avoiding AI-generated patterns, corporate speak, and generic phrasing316skills.sh installs