Bitwarden CLI
Goal
Use bw to access or mutate Bitwarden vault data safely from the terminal without leaking master passwords, API credentials, session keys, or vault contents.
Workflow
- Verify the CLI is installed and note the version in play.
bw --version
- If
bw is missing, use Bitwarden's official CLI install docs.
- Use
bw update only when the user explicitly wants to check for a newer CLI build.
- Configure the correct server before authenticating.
bw config server
bw config server bitwarden.com
bw config server https://bw.company.com
bw status
- Use the correct cloud or self-hosted server before
bw login.
- Confirm
serverUrl with bw status.
- Check current auth state before choosing the next step.
bw status
status is one of unauthenticated, locked, or unlocked.
unauthenticated means the user must log in.
locked means the user is already logged in and only needs bw unlock.
unlocked means a valid session key is already active for this shell or command.
- Log in with the method that matches the user's environment.
bw login
bw login --sso
BW_CLIENTID=... BW_CLIENTSECRET=... bw login --apikey
- Prefer interactive
bw login for normal user sessions.
- Use
bw login --sso when the account requires SSO.
- Use
bw login --apikey for automation, external applications, or cases where normal login is not suitable.
- If the user explicitly wants a one-shot session key from email/password login,
bw login --raw can return it directly.
- Avoid passing passwords directly on the command line unless the user explicitly requests it. Prefer the interactive prompt,
--passwordenv, or --passwordfile.
- Unlock the vault and capture the session key deliberately.
export BW_SESSION="$(bw unlock --raw)"
bw status
bw login authenticates the account. bw unlock decrypts the vault and returns a new session key.
- Any previous session key becomes invalid after a new
bw unlock.
- Prefer exporting
BW_SESSION for a single shell session or pass --session per command when you want tighter scope.
- Never echo
BW_SESSION into logs, tickets, or chat output.
- Sync vault state before item searches and other reads.
bw sync
bw sync --last
bw --session "$BW_SESSION" list items --search github
- Run
bw sync immediately before bw list ... --search ... when trying to find an item.
- Use
bw sync before other reads if the vault may be stale.
- Use
bw sync -f only when troubleshooting stale local state or a partial sync problem.
- Use
bw list and bw get for read paths.
bw --session "$BW_SESSION" get item <item-id>
bw --session "$BW_SESSION" get password github.com
bw --session "$BW_SESSION" get totp github.com
- Use
bw list after bw sync to discover candidate objects and IDs.
- Use
bw get item for the full JSON object.
- Use
bw get password, bw get username, bw get uri, bw get totp, or bw get notes when the user needs one field.
- Use
jq after bw get item when the user needs targeted extraction from object JSON.
- Create new objects from Bitwarden templates, then encode the full JSON payload.
bw --session "$BW_SESSION" get template folder | jq '.name = "Infra"' | bw encode | bw --session "$BW_SESSION" create folder
item_template="$(bw --session "$BW_SESSION" get template item)"
login_template="$(bw --session "$BW_SESSION" get template item.login)"
jq -n \
--argjson item "$item_template" \
--argjson login "$login_template" \
'$item | .type = 1 | .name = "Github" | .login = $login | .login.username = "bot@example.com" | .login.password = "replace-me"' \
| bw encode \
| bw --session "$BW_SESSION" create item
- Start from
bw get template ... instead of hand-writing object JSON.
- Use
jq to fill the template with the required fields.
- If
jq is unavailable, write the full template JSON to a temporary file, edit it completely, then pass it to bw encode.
- Pipe the final JSON through
bw encode before bw create or bw edit.
- Do not store the encoded payload in tracked files unless the user explicitly wants that artifact.
- Edit existing objects by starting from the current object, not a partial patch.
bw --session "$BW_SESSION" get item <item-id> \
| jq '.notes = "rotated on 2026-03-06"' \
| bw encode \
| bw --session "$BW_SESSION" edit item <item-id>
bw edit replaces the stored object with the supplied full JSON payload.
- Begin from
bw get item <id> for edits so unchanged fields survive.
- If
jq is unavailable, edit the full current object in a temporary file instead of constructing a partial payload.
- Use templates for new objects and full current objects for edits.
- End the session explicitly.
bw lock
bw logout
- Use
bw lock when the user is done for now but wants to remain logged in.
- Use
bw logout when switching accounts, rotating auth posture, or removing local login state.
bw lock destroys active session keys, so commands using the old BW_SESSION will fail until the vault is unlocked again.
Guardrails
- Never print master passwords, API keys,
BW_SESSION, or decrypted secrets unless the user explicitly asks for raw output.
- Prefer prompt-based login or
--passwordenv over putting passwords directly in shell history.
- Prefer
--apikey for automation instead of personal interactive login flows.
- Treat
bw get password, bw get totp, and attachment retrieval as sensitive output and redact by default.
- Run
bw sync before any item search, and before other reads if multiple devices or teammates may have modified shared vault content.
- Start create flows from
bw get template and edit flows from bw get item; do not hand-build partial JSON for bw edit.
- If the user really wants app-runtime secret injection instead of vault CRUD, note that Bitwarden Secrets Manager is a better fit than the Password Manager CLI.
Troubleshooting
bw status returns unauthenticated:
- Run
bw login with the correct method, then bw unlock.
bw status returns locked:
- Run
bw unlock and export or pass the new session key.
- Commands fail after a fresh
bw unlock:
- Replace the old
BW_SESSION. Previous session keys become invalid on each unlock.
- The wrong server is configured:
- Check
bw config server and bw status, then re-run bw config server <value> before logging in again if needed.
- A search misses an item that should exist:
- Run
bw sync, then retry bw list items --search ... before assuming the item is absent.
- Reads look stale:
- Run
bw sync or bw sync -f, then retry the read.
bw edit drops fields unexpectedly:
- The payload was incomplete. Rebuild the edit from
bw get item <id> and apply the change with jq.
Output
- Show the exact commands used.
- State the observed Bitwarden state from
bw status.
- State whether
BW_SESSION was exported, passed with --session, or intentionally omitted.
- State whether the command only read data or also created, edited, locked, or logged out.
- Call out any written files or sensitive output that should be cleaned up or redacted.
1---2name: bitwarden-cli3description: Use Bitwarden Password Manager CLI (`bw`) to authenticate, unlock a vault, manage `BW_SESSION`, configure cloud or self-hosted server settings, sync vault state, list or get vault objects, create or edit items with `bw get template`, `jq`, and `bw encode`, or safely lock and log out of terminal sessions. Use when Codex needs to work with Bitwarden vault data from the terminal or troubleshoot Bitwarden CLI auth, session, and object mutation behavior.4---56# Bitwarden CLI78## Goal910Use `bw` to access or mutate Bitwarden vault data safely from the terminal without leaking master passwords, API credentials, session keys, or vault contents.1112## Workflow13141. Verify the CLI is installed and note the version in play.1516```bash17bw --version18```1920- If `bw` is missing, use Bitwarden's official CLI install docs.21- Use `bw update` only when the user explicitly wants to check for a newer CLI build.22232. Configure the correct server before authenticating.2425```bash26bw config server27bw config server bitwarden.com28bw config server https://bw.company.com29bw status30```3132- Use the correct cloud or self-hosted server before `bw login`.33- Confirm `serverUrl` with `bw status`.34353. Check current auth state before choosing the next step.3637```bash38bw status39```4041- `status` is one of `unauthenticated`, `locked`, or `unlocked`.42- `unauthenticated` means the user must log in.43- `locked` means the user is already logged in and only needs `bw unlock`.44- `unlocked` means a valid session key is already active for this shell or command.45464. Log in with the method that matches the user's environment.4748```bash49bw login50bw login --sso51BW_CLIENTID=... BW_CLIENTSECRET=... bw login --apikey52```5354- Prefer interactive `bw login` for normal user sessions.55- Use `bw login --sso` when the account requires SSO.56- Use `bw login --apikey` for automation, external applications, or cases where normal login is not suitable.57- If the user explicitly wants a one-shot session key from email/password login, `bw login --raw` can return it directly.58- Avoid passing passwords directly on the command line unless the user explicitly requests it. Prefer the interactive prompt, `--passwordenv`, or `--passwordfile`.59605. Unlock the vault and capture the session key deliberately.6162```bash63export BW_SESSION="$(bw unlock --raw)"64bw status65```6667- `bw login` authenticates the account. `bw unlock` decrypts the vault and returns a new session key.68- Any previous session key becomes invalid after a new `bw unlock`.69- Prefer exporting `BW_SESSION` for a single shell session or pass `--session` per command when you want tighter scope.70- Never echo `BW_SESSION` into logs, tickets, or chat output.71726. Sync vault state before item searches and other reads.7374```bash75bw sync76bw sync --last77bw --session "$BW_SESSION" list items --search github78```7980- Run `bw sync` immediately before `bw list ... --search ...` when trying to find an item.81- Use `bw sync` before other reads if the vault may be stale.82- Use `bw sync -f` only when troubleshooting stale local state or a partial sync problem.83847. Use `bw list` and `bw get` for read paths.8586```bash87bw --session "$BW_SESSION" get item <item-id>88bw --session "$BW_SESSION" get password github.com89bw --session "$BW_SESSION" get totp github.com90```9192- Use `bw list` after `bw sync` to discover candidate objects and IDs.93- Use `bw get item` for the full JSON object.94- Use `bw get password`, `bw get username`, `bw get uri`, `bw get totp`, or `bw get notes` when the user needs one field.95- Use `jq` after `bw get item` when the user needs targeted extraction from object JSON.96978. Create new objects from Bitwarden templates, then encode the full JSON payload.9899```bash100bw --session "$BW_SESSION" get template folder | jq '.name = "Infra"' | bw encode | bw --session "$BW_SESSION" create folder101102item_template="$(bw --session "$BW_SESSION" get template item)"103login_template="$(bw --session "$BW_SESSION" get template item.login)"104jq -n \105 --argjson item "$item_template" \106 --argjson login "$login_template" \107 '$item | .type = 1 | .name = "Github" | .login = $login | .login.username = "bot@example.com" | .login.password = "replace-me"' \108 | bw encode \109 | bw --session "$BW_SESSION" create item110```111112- Start from `bw get template ...` instead of hand-writing object JSON.113- Use `jq` to fill the template with the required fields.114- If `jq` is unavailable, write the full template JSON to a temporary file, edit it completely, then pass it to `bw encode`.115- Pipe the final JSON through `bw encode` before `bw create` or `bw edit`.116- Do not store the encoded payload in tracked files unless the user explicitly wants that artifact.1171189. Edit existing objects by starting from the current object, not a partial patch.119120```bash121bw --session "$BW_SESSION" get item <item-id> \122 | jq '.notes = "rotated on 2026-03-06"' \123 | bw encode \124 | bw --session "$BW_SESSION" edit item <item-id>125```126127- `bw edit` replaces the stored object with the supplied full JSON payload.128- Begin from `bw get item <id>` for edits so unchanged fields survive.129- If `jq` is unavailable, edit the full current object in a temporary file instead of constructing a partial payload.130- Use templates for new objects and full current objects for edits.13113210. End the session explicitly.133134```bash135bw lock136bw logout137```138139- Use `bw lock` when the user is done for now but wants to remain logged in.140- Use `bw logout` when switching accounts, rotating auth posture, or removing local login state.141- `bw lock` destroys active session keys, so commands using the old `BW_SESSION` will fail until the vault is unlocked again.142143## Guardrails144145- Never print master passwords, API keys, `BW_SESSION`, or decrypted secrets unless the user explicitly asks for raw output.146- Prefer prompt-based login or `--passwordenv` over putting passwords directly in shell history.147- Prefer `--apikey` for automation instead of personal interactive login flows.148- Treat `bw get password`, `bw get totp`, and attachment retrieval as sensitive output and redact by default.149- Run `bw sync` before any item search, and before other reads if multiple devices or teammates may have modified shared vault content.150- Start create flows from `bw get template` and edit flows from `bw get item`; do not hand-build partial JSON for `bw edit`.151- If the user really wants app-runtime secret injection instead of vault CRUD, note that Bitwarden Secrets Manager is a better fit than the Password Manager CLI.152153## Troubleshooting154155- `bw status` returns `unauthenticated`:156 - Run `bw login` with the correct method, then `bw unlock`.157- `bw status` returns `locked`:158 - Run `bw unlock` and export or pass the new session key.159- Commands fail after a fresh `bw unlock`:160 - Replace the old `BW_SESSION`. Previous session keys become invalid on each unlock.161- The wrong server is configured:162 - Check `bw config server` and `bw status`, then re-run `bw config server <value>` before logging in again if needed.163- A search misses an item that should exist:164 - Run `bw sync`, then retry `bw list items --search ...` before assuming the item is absent.165- Reads look stale:166 - Run `bw sync` or `bw sync -f`, then retry the read.167- `bw edit` drops fields unexpectedly:168 - The payload was incomplete. Rebuild the edit from `bw get item <id>` and apply the change with `jq`.169170## Output171172- Show the exact commands used.173- State the observed Bitwarden state from `bw status`.174- State whether `BW_SESSION` was exported, passed with `--session`, or intentionally omitted.175- State whether the command only read data or also created, edited, locked, or logged out.176- Call out any written files or sensitive output that should be cleaned up or redacted.