Open-Source Wikis

/

Bun

/

Apps

oven-sh/bun

Apps

Bun ships as a single executable with many subcommands. Each "app" in this section is one subcommand or one major user-facing surface. They share a process, an event loop, and most subsystems — they are not separate binaries.

The CLI dispatcher is in src/cli.zig (~78,000 lines of Zig). It parses argv via src/cli/Arguments.zig, picks a Command enum variant, and calls the matching *_command.zig file under src/cli/.

Subcommands and their entry points

Subcommand Entry point Page
bun run, bun ./script, bun -e ... src/cli/run_command.zig Runtime
bun install, bun add, bun remove, bun update, bun pm, bun outdated, bun audit, bun publish, bun pack, bun why, bun link/unlink, bun patch/patch-commit src/cli/install_command.zig and friends Package manager
bun build, Bun.build src/cli/build_command.zig, src/bundler/bundle_v2.zig Bundler
bun test src/cli/test_command.zig Test runner
bun x, bunx src/cli/bunx_command.zig bunx
bun init, bun create src/cli/init_command.zig, src/cli/create_command.zig Misc commands
bun repl src/cli/repl_command.zig Misc commands
bun upgrade src/cli/upgrade_command.zig Misc commands
bun completions src/cli/install_completions_command.zig Misc commands
Embedded shell (Bun.$) src/shell/interpreter.zig Shell
Dev server (Bake) src/bake/DevServer.zig Bake (dev server)

How a command is dispatched

sequenceDiagram
    participant Sh as Shell
    participant Main as src/main.zig
    participant Bun as src/bun.zig
    participant CLI as src/cli.zig
    participant Args as src/cli/Arguments.zig
    participant Cmd as src/cli/<cmd>_command.zig

    Sh->>Main: argv
    Main->>Bun: bun.main()
    Bun->>Bun: install allocator + crash handler + signals
    Bun->>CLI: Cli.start(allocator)
    CLI->>Args: Arguments.parse(argv)
    Args-->>CLI: parsed options + Command tag
    CLI->>Cmd: Command.exec(ctx)
    Cmd-->>CLI: exit code
    CLI-->>Sh: exit

The dispatcher is also responsible for recognising bun invocations made through node shims (bun --bun node ...), Yarn-equivalent commands (bun addyarn add), and shell completions.

Shared building blocks

Every app pulls from the same core library:

  • Loggersrc/logger.zig (~55 KB) — diagnostics, error rendering, source-mapped stack traces.
  • Outputsrc/output.zig (~46 KB) — stdout/stderr with <r><red>...</r> ANSI markup.
  • fs / syssrc/fs.zig, src/sys.zig (~165 KB) — POSIX/Windows abstractions. All file I/O goes through sys.zig.
  • HTTP clientsrc/http/HTTPThread.zig — used by fetch(), bun install, bunx, bun upgrade.
  • JSON parsersrc/json_parser.zig — used by every package.json reader.

When you change one of these, audit every command that uses it.

Active contributors

For per-subsystem ownership and active contributors, see maintainers.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Apps – Bun wiki | Factory