Build Bun natively on FreeBSD. Based on Li-Wen Hsu's claude/freebsd-support branch with additional patches for WebKit, bootstrap toolchain, and cmake wiring.
git clone https://github.com/8ff/bun-freebsd.git
cd bun-freebsd
sh build.shRequires FreeBSD 13.2+ amd64, ~16 GB RAM, ~20 GB disk. The script installs all dependencies via pkg, clones the source trees, builds Bun's Zig fork, applies patches, and compiles Bun + WebKit/JSC.
Output: ~/src/bun/build/bun — a native FreeBSD ELF.
After building, grab cli.js from the npm package (while it's still available — Anthropic has said this is being deprecated):
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
npm install -g @anthropic-ai/claude-codeThen run it under your native bun:
~/src/bun/build/bun ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js --versionFor convenience, create a wrapper:
mkdir -p ~/.local/bin
cat > ~/.local/bin/claude <<'EOF'
#!/bin/sh
exec ~/src/bun/build/bun ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js "$@"
EOF
chmod +x ~/.local/bin/claudeNote: cli.js is Anthropic's proprietary code (not included in this repo). Anthropic has stated they plan to deprecate the npm package. This repo only contains the Bun build script and patches — sourcing cli.js is on you.
~150 lines on top of lwhsu's branch:
- WebKit
AvailableMemory.cpp— FreeBSD branch was using Linux-onlystruct sysinfo; replaced withsysctlbyname("hw.physmem") - WebKit
RAMSize.cpp— removed FreeBSD from#include <sys/sysinfo.h>guard (Linux-only header) SetupWebKit.cmake— passUSE_SYSTEM_MALLOC=ONto JSC on FreeBSD (lwhsu had a comment for this but never wired it)codegen-ts-node-runner.mjs— fix esbuild output format for Node bootstrap: strip__commonJSwrapper, removeinit_define_*no-ops, disablekeepNamesto avoid__name()helperbundle-functions.ts— removeif (import.meta.main)guard that esbuild's--defineconstant-folds toif (true)in bundled outputglob-sources-node.mjs(new) — Node port of Bun-requiringglob-sources.mjsfor bootstrap on hosts without an existing Bun binary
- Li-Wen Hsu (@lwhsu) — ~90% of the FreeBSD port
- Upstream: oven-sh/bun, oven-sh/WebKit, oven-sh/zig