name: bitwarden-cli
description: 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.
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
bwis missing, use Bitwarden's official CLI install docs. - Use
bw updateonly 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
serverUrlwithbw status.
- Check current auth state before choosing the next step.
bw status
statusis one ofunauthenticated,locked, orunlocked.unauthenticatedmeans the user must log in.lockedmeans the user is already logged in and only needsbw unlock.unlockedmeans 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 loginfor normal user sessions. - Use
bw login --ssowhen the account requires SSO. - Use
bw login --apikeyfor 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 --rawcan 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 loginauthenticates the account.bw unlockdecrypts the vault and returns a new session key.- Any previous session key becomes invalid after a new
bw unlock. - Prefer exporting
BW_SESSIONfor a single shell session or pass--sessionper command when you want tighter scope. - Never echo
BW_SESSIONinto 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 syncimmediately beforebw list ... --search ...when trying to find an item. - Use
bw syncbefore other reads if the vault may be stale. - Use
bw sync -fonly when troubleshooting stale local state or a partial sync problem.
- Use
bw listandbw getfor 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 listafterbw syncto discover candidate objects and IDs. - Use
bw get itemfor the full JSON object. - Use
bw get password,bw get username,bw get uri,bw get totp, orbw get noteswhen the user needs one field. - Use
jqafterbw get itemwhen 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
jqto fill the template with the required fields. - If
jqis unavailable, write the full template JSON to a temporary file, edit it completely, then pass it tobw encode. - Pipe the final JSON through
bw encodebeforebw createorbw 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 editreplaces the stored object with the supplied full JSON payload.- Begin from
bw get item <id>for edits so unchanged fields survive. - If
jqis 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 lockwhen the user is done for now but wants to remain logged in. - Use
bw logoutwhen switching accounts, rotating auth posture, or removing local login state. bw lockdestroys active session keys, so commands using the oldBW_SESSIONwill 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
--passwordenvover putting passwords directly in shell history. - Prefer
--apikeyfor 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 syncbefore any item search, and before other reads if multiple devices or teammates may have modified shared vault content. - Start create flows from
bw get templateand edit flows frombw get item; do not hand-build partial JSON forbw 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 statusreturnsunauthenticated:- Run
bw loginwith the correct method, thenbw unlock.
- Run
bw statusreturnslocked:- Run
bw unlockand export or pass the new session key.
- Run
- Commands fail after a fresh
bw unlock:- Replace the old
BW_SESSION. Previous session keys become invalid on each unlock.
- Replace the old
- The wrong server is configured:
- Check
bw config serverandbw status, then re-runbw config server <value>before logging in again if needed.
- Check
- A search misses an item that should exist:
- Run
bw sync, then retrybw list items --search ...before assuming the item is absent.
- Run
- Reads look stale:
- Run
bw syncorbw sync -f, then retry the read.
- Run
bw editdrops fields unexpectedly:- The payload was incomplete. Rebuild the edit from
bw get item <id>and apply the change withjq.
- The payload was incomplete. Rebuild the edit from
Output
- Show the exact commands used.
- State the observed Bitwarden state from
bw status. - State whether
BW_SESSIONwas 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.