# bunfig.toml

> Configure Bun's behavior using its configuration file bunfig.toml

`bunfig.toml` is Bun's configuration file.

Bun relies on pre-existing configuration files like `package.json` and `tsconfig.json` where it can; `bunfig.toml` is only for Bun-specific settings. The file is optional, and Bun works without it.

## Global vs. local

Put `bunfig.toml` in your project root, alongside your `package.json`.

To configure Bun's package manager globally, you can also create a `.bunfig.toml` file at one of the following paths:

- `$HOME/.bunfig.toml`
- `$XDG_CONFIG_HOME/.bunfig.toml`

Only package manager commands (`bun install`, `bun add`, `bun remove`, `bun update`, `bun pm`, `bunx`, and so on) read the global file. If Bun finds both a global and a local `bunfig`, it loads both; keys set in the local file override the same keys in the global file. CLI flags override `bunfig` settings where applicable.

## Runtime

Top-level fields in `bunfig.toml` configure Bun's runtime behavior.

### `preload`

An array of scripts/plugins to execute before running a file or script.

```toml title="bunfig.toml" icon="settings"
# scripts to run before `bun run`-ing a file or script
# register plugins by adding them to this list
preload = ["./preload.ts"]
```

### `jsx`

Configure how Bun handles JSX. You can also set these fields in the `compilerOptions` of your `tsconfig.json`, but `bunfig.toml` supports them for non-TypeScript projects.

```toml title="bunfig.toml" icon="settings"
jsx = "react"
jsxFactory = "h"
jsxFragment = "Fragment"
jsxImportSource = "react"
```

Refer to the tsconfig docs for more information on these fields.

- [`jsx`](https://www.typescriptlang.org/tsconfig#jsx)
- [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory)
- [`jsxFragment`](https://www.typescriptlang.org/tsconfig#jsxFragment)
- [`jsxImportSource`](https://www.typescriptlang.org/tsconfig#jsxImportSource)

### `smol`

Enable `smol` mode. This reduces memory usage at the cost of performance.

```toml title="bunfig.toml" icon="settings"
# Reduce memory usage at the cost of performance
smol = true
```

### `logLevel`

Set the log level: `"debug"`, `"warn"`, or `"error"`.

```toml title="bunfig.toml" icon="settings"
logLevel = "debug" # "debug" | "warn" | "error"
```

### `define`

The `define` field replaces global identifiers with constant expressions wherever they appear. The expression should be a JSON string.

```toml title="bunfig.toml" icon="settings"
[define]
# Replace any usage of "process.env.bagel" with the string `lox`.
# The values are parsed as JSON, except single-quoted strings are supported and `'undefined'` becomes `undefined` in JS.
# This will probably change in a future release to be just regular TOML instead. It is a holdover from the CLI argument parsing.
"process.env.bagel" = "'lox'"
```

### `loader`

Configure how Bun maps file extensions to [loaders](https://aphrody.app/docs/bundler/loaders). Use this to load file types Bun doesn't support natively.

```toml title="bunfig.toml" icon="settings"
[loader]
# when a .bagel file is imported, treat it like a tsx file
".bagel" = "tsx"
```

Bun supports the following loaders:

- `jsx`
- `js`
- `ts`
- `tsx`
- `css`
- `file`
- `json`
- `toml`
- `wasm`
- `napi`
- `base64`
- `dataurl`
- `text`

### `telemetry`

The `telemetry` field enables or disables analytics. By default, telemetry is enabled. This setting is equivalent to the `DO_NOT_TRACK` environment variable.

We do not currently collect telemetry; this setting only controls anonymous crash reports. We plan to collect information like which Bun APIs are used most or how long `bun build` takes.

```toml title="bunfig.toml" icon="settings"
telemetry = false
```

### `env`

Configure automatic `.env` file loading. Bun loads `.env` files by default. To disable this behavior:

```toml title="bunfig.toml" icon="settings"
# Disable automatic .env file loading
env = false
```

You can also use object syntax with the `file` property:

```toml title="bunfig.toml" icon="settings"
[env]
file = false
```

Use this in production or CI/CD pipelines where you want to rely solely on system environment variables.

Bun still loads files passed explicitly with `--env-file` even when default loading is disabled.

### `console`

Configure console output behavior.

#### `console.depth`

Set the default depth for `console.log()` object inspection. Default `2`.

```toml title="bunfig.toml" icon="settings"
[console]
depth = 3
```

Higher values show more nested properties but may produce verbose output for complex objects. The `--console-depth` CLI flag overrides this setting.

## Serve

The `[serve]` section configures `Bun.serve` and `bun run` when serving HTTP.

### `serve.port`

The default port for `Bun.serve` to listen on. Default `3000`. You can also set it with the `BUN_PORT` or `PORT` environment variables, or the `--port` flag.

```toml title="bunfig.toml" icon="settings"
[serve]
port = 3000
```

## Lint and format

[`bun lint`](https://aphrody.app/docs/runtime/lint) and [`bun fmt`](https://aphrody.app/docs/runtime/fmt) run their linked native engines. They do not use `[lint]` or `[fmt]` sections to select executables, versions or downloads.

Use `.oxlintrc.json` or `.oxlintrc.jsonc` for lint rules, and `.oxfmtrc.json` or `.oxfmtrc.jsonc` for formatting options. Pass `--config` for an explicit configuration, filesystem operands for scope and `--ignore-pattern` for exclusions.

```sh
bun lint --config .oxlintrc.json src
bun fmt --config .oxfmtrc.json --check src
```

## Test runner

The `[test]` section of `bunfig.toml` configures the test runner.

```toml title="bunfig.toml" icon="settings"
[test]
# configuration goes here
```

### `test.root`

The root directory to run tests from. Default `.`.

```toml title="bunfig.toml" icon="settings"
[test]
root = "./__tests__"
```

### `test.preload`

Same as the top-level `preload` field, but only applies to `bun test`.

```toml title="bunfig.toml" icon="settings"
[test]
preload = ["./setup.ts"]
```

### `test.pathIgnorePatterns`

Exclude files and directories from test discovery using glob patterns. The test runner prunes matched directories during scanning, so it never traverses their contents. Use this when your project contains submodules or vendored code with `*.test.ts` files that you don't want `bun test` to pick up.

```toml title="bunfig.toml" icon="settings"
[test]
pathIgnorePatterns = ["vendor/**", "submodules/**", "fixtures/**"]
```

Equivalent CLI flag: `--path-ignore-patterns`. CLI flags override the `bunfig.toml` value entirely.

### `test.snapshotSerializers`

Modules whose default export (or the module itself) is a Jest/Vitest snapshot serializer, an object with `test()` and either `serialize()` or `print()`. They load after `test.preload` and are registered as if passed to `expect.addSnapshotSerializer()`. Paths resolve like `test.preload`.

```toml title="bunfig.toml" icon="settings"
[test]
snapshotSerializers = ["./test/serializers/date.ts"]
```

### `test.smol`

Same as the top-level `smol` field, but only applies to `bun test`.

```toml title="bunfig.toml" icon="settings"
[test]
smol = true
```

### `test.coverage`

Enables coverage reporting. Default `false`. Use `--coverage` to override.

```toml title="bunfig.toml" icon="settings"
[test]
coverage = false
```

### `test.coverageThreshold`

The coverage threshold. By default, no threshold is set. If your test suite does not meet it, `bun test` exits with a non-zero exit code.

```toml title="bunfig.toml" icon="settings"
[test]

# to require 90% line-level and function-level coverage
coverageThreshold = 0.9
```

You can set separate thresholds for line and function coverage. Bun accepts a `statements` key but does not currently enforce it.

```toml title="bunfig.toml" icon="settings"
[test]
coverageThreshold = { lines = 0.7, functions = 0.8 }
```

### `test.coverageSkipTestFiles`

Whether to skip test files when computing coverage statistics. Default `false`.

```toml title="bunfig.toml" icon="settings"
[test]
coverageSkipTestFiles = false
```

### `test.coverageIgnoreSourcemaps`

Whether to report coverage against transpiled output instead of remapping line numbers through sourcemaps back to the original source. Default `false`. Primarily useful for debugging.

```toml title="bunfig.toml" icon="settings"
[test]
coverageIgnoreSourcemaps = false
```

### `test.coveragePathIgnorePatterns`

Exclude files from coverage reports using glob patterns. Accepts a single pattern or an array of patterns.

```toml title="bunfig.toml" icon="settings"
[test]
# Single pattern
coveragePathIgnorePatterns = "**/*.spec.ts"

# Multiple patterns
coveragePathIgnorePatterns = [
  "**/*.spec.ts",
  "**/*.test.ts",
  "src/utils/**",
  "*.config.js"
]
```

### `test.coverageReporter`

By default, the test runner prints coverage reports to the console. For persistent reports that CI and other tools can read, use `lcov`.

```toml title="bunfig.toml" icon="settings"
[test]
coverageReporter  = ["text", "lcov"]  # default ["text"]
```

### `test.coverageDir`

Set the path where coverage reports are saved. This only applies to persistent reporters like `lcov`.

```toml title="bunfig.toml" icon="settings"
[test]
coverageDir = "path/to/somewhere"  # default "coverage"
```

### `test.randomize`

Run tests in random order. Default `false`.

```toml title="bunfig.toml" icon="settings"
[test]
randomize = true
```

Running tests in a different order each time helps catch bugs related to test interdependencies. When combined with `seed`, the random order becomes reproducible.

The `--randomize` CLI flag overrides this setting.

### `test.seed`

Set the random seed for test randomization. This option requires `randomize` to be `true`.

```toml title="bunfig.toml" icon="settings"
[test]
randomize = true
seed = 2444615283
```

A seed makes the randomized test order reproducible across runs, which helps when debugging flaky tests.

The `--seed` CLI flag overrides this setting.

### `test.rerunEach`

Re-run each test file a specified number of times. Default `0` (run once).

```toml title="bunfig.toml" icon="settings"
[test]
rerunEach = 3
```

Use this to catch flaky tests or non-deterministic behavior.

The `--rerun-each` CLI flag overrides this setting.

### `test.retry`

Default retry count for all tests. The test runner retries failed tests up to this many times. Per-test `{ retry: N }` overrides this value. Default `0` (no retries).

```toml title="bunfig.toml" icon="settings"
[test]
retry = 3
```

The `--retry` CLI flag overrides this setting.

### `test.concurrentTestGlob`

Test files matching this glob pattern run all of their tests concurrently, as if you passed the `--concurrent` flag.

```toml title="bunfig.toml" icon="settings"
[test]
concurrentTestGlob = "**/concurrent-*.test.ts"
```

Use this to migrate a test suite to concurrent execution gradually, or to run integration tests concurrently while keeping unit tests sequential.

The `--concurrent` CLI flag overrides this setting.

### `test.onlyFailures`

When enabled, the output shows only failed tests, which reduces noise in large test suites. Default `false`.

```toml title="bunfig.toml" icon="settings"
[test]
onlyFailures = true
```

Equivalent to the `--only-failures` flag.

### `test.reporter`

Configure the test reporter settings.

#### `test.reporter.dots`

Enable the dots reporter, which prints one dot per test. Default `false`.

```toml title="bunfig.toml" icon="settings"
[test.reporter]
dots = true
```

#### `test.reporter.junit`

Enable JUnit XML reporting and specify the output file path.

```toml title="bunfig.toml" icon="settings"
[test.reporter]
junit = "test-results.xml"
```

CI systems and other tools can consume the report.

## Linter

The `[lint]` section configures [`bun lint`](https://aphrody.app/docs/lint). Run `bun lint --init` to add it.

```toml title="bunfig.toml" icon="settings"
[lint]
typeAware = true
ignorePatterns = ["vendor/", "**/*.gen.ts"]

[lint.rules]
"no-console" = "warn"
eqeqeq = ["error", "smart"]

[[lint.overrides]]
files = ["scripts/**"]
rules = { "no-console" = "off" }
```

`bun lint` uses the nearest `bunfig.toml` that has a `[lint]` section, from the working directory up, so it finds the same problems from any directory of the project. Next to an ESLint or oxlint config, what those tools read from the working directory is still read from there.

Paths and patterns in the section are relative to the file, including the ones in the options of the `import` rules. So are the patterns in a config file that `config` names and the file names in the file that `suppressionsLocation` names.

With `bun --config=<path> lint`, everything but `plugins` is relative to the working directory.

A typo is an error. `bun lint` exits with code `2` on an unknown key or an unknown rule.

```txt
2 | "no-vra" = "error"
    ^
error: Unknown rule "no-vra"
  Did you mean "no-var"?
    at bunfig.toml:2:1
```

### `lint.rules`

Set a rule to `"off"`, `"warn"`, or `"error"`. To pass options, use an array. Every rule in `bun lint --rules` works, with nothing to install.

```toml title="bunfig.toml" icon="settings"
[lint.rules]
"no-console" = "warn"
"@typescript-eslint/no-explicit-any" = "off"
"unicorn/prefer-node-protocol" = "error"
"no-restricted-imports" = ["error", { paths = ["lodash"] }]
```

Some ESLint rules have a typescript-eslint version, such as `no-unused-vars` and `@typescript-eslint/no-unused-vars`. Setting either name sets both. The ESLint rule runs on JavaScript files and the typescript-eslint rule on TypeScript files, so a problem is never reported twice. If you set both names, each one applies to its own kind of file.

A few typescript-eslint versions need type information, such as `@typescript-eslint/require-await`. Setting that name type checks your TypeScript files, like any other [type-aware rule](https://aphrody.app/docs/lint#type-aware-rules). Setting only `require-await` doesn't start a type check. It uses the typescript-eslint version if the run has types anyway, and the ESLint rule otherwise.

### `lint.plugins`

Load [ESLint plugins](https://aphrody.app/docs/lint/plugins): paths, relative to `bunfig.toml`, or package names. Their rules are added to the built-in ones.

```toml title="bunfig.toml" icon="settings"
[lint]
plugins = ["./lint/plugin.js", "eslint-plugin-perfectionist"]

[lint.rules]
"local/no-todo" = "warn"
"perfectionist/sort-imports" = "error"
```

### `lint.categories`

Set a whole category of rules at once. `[lint.rules]` wins over a category.

```toml title="bunfig.toml" icon="settings"
[lint.categories]
suspicious = "warn"
perf = "warn"
```

| Category      | What its rules report                          |
| ------------- | ---------------------------------------------- |
| `correctness` | Code that is wrong or useless                  |
| `suspicious`  | Code that is probably wrong or useless         |
| `pedantic`    | Strict checks, with some false positives       |
| `perf`        | Code that could run faster                     |
| `style`       | Code that could be more idiomatic              |
| `restriction` | Language features and patterns you want to ban |
| `nursery`     | New rules that are still changing              |
| `all`         | Every category at once                         |

### `lint.overrides`

Use different rules for some files. `files` is required. `excludeFiles`, `rules`, `globals`, and `settings` are optional.

```toml title="bunfig.toml" icon="settings"
[[lint.overrides]]
files = ["*.test.ts", "scripts/**"]
excludeFiles = ["scripts/vendor/**"]
rules = { "no-console" = "off" }
```

Patterns use the same syntax as [`Bun.Glob`](https://aphrody.app/docs/runtime/glob) and are relative to `bunfig.toml`. A pattern without a slash matches the file name in any directory. Later overrides win over earlier ones, and all of them win over `[lint.rules]`.

### `lint.ignorePatterns`

Skip the files that match. `bun lint` already skips `node_modules` and everything in `.gitignore`.

```toml title="bunfig.toml" icon="settings"
[lint]
ignorePatterns = ["vendor/", "**/*.gen.ts"]
```

### `lint.settings`

Settings that rules share, such as the React version. The same as `settings` in an ESLint or oxlint config.

```toml title="bunfig.toml" icon="settings"
[lint.settings.react]
version = "18.2"

[lint.settings."jsx-a11y".components]
Picture = "img"
```

### `lint.typeAware`

Turn on typescript-eslint's recommended [type-aware rules](https://aphrody.app/docs/lint#type-aware-rules), such as `@typescript-eslint/no-floating-promises`. Default `false`.

```toml title="bunfig.toml" icon="settings"
[lint]
typeAware = true
tsconfig = "./tsconfig.lint.json" # default: the nearest tsconfig.json
```

You don't need it for a single rule. A type-aware rule runs as soon as you turn it on in `[lint.rules]`. `typeAware = false` skips every type-aware rule.

### `lint.typeCheck`

Also report type errors, like [`bun check`](https://aphrody.app/docs/runtime/check). It turns on no rules. Default `false`.

```toml title="bunfig.toml" icon="settings"
[lint]
typeCheck = true
```

### `lint.globals`

Declare global variables, so that `no-undef` accepts them. A global is `"readonly"`, `"writable"`, or `"off"`.

```toml title="bunfig.toml" icon="settings"
[lint.globals]
MY_GLOBAL = "readonly"
```

### `lint.maxWarnings`

Exit with code `1` if there are more warnings than this. By default, warnings never fail a run.

```toml title="bunfig.toml" icon="settings"
[lint]
maxWarnings = 0
```

### All keys

Every flag that makes sense as a default is also a key, in camelCase: `--max-warnings 0` is `maxWarnings = 0`, and `--no-inline-config` is `inlineConfig = false`. The command line wins over `bunfig.toml`.

| Key                             | Value                                 | Flag                                                |
| ------------------------------- | ------------------------------------- | --------------------------------------------------- |
| `rules`                         | table                                 | `--rule`                                            |
| `plugins`                       | array                                 | `--plugin`                                          |
| `categories`                    | table                                 | `-A`, `-W`, `-D`                                    |
| `overrides`                     | array of tables                       |                                                     |
| `globals`                       | table                                 | `--global`                                          |
| `settings`                      | table                                 |                                                     |
| `ignorePatterns`                | array                                 | `--ignore-pattern`                                  |
| `typeAware`                     | boolean                               | `--type-aware`, `--no-type-aware`                   |
| `typeCheck`                     | boolean                               | `--type-check`                                      |
| `tsconfig`                      | path                                  | `--tsconfig`                                        |
| `inferGlobals`                  | boolean                               | `--infer-globals`, `--no-infer-globals`             |
| `maxWarnings`                   | number                                | `--max-warnings`                                    |
| `denyWarnings`                  | boolean                               | `--deny-warnings`                                   |
| `quiet`                         | boolean                               | `--quiet`                                           |
| `silent`                        | boolean                               | `--silent`                                          |
| `format`                        | name                                  | `-f`, `--format`                                    |
| `all`                           | boolean                               | `--all`                                             |
| `threads`                       | number                                | `--threads`                                         |
| `inlineConfig`                  | boolean                               | `--no-inline-config`                                |
| `reportUnusedDisableDirectives` | boolean, `"off"`, `"warn"`, `"error"` | `--report-unused-disable-directives`                |
| `reportUnusedInlineConfigs`     | `"off"`, `"warn"`, `"error"`          | `--report-unused-inline-configs`                    |
| `fixType`                       | array                                 | `--fix-type`                                        |
| `config`                        | path                                  | `-c`, `--config`                                    |
| `configLookup`                  | boolean                               | `--no-config-lookup`                                |
| `disableNestedConfig`           | boolean                               | `--disable-nested-config`                           |
| `allowUnsupported`              | boolean                               | `--allow-unsupported`                               |
| `nativePluginRules`             | boolean, or an array of plugin names  | `--native-plugin-rules`, `--no-native-plugin-rules` |
| `parserOptions`                 | table                                 | `--parser-options`                                  |
| `ext`                           | array                                 | `--ext`                                             |
| `ignore`                        | boolean                               | `--no-ignore`                                       |
| `ignorePath`                    | path                                  | `--ignore-path`                                     |
| `warnIgnored`                   | boolean                               | `--no-warn-ignored`                                 |
| `errorOnUnmatchedPattern`       | boolean                               | `--no-error-on-unmatched-pattern`                   |
| `passOnNoPatterns`              | boolean                               | `--pass-on-no-patterns`                             |
| `exitOnFatalError`              | boolean                               | `--exit-on-fatal-error`                             |
| `suppressionsLocation`          | path                                  | `--suppressions-location`                           |
| `passOnUnprunedSuppressions`    | boolean                               | `--pass-on-unpruned-suppressions`                   |

`bun lint --help --all` says what each flag does.

`[lint]` also applies next to an `eslint.config.js` or an `.oxlintrc.json`. There, a key overrides the config file the way its flag does.

## Formatter

The `[fmt]` section configures [`bun fmt`](https://aphrody.app/docs/format). Run `bun fmt --init` to add it.

```toml title="bunfig.toml" icon="settings"
[fmt]
printWidth = 100
semi = false
sortImports = true
ignorePatterns = ["vendor/", "**/*.gen.ts"]
```

`bun fmt` uses the nearest `bunfig.toml` that has a `[fmt]` section, from the working directory up, so it prints the same from any directory of the project.

Paths and patterns in the section are relative to the file. With `bun --config=<path> fmt` they are relative to the working directory.

A typo doesn't go unnoticed. An unknown key or a bad value is an error, and `bun fmt` exits with code `2`.

### Style options

Same names, defaults, and meaning as [Prettier's options](https://prettier.io/docs/options). Each one is also a flag, like `--print-width 100` or `--no-semi`, and the flag wins.

| Key                            | Default       | What it does                                                          |
| ------------------------------ | ------------- | --------------------------------------------------------------------- |
| `printWidth`                   | `80`          | Wrap lines at this column                                             |
| `tabWidth`                     | `2`           | Spaces per indentation level                                          |
| `useTabs`                      | `false`       | Indent with tabs                                                      |
| `semi`                         | `true`        | Print semicolons                                                      |
| `singleQuote`                  | `false`       | Use single quotes                                                     |
| `jsxSingleQuote`               | `false`       | Use single quotes in JSX                                              |
| `quoteProps`                   | `"as-needed"` | Quote object keys: `"as-needed"`, `"consistent"`, or `"preserve"`     |
| `trailingComma`                | `"all"`       | `"all"`, `"es5"`, or `"none"`                                         |
| `bracketSpacing`               | `true`        | `{ a }` or `{a}`                                                      |
| `bracketSameLine`              | `false`       | Put the `>` of a multi-line element at the end of the last line       |
| `arrowParens`                  | `"always"`    | `(x) => x` or, with `"avoid"`, `x => x`                               |
| `objectWrap`                   | `"preserve"`  | `"collapse"` puts an object on one line whenever it fits              |
| `singleAttributePerLine`       | `false`       | One attribute per line in HTML, Vue, and JSX                          |
| `proseWrap`                    | `"preserve"`  | Wrap Markdown text: `"always"`, `"never"`, or `"preserve"`            |
| `endOfLine`                    | `"lf"`        | `"lf"`, `"crlf"`, `"cr"`, or `"auto"`                                 |
| `htmlWhitespaceSensitivity`    | `"css"`       | How whitespace in HTML is treated: `"css"`, `"strict"`, or `"ignore"` |
| `vueIndentScriptAndStyle`      | `false`       | Indent the code in `<script>` and `<style>` of Vue files              |
| `embeddedLanguageFormatting`   | `"auto"`      | `"off"` leaves embedded code alone, like CSS in a template literal    |
| `experimentalTernaries`        | `false`       | Prettier's new style for nested ternaries                             |
| `experimentalOperatorPosition` | `"end"`       | `"start"` puts a binary operator at the start of the next line        |

### `format.sortImports`

[Sort, group, and merge imports](https://aphrody.app/docs/format#sort-imports). Default `false`.

```toml title="bunfig.toml" icon="settings"
[fmt]
sortImports = true
```

To change the groups, use a table. These are the defaults:

```toml title="bunfig.toml" icon="settings"
[fmt.sortImports]
groups = ["builtin", "external", ["internal", "subpath"], ["parent", "sibling", "index"], "style", "unknown"]
internalPattern = ["~/", "@/", "#"]
newlinesBetween = true
```

| Key                  | Default | What it does                                                                  |
| -------------------- | ------- | ----------------------------------------------------------------------------- |
| `groups`             | above   | The order of the groups. A nested array merges several groups into one        |
| `customGroups`       | `[]`    | Your own groups: `{ groupName = "ui", elementNamePattern = ["@acme/ui/**"] }` |
| `internalPattern`    | above   | The prefixes that count as `internal`                                         |
| `newlinesBetween`    | `true`  | A blank line between groups                                                   |
| `order`              | `"asc"` | `"asc"` or `"desc"`                                                           |
| `ignoreCase`         | `true`  | `a` and `A` sort together                                                     |
| `sortSideEffects`    | `false` | Also move side-effect imports, like `import "./setup"`                        |
| `partitionByComment` | `false` | Sort the imports before and after a comment line separately                   |
| `partitionByNewline` | `false` | The same for a blank line. Needs `newlinesBetween = false`                    |

To give type imports a group of their own, prefix a group with `type-`, like `"type-external"`, or use `"type"` for all of them.

### `format.sortTailwindcss`

[Sort Tailwind CSS classes](https://aphrody.app/docs/format#sort-tailwind-css-classes). Default `false`. Needs `tailwindcss` version 3 or 4 installed in the project.

```toml title="bunfig.toml" icon="settings"
[fmt.sortTailwindcss]
stylesheet = "./src/app.css"
functions = ["clsx", "tw"]
```

| Key                  | What it does                                                          |
| -------------------- | --------------------------------------------------------------------- |
| `stylesheet`         | Tailwind 4: the CSS file that imports Tailwind                        |
| `config`             | Tailwind 3: the path of `tailwind.config.js`                          |
| `functions`          | Sort the strings passed to these functions. Replaces the default list |
| `attributes`         | Sort these attributes too, besides `class` and `className`            |
| `preserveWhitespace` | Keep the whitespace between classes                                   |
| `preserveDuplicates` | Keep duplicate classes                                                |

By default, `functions` is `clsx`, `cn`, `cva`, `cx`, `classNames`, `classnames`, `twMerge`, `twJoin`, and `tv`.

### `format.sortPackageJson`

[Sort the keys of `package.json`](https://aphrody.app/docs/format#sort-package-json). Default `false`.

```toml title="bunfig.toml" icon="settings"
[fmt]
sortPackageJson = true
```

`sortPackageJson = { sortScripts = true }` sorts `scripts` by name too.

### `format.jsdoc`

[Format JSDoc comments](https://aphrody.app/docs/format#format-jsdoc-comments). Default `false`.

```toml title="bunfig.toml" icon="settings"
[fmt]
jsdoc = true
```

| Key                           | Default        | What it does                                                                |
| ----------------------------- | -------------- | --------------------------------------------------------------------------- |
| `capitalizeDescriptions`      | `true`         | Start descriptions with a capital letter                                    |
| `descriptionWithDot`          | `false`        | End descriptions with a period                                              |
| `descriptionTag`              | `false`        | Put `@description` before the description                                   |
| `addDefaultToDescription`     | `true`         | Add ``Default is `1` `` to the description of `@param {number} [a=1]`       |
| `commentLineStrategy`         | `"singleLine"` | Put a short comment on one line: `"singleLine"`, `"multiline"`, or `"keep"` |
| `separateTagGroups`           | `false`        | A blank line between different tags                                         |
| `separateReturnsFromParam`    | `false`        | A blank line between `@param` and `@returns`                                |
| `bracketSpacing`              | `false`        | `{ number }` instead of `{number}`                                          |
| `preferCodeFences`            | `false`        | Turn indented code into a fenced code block                                 |
| `lineWrappingStyle`           | `"greedy"`     | `"balance"` makes wrapped lines about the same length                       |
| `keepUnparsableExampleIndent` | `false`        | Keep the indentation of an `@example` that doesn't parse                    |

### `format.svelte`

[Format Svelte components](https://aphrody.app/docs/format#svelte). Default `true`. `svelte = false` leaves `.svelte` files alone, and the Svelte code blocks in Markdown.

```toml title="bunfig.toml" icon="settings"
[fmt.svelte]
sortOrder = "scripts-markup-styles-options"
```

| Key                    | Default                           | What it does                                                                                |
| ---------------------- | --------------------------------- | ------------------------------------------------------------------------------------------- |
| `sortOrder`            | `"options-scripts-markup-styles"` | The order of `<svelte:options>`, the scripts, the markup, and the styles. `"none"` keeps it |
| `allowShorthand`       | `true`                            | Print `a={a}` as `{a}`                                                                      |
| `indentScriptAndStyle` | `true`                            | Indent the code in `<script>` and `<style>`                                                 |

Next to a `.prettierrc` or an `.oxfmtrc.json`, the default is what that file says: Prettier formats `.svelte` files if it lists `prettier-plugin-svelte`, and oxfmt if it has `svelte`. The key overrides the file either way. With `svelte = true`, Bun formats the files whichever version of the plugin is installed.

### `format.ignorePatterns`

Skip the files that match. `bun fmt` already skips `node_modules` and everything in `.gitignore`.

```toml title="bunfig.toml" icon="settings"
[fmt]
ignorePatterns = ["vendor/", "**/*.gen.ts"]
```

### `format.overrides`

Different options for some files. Later entries win over earlier ones, and a flag wins over all of them.

```toml title="bunfig.toml" icon="settings"
[[fmt.overrides]]
files = ["*.test.ts", "scripts/**"]
excludeFiles = ["scripts/vendor/**"]
options = { printWidth = 120, sortImports = false }
```

- `files` and `excludeFiles` take a glob or an array of globs, relative to `bunfig.toml`. They use the same syntax as [`Bun.Glob`](https://aphrody.app/docs/runtime/glob). A glob without a slash matches the file name in any directory.
- `options` takes the style options, `sortImports`, `sortTailwindcss`, `sortPackageJson`, `jsdoc`, `svelte`, and `parser`.

### Every other flag

Any flag that makes sense as a default has a key: its name in camelCase. `bun fmt --help --all` lists the flags. The command line wins over `bunfig.toml`.

```toml title="bunfig.toml" icon="settings"
[fmt]
editorconfig = false # --no-editorconfig
ignorePath = [".gitignore", ".formatignore"] # --ignore-path .gitignore --ignore-path .formatignore
insertFinalNewline = false # --no-insert-final-newline
logLevel = "warn" # --log-level warn
threads = 4 # --threads 4
```

`[fmt]` also applies in a project with a `.prettierrc` or an `.oxfmtrc.json`, where a key overrides the config file as its flag does. `plugins` belong in that config file.

## Package manager

The `[install]` section configures the behavior of `bun install`.

```toml title="bunfig.toml" icon="settings"
[install]
# configuration here
```

### `install.optional`

Whether to install optional dependencies. Default `true`.

```toml title="bunfig.toml" icon="settings"
[install]
optional = true
```

### `install.dev`

Whether to install development dependencies. Default `true`.

```toml title="bunfig.toml" icon="settings"
[install]
dev = true
```

### `install.peer`

Whether to install peer dependencies. Default `true`.

```toml title="bunfig.toml" icon="settings"
[install]
peer = true
```

### `install.production`

Whether `bun install` runs in "production mode". Default `false`.

In production mode, Bun does not install `"devDependencies"` and freezes the lockfile (same as [`install.frozenLockfile`](#install-frozenlockfile)). Use the `--production` CLI flag to enable it for a single install. Since production mode freezes the lockfile, `bun add`, `bun remove`, and `bun update` fail while it is set.

```toml title="bunfig.toml" icon="settings"
[install]
production = false
```

### `install.exact`

Whether to set an exact version in `package.json`. Default `false`.

By default Bun uses caret ranges. If the `latest` version of a package is `2.4.1`, Bun writes `^2.4.1` to your `package.json`. That range accepts any version from `2.4.1` up to (but not including) `3.0.0`.

```toml title="bunfig.toml" icon="settings"
[install]
exact = false
```

### `install.ignoreScripts`

Whether to skip lifecycle scripts during install. Default `false`. Equivalent to the `--ignore-scripts` flag.

When `true`, Bun does not run any `preinstall` / `install` / `postinstall` / `prepare` scripts, both for your project and for packages in `trustedDependencies`. See [Lifecycle scripts](https://aphrody.app/docs/pm/lifecycle).

```toml title="bunfig.toml" icon="settings"
[install]
ignoreScripts = false
```

### `install.concurrentScripts`

The maximum number of concurrent lifecycle scripts to run at once. Defaults to two times the number of CPU cores. Equivalent to the `--concurrent-scripts` flag.

```toml title="bunfig.toml" icon="settings"
[install]
concurrentScripts = 5
```

### `install.saveTextLockfile`

If `false`, `bun install` generates a binary `bun.lockb` instead of a text-based `bun.lock` file when no lockfile is present.

Default `true` (since Bun v1.2).

```toml title="bunfig.toml" icon="settings"
[install]
saveTextLockfile = false
```

### `install.auto`

Configure Bun's [auto-install](https://aphrody.app/docs/runtime/auto-install) behavior. Default `"auto"` — when no `node_modules` folder is found, Bun installs dependencies on the fly during execution.

```toml title="bunfig.toml" icon="settings"
[install]
auto = "auto"
```

Valid values are:

| Value        | Description                                                                                                                         |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| `"auto"`     | Resolve modules from local `node_modules` if it exists. Otherwise, auto-install dependencies on the fly.                            |
| `"force"`    | Always auto-install dependencies, even if `node_modules` exists.                                                                    |
| `"disable"`  | Never auto-install dependencies.                                                                                                    |
| `"fallback"` | Check local `node_modules` first, then auto-install any packages that aren't found. You can enable this from the CLI with `bun -i`. |

### `install.prefer`

Configure how Bun resolves package versions against the npm registry when running scripts. Default `"online"`.

```toml title="bunfig.toml" icon="settings"
[install]
prefer = "online"
```

Valid values are:

| Value       | Description                                                                                                                         |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `"online"`  | Default. Check the registry for stale packages as needed.                                                                           |
| `"offline"` | Skip staleness checks and resolve packages from the local cache. Equivalent to `--prefer-offline` (also honoured by `bun install`). |
| `"latest"`  | Always check npm for the latest matching versions. Equivalent to `--prefer-latest`.                                                 |

### `install.offline`

When `true`, `bun install` never touches the network: package metadata and tarballs must already be in the cache, and anything missing is an error. Default `false`. Equivalent to `bun install --offline`. For the softer "use the cache when possible" behaviour see `install.prefer = "offline"` / `--prefer-offline`.

```toml title="bunfig.toml" icon="settings"
[install]
offline = true
```

### `install.frozenLockfile`

When `true`, `bun install` does not update `bun.lock`. Default `false`. If `package.json` and the existing `bun.lock` disagree, the install errors.

```toml title="bunfig.toml" icon="settings"
[install]
frozenLockfile = false
```

### `install.dryRun`

Whether `bun install` resolves dependencies without installing them. Default `false`. When `true`, it's equivalent to passing `--dry-run` to all `bun install` commands.

```toml title="bunfig.toml" icon="settings"
[install]
dryRun = false
```

### `install.globalDir`

The directory where Bun puts globally installed packages.

Environment variable: `BUN_INSTALL_GLOBAL_DIR`

```toml title="bunfig.toml" icon="settings"
[install]
# where `bun install --global` installs packages
globalDir = "~/.bun/install/global"
```

### `install.globalBinDir`

The directory where Bun links the binaries of globally installed packages.

Environment variable: `BUN_INSTALL_BIN`

```toml title="bunfig.toml" icon="settings"
[install]
# where globally-installed package bins are linked
globalBinDir = "~/.bun/bin"
```

### `install.registry`

The default registry is `https://registry.npmjs.org/`. To change it:

```toml title="bunfig.toml" icon="settings"
[install]
# set default registry as a string
registry = "https://registry.npmjs.org"
# set a token
registry = { url = "https://registry.npmjs.org", token = "123456" }
# set a username/password
registry = "https://username:password@registry.npmjs.org"
```

### `install.linkWorkspacePackages`

Whether to link workspace packages from the monorepo root to their respective `node_modules` directories. Default `true`.

```toml title="bunfig.toml" icon="settings"
[install]
linkWorkspacePackages = true
```

### `install.scopes`

To configure a registry for a particular scope (for example, `@myorg/<package>`), use `install.scopes`. You can reference environment variables with `$variable` notation.

```toml title="bunfig.toml" icon="settings"
[install.scopes]
# registry as string
myorg = "https://username:password@registry.myorg.com/"

# registry with username/password
# you can reference environment variables
myorg = { username = "myusername", password = "$npm_password", url = "https://registry.myorg.com/" }

# registry with token
myorg = { token = "$npm_token", url = "https://registry.myorg.com/" }
```

### `install.ca` and `install.cafile`

To configure a CA certificate, set `install.ca` to the certificate string or `install.cafile` to the path of a certificate file.

```toml title="bunfig.toml" icon="settings"
[install]
# The CA certificate as a string
ca = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"

# A path to a CA certificate file. The file can contain multiple certificates.
cafile = "path/to/cafile"
```

### `install.cache`

To configure the cache behavior:

```toml title="bunfig.toml" icon="settings"
[install.cache]

# the directory to use for the cache
dir = "~/.bun/install/cache"

# when true, don't load from the global cache.
# Bun may still write to node_modules/.cache
disable = false

# when true, always resolve the latest versions from the registry
disableManifest = false
```

### `install.lockfile`

Whether to generate a lockfile on `bun install`. Default `true`.

```toml title="bunfig.toml" icon="settings"
[install.lockfile]
save = true
```

Whether to generate a non-Bun lockfile alongside `bun.lock`. (Bun always creates a `bun.lock`.) `"yarn"` is the only supported value.

```toml title="bunfig.toml" icon="settings"
[install.lockfile]
print = "yarn"
```

### `install.linker`

Configure the linker strategy: how `bun install` lays out dependencies in `node_modules`. Defaults to `"isolated"` for new workspaces, `"hoisted"` for new single-package projects and existing projects (made pre-v1.3.2).

See [Isolated installs](https://aphrody.app/docs/pm/isolated-installs).

```toml title="bunfig.toml" icon="settings"
[install]
linker = "hoisted"
```

Valid values are:

| Value        | Description                                             |
| ------------ | ------------------------------------------------------- |
| `"hoisted"`  | Link dependencies in a shared `node_modules` directory. |
| `"isolated"` | Link dependencies inside each package installation.     |

### `install.globalStore`

When using the `"isolated"` linker, share package installations across projects in a global virtual store at `<cache>/links/`. Bun links `node_modules/.bun/<pkg>@<ver>` into the store instead of materializing each package into the project. Makes warm installs after `rm -rf node_modules` an order of magnitude faster. Default `false`. You can also set it with the `BUN_INSTALL_GLOBAL_STORE` environment variable.

See [Global virtual store](https://aphrody.app/docs/pm/global-store).

```toml title="bunfig.toml" icon="settings"
[install]
globalStore = true
```

### `install.publicHoistPattern`

When using the `"isolated"` linker, Bun hoists packages matching these glob patterns to the root `node_modules` directory so any package in the project can resolve them. Default `[]`. Similar to pnpm's `public-hoist-pattern`.

```toml title="bunfig.toml" icon="settings"
[install]
publicHoistPattern = ["*eslint*", "*prettier*"]
```

### `install.hoistPattern`

When using the `"isolated"` linker, Bun hoists packages matching these glob patterns to a fallback directory inside the virtual store (`node_modules/.bun/node_modules`) so other packages in the virtual store can resolve them. By default Bun hoists every package there, equivalent to `["*"]`. Similar to pnpm's `hoist-pattern`.

```toml title="bunfig.toml" icon="settings"
[install]
hoistPattern = ["*"]
```

### `install.hoist`

When using the `"isolated"` linker, Bun creates `node_modules/.bun/node_modules`. This fallback directory contains a symlink to every installed package, or only to the packages matching `install.hoistPattern` when one is set. The directory sits on the upward resolution path of every package in the store, so a package can still resolve dependencies it never declared ("phantom dependencies"). Set `hoist = false` to skip creating this directory entirely. An undeclared import from a store package then fails unless the imported package is linked at the project root `node_modules` (a direct dependency, a `publicHoistPattern` match, or a workspace package). The root `node_modules` stays on the resolution path because `.bun` lives inside it. The project's own `node_modules` symlinks are unchanged. Default `true`. Equivalent to pnpm's `hoist` setting, including this root-`node_modules` caveat; takes precedence over `install.hoistPattern`.

This setting only applies to the `"isolated"` linker. Hoisted installs are unaffected: there the flat `node_modules` tree is the layout itself, not something this switch controls.

```toml title="bunfig.toml" icon="settings"
[install]
hoist = false
```

### `install.logLevel`

Set the log level for `bun install`. This can be one of `"debug"`, `"warn"`, or `"error"`.

```toml title="bunfig.toml" icon="settings"
[install]
logLevel = "warn"
```

### `install.security.scanner`

Configure a security scanner to scan packages for vulnerabilities before installation.

First, install a security scanner from npm:

```bash terminal icon="terminal"
bun add -d @oven/bun-security-scanner
```

<Note>
  `@oven/bun-security-scanner` is an example package name, not a real package. Replace it with the scanner you want to
  use, and consult that scanner's documentation for the exact package name and installation instructions. Most scanners
  are installed with `bun add`.
</Note>

Then configure it in your `bunfig.toml`:

```toml bunfig.toml icon="settings"
[install.security]
scanner = "@oven/bun-security-scanner" # example name, replace with your scanner's package
```

When a security scanner is configured:

- Auto-install is automatically disabled for security
- Packages are scanned before installation
- Installation is cancelled if fatal issues are found
- Security warnings are displayed during installation

Learn more about [using and writing security scanners](https://aphrody.app/docs/pm/security-scanner-api).

### `install.minimumReleaseAge`

Configure a minimum age (in seconds) for npm package versions. During installation, Bun filters out package versions published more recently than this threshold. Default `null` (disabled).

```toml title="bunfig.toml" icon="settings"
[install]
# Only install package versions published at least 3 days ago
minimumReleaseAge = 259200
```

See [Minimum release age](https://aphrody.app/docs/pm/cli/install#minimum-release-age).

### `install.minimumReleaseAgeExcludes`

An array of package names that are exempt from the `minimumReleaseAge` check. Default `[]`.

```toml title="bunfig.toml" icon="settings"
[install]
minimumReleaseAge = 259200
# These packages will bypass the 3-day minimum age requirement
minimumReleaseAgeExcludes = ["@types/bun", "typescript"]
```

## `bun run`

The `[run]` section configures the `bun run` command. These settings also apply to the `bun` command when running a file, script, or executable.

For `bun run`, Bun only loads the local project's `bunfig.toml` automatically (it doesn't check for a global `.bunfig.toml`).

### `run.shell` - use the system shell or Bun's shell

The shell used to run `package.json` scripts with `bun run` or `bun`. Defaults to `"bun"` on Windows and `"system"` on other platforms.

To always use the system shell instead of Bun's shell (the default everywhere except Windows):

```toml title="bunfig.toml" icon="settings"
[run]
# default outside of Windows
shell = "system"
```

To always use Bun's shell instead of the system shell:

```toml title="bunfig.toml" icon="settings"
[run]
# default on Windows
shell = "bun"
```

### `run.bun` - auto alias `node` to `bun`

When `true`, Bun prepends `$PATH` with a `node` symlink that points to the `bun` binary for all scripts or executables invoked by `bun run` or `bun`.

A script that runs `node` runs `bun` instead, with no changes to the script. This works recursively, so a script that runs another script that runs `node` also runs `bun`. The alias also applies to shebangs that point to `node`.

By default, this is enabled if `node` is not already in your `$PATH`.

```toml title="bunfig.toml" icon="settings"
[run]
# equivalent to `bun --bun` for all `bun run` commands
bun = true
```

You can test this by running:

```sh
bun --bun which node # /path/to/bun
bun which node # /path/to/node
```

This option is equivalent to prefixing all `bun run` commands with `--bun`:

```sh
bun --bun run dev
bun --bun dev
bun run --bun dev
```

Set to `false` to disable the `node` symlink.

### `run.silent` - suppress reporting the command being run

When `true`, `bun run` and `bun` don't print the command being run.

```toml title="bunfig.toml" icon="settings"
[run]
silent = true
```

Without this option, Bun prints the command being run to the console:

```sh terminal icon="terminal"
bun run dev
echo "Running \"dev\"..."
```

```txt
Running "dev"...
```

With this option, Bun does not print the command being run:

```sh
bun run dev
```

```txt
Running "dev"...
```

This is equivalent to passing `--silent` to all `bun run` commands:

```sh
bun --silent run dev
bun --silent dev
bun run --silent dev
```

### `run.elide-lines` - truncate filtered output

Truncate each script's output to its last N lines when using `--filter` in a terminal. Default `0` (show all lines). Equivalent to the `--elide-lines` flag.

```toml title="bunfig.toml" icon="settings"
[run]
elide-lines = 10
```

### `run.noOrphans` - don't leave orphan processes behind

When `true`, Bun watches the process that spawned it and exits as soon as that parent goes away, even if the parent was force-killed and never got a chance to forward a signal. On its own exit, Bun also terminates every descendant process so nothing it spawned outlives it. Useful when Bun is launched by a supervisor (Electron, a CI runner, a thin shim) that may be force-killed.

On Linux, Bun uses `prctl(PR_SET_PDEATHSIG)` and a `/proc` descendant walk. On macOS, it uses `EVFILT_PROC`/`NOTE_EXIT` on the event loop's kqueue and a libproc descendant walk. On Windows, it uses a thread-pool wait on the parent's process handle and a kill-on-close Job Object.

Equivalent to the `--no-orphans` CLI flag or the `BUN_FEATURE_FLAG_NO_ORPHANS=1` environment variable.

```toml title="bunfig.toml" icon="settings"
[run]
noOrphans = true
```
