skills/bun-guides-util-detect-bun/SKILL.md
Detect when code is executed with Bun
npx skillsauth add jarle/bun-skills Bun Detect when code is executed with BunInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The recommended way to detect when code is being executed with Bun is to check process.versions.bun. This works in both JavaScript and TypeScript without requiring any additional type definitions.
if (process.versions.bun) {
// this code will only run when the file is run with Bun
}
Alternatively, you can check for the existence of the Bun global. This is similar to how you'd check for the existence of the window variable to detect when code is being executed in a browser.
if (typeof Bun !== "undefined") {
// this code will only run when the file is run with Bun
}
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling