bw), Bitwarden Secrets CLI (bws), and rbw to expose data as template functions.
Bitwarden CLI Setup
Install
Install the Bitwarden CLI:Log In
Log in using one of these methods:Unlock
If required, unlock your vault (API key and SSO logins always require an explicit unlock):BW_SESSION environment variable as instructed.
Quick Session Setup
Template Functions
bitwarden
Get structured data from an item:
bw get item example.com and returns parsed JSON.
bitwardenFields
Access custom fields:
bitwardenAttachment
Retrieve attachments by item ID:
bitwardenAttachmentByRef
Retrieve attachments by item reference:
Usage Examples
Login Credentials
Custom Fields
Attachments
Configuration
Automatic Unlock
Enable automatic unlocking ifBW_SESSION is not set:
~/.config/chezmoi/chezmoi.toml
Custom Command
Ifbw is not in your PATH:
~/.config/chezmoi/chezmoi.toml
Bitwarden Secrets CLI
The Secrets CLI (bws) is for Bitwarden Secrets Manager.
Setup
- Generate an access token for a service account
- Either set the environment variable or store in config:
bitwardenSecrets
Retrieve secrets:
Usage Examples
Unofficial Alternative: rbw
rbw is an unofficial Bitwarden CLI with better daemon support. See the rbw template functions reference for usage.Complete Examples
AWS Credentials
~/.aws/credentials.tmpl
NPM Configuration
~/.npmrc.tmpl
Multiple API Keys
~/.config/api-keys.sh.tmpl
Troubleshooting
Session Not Set
If you get “Session key is invalid”:Vault Locked
Command Not Found
Ensure Bitwarden CLI is installed:Item Not Found
Verify the item exists:Testing Templates
Test your template functions:Enable Auto-Unlock
To avoid manually unlocking:~/.config/chezmoi/chezmoi.toml
Best Practices
- Use auto-unlock: Set
bitwarden.unlock = "auto"for convenience - Organize items: Use clear naming conventions for items
- Use custom fields: Store structured data in custom fields
- Session management: Set
BW_SESSIONin your shell profile - Test incrementally: Test templates before adding more complexity
- Use Secrets Manager: For production/CI/CD, use Bitwarden Secrets Manager