# Add an optional dependency (/guides/install/add-optional)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 98 · updated: 2026-07-28 -->
Related: [Add a dependency](/guides/install/add.md), [Add a development dependency](/guides/install/add-dev.md), [Add a peer dependency](/guides/install/add-peer.md), [Add a Git dependency](/guides/install/add-git.md), [Add a tarball dependency](/guides/install/add-tarball.md), [Install a package under a different name](/guides/install/npm-alias.md)

To add an npm package as an optional dependency, use the `--optional` flag.

```sh icon="terminal" title="terminal" terminal
bun add zod --optional
```

***

This adds the package to `optionalDependencies` in `package.json`.

```json icon="file-json" title="package.json"
{
  "optionalDependencies": {
    "zod": "^3.0.0" // [!code ++]
  }
}
```

***

See [`bun install`](/pm/cli/install).
