Skip to content

feat: agent skill/rule that guides agents toward native Bun APIs #120

Closed

Description

@blimmer

What's the problem?

This monorepo runs exclusively on Bun, but agents (Claude Code, Codex, etc.) consistently reach for node-fs / hand-rolled patterns when a native Bun API would be cleaner and idiomatic for this codebase. Recent examples from PR review:

The pattern: agents default to the Node API surface from their training data and miss Bun-specific affordances even when they make the code materially shorter and more idiomatic.

Proposed solution

Add an agent-loaded skill or .contextbridge/rules/ file (similar to the existing error-handling-neverthrow.md and testing-patterns.md) that:

  1. States the project is Bun-first — agents should reach for Bun.* globals before equivalent Node APIs.
  2. Lists the high-value cases with before/after pairs. Initial set:
    • Bun.Glob for file-pattern matching (vs. manual readdirSync walking)
    • Bun.file(path).text() for reading text (vs. readFileSync)
    • Bun.spawn / Bun.spawnSync (vs. child_process.spawn)
    • Bun.serve for HTTP (already used in packages/server)
    • bun:test runner (vs. importing third-party test libraries)
    • Bun macros for compile-time evaluation in build/codegen paths
  3. Calls out scope — application code that ships to consumers running under non-Bun runtimes shouldn't depend on Bun.* globals. CLI/build/script code can. Today the only externally-facing runtime is the compiled contextbridge binary, which IS Bun, so this restriction is mostly theoretical for the moment.
  4. Hooks into the existing rule auto-load — .claude/rules/*.md is already auto-loaded by Claude Code when editing files in this repo; the new rule should live there (or .contextbridge/rules/ if it should apply to all harnesses).

Alternatives you considered

  • ESLint rule — could flag readdirSync with recursive: true and suggest Bun.Glob. Higher precision but lower coverage; doesn't help with macros, Bun.spawn, etc. where the trigger isn't a single AST shape.
  • CLAUDE.md / AGENTS.md note — possible but those files are already dense; a dedicated rule is more discoverable.
  • Do nothing — accept that PR review catches these. Works but burns reviewer attention on the same pattern across every PR.

Additional context

Discussion thread: #115 (comment)

blimmer: Great callout! I wonder if we should have some agent skill that guides it to use more native bun solutions (like this, macros in your previous DB PR, etc.)

jcarver989: yea, worth trying!

This is the spinoff issue from that thread.

Activity

  1. added
    enhancement
    on May 14, 2026
  2. added a commit that references this issue on May 15, 2026
    99f5c08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions