﻿# Bitwarden Custody

> Keep your private keys in Bitwarden

[Custody](/docs/custody/)

## Install

Add Bitwarden to your Dotenvx installation.

Requires Dotenvx 3.0.

```console
$ dotenvx install --add bitwarden
```

Install the [Bitwarden CLI](https://bitwarden.com/help/cli/) (`bw`).

## Login

Log in to your Bitwarden account.

```console
$ bw login
```

Sign in on each machine that needs access.

## Encrypt

From the project directory containing your .env file, encrypt and choose **more**, then **Bitwarden** when prompted.

```console
$ dotenvx encrypt
```

Dotenvx prompts to unlock your vault if needed, encrypts your .env file, and stores the private key in Bitwarden. Commit the encrypted .env file with your code.

For .env.production, add `-f .env.production`.

Already using .env.keys? Follow the [Bitwarden migration guide](/docs/cli/bitwarden-up/) to move your existing private key instead.

## Run

When you run your app, Dotenvx reads the private key through `bw` and loads your decrypted environment variables.

```console
$ dotenvx run -- node index.js
```

For noninteractive use, provide an unlocked `BW_SESSION`. Replace node index.js with your app’s start command.

That’s it! Your app now loads encrypted secrets with the private key stored in Bitwarden.

---

## Bitwarden Commands

- [bitwarden up](/docs/cli/bitwarden-up/)
- [bitwarden down](/docs/cli/bitwarden-down/)
- [bitwarden push](/docs/cli/bitwarden-push/)
- [bitwarden pull](/docs/cli/bitwarden-pull/)
- [bitwarden list](/docs/cli/bitwarden/list/)
- [bitwarden show](/docs/cli/bitwarden/show/)
