@ksense-tech/bws-ctl
v0.2.1
Published
Bitwarden Secrets Manager helper CLI (doctor/pull/push/diff/project list/search)
Maintainers
Readme
bws-ctl
A lightweight, bash-based CLI for working with Bitwarden Secrets Manager.
bws-ctl helps teams:
- Pull secrets into local .env files
- Push syncs a local .env files up to Bitwarden Secrets which will create, update, or delete secrets
- Diff local envs vs Bitwarden secrets (git-style)
- Sync secrets from one Bitwarden project to another
- List and search Bitwarden Secrets Manager projects
- Validate local setup and access with a doctor command
Designed for developer computers, CI, and automation, with minimal setup and strong guardrails.
Requirements
Required
- Bash 4+
- macOS:
brew install bash - Linux: usually already available
- Windows: use WSL
- macOS:
- Bitwarden Secrets Manager CLI (bws)
- jq (JSON parsing)
BWS_ACCESS_TOKENset in your environment
Optional
- fzf – enables interactive fuzzy project search
- macOS:
brew install fzf - Ubuntu:
sudo apt install fzf - Windows (WSL):
sudo apt install fzf
- macOS:
Installation
Run without installing (recommended)
Always runs the latest published version:
npx @ksense-tech/bws-ctl --helpInstall globally (optional)
npm install -g @ksense-tech/bws-ctl
bws-ctl --help⚠️ Global installs depend on your Node version and PATH.
If you use nvm, npx is usually more reliable.
Authentication & Configuration
Bitwarden access token
Create a machine account in Bitwarden Secrets Manager and generate an access token.
Set it in your shell:
export BWS_ACCESS_TOKEN="your-token"This token's permissions determine which projects you can access.
Project ID configuration (required for pull/push/diff)
bws-ctl resolves the project ID in this order:
--project-id <id>flagBWS_PROJECT_IDenvironment variableBWS_PROJECT_IDfound in a local env file:.env.env.local.env.development.local
Recommended (per project)
Add to your project's
.env(or.env.local):
BWS_PROJECT_ID="your-secrets-project-id"Commands
doctor
Validate local setup, dependencies, and access.
bws-ctl doctorWhat it checks:
- Bash version
- bws availability
- jq availability
- fzf availability (optional)
BWS_ACCESS_TOKEN- Project ID resolution
- Optional live Bitwarden access checks
Skip network calls:
bws-ctl doctor --skip-networkpull
Export secrets from Bitwarden into a local env file.
bws-ctl pullOptions:
bws-ctl pull --out .env.local
bws-ctl pull --project-id <id>Default output file:
.env.local
The generated file includes an auto-generated header and should be added to .gitignore.
diff
Show differences between your local env file and Bitwarden secrets.
bws-ctl diffOutput is git-style, with values shown:
-DATABASE_URL=postgres://old
+DATABASE_URL=postgres://new
+PRINT_MODE=debugOptions:
bws-ctl diff --project-id <id>
bws-ctl diff --prune--prune also shows secrets that exist in Bitwarden but not in your env file.
push
Sync a local env file into Bitwarden.
bws-ctl pushBehavior:
- Creates missing secrets
- Updates secrets only when values differ
- Does not delete secrets unless
--pruneis used
Options:
bws-ctl push --dry-run
bws-ctl push --prune
bws-ctl push --project-id <id>Always dry-run first
bws-ctl push --dry-runsync
Sync secrets from one Bitwarden project to another.
bws-ctl syncBehavior:
- Creates missing secrets
- Updates secrets only when values differ
- Does not delete secrets unless
--pruneis used
Options:
bws-ctl sync --source-project-id <id>
bws-ctl sync --target-project-id <id>
bws-ctl sync --dry-run
bws-ctl sync --pruneAliases:
--src <id> same as --source-project-id
--dst <id> same as --target-project-idAlways dry-run first
bws-ctl sync --src a123 --dst b456 --prune --dry-runproject list
List all Bitwarden Secrets Manager projects (name + ID).
bws-ctl project listproject search
Search projects by name.
bws-ctl project search testInteractive fuzzy search (if fzf is installed):
bws-ctl project search --fzfIf no search term is provided and fzf is available, it will automatically open the fuzzy picker.
Typical Workflows
Local development
# once per repo
echo 'BWS_PROJECT_ID="abc123"' >> .env
bws-ctl doctor
bws-ctl pull
bws-ctl diffUpdating dev secrets
bws-ctl diff
bws-ctl push --dry-run
bws-ctl pushCI / automation
export BWS_ACCESS_TOKEN="ci-token"
export BWS_PROJECT_ID="project-id"
bws-ctl pull --out .envSecurity Model
- Access is controlled entirely by the Bitwarden machine account token
- Knowing a project ID does not grant access
- Developers should typically have:
- Read or read/write access to dev projects
- No access to staging or prod projects
- Production tokens should never live on developer laptops
Notes & Best Practices
- Do not commit generated env files
- Prefer
npx @ksense-tech/bws-ctlover global installs - Use
--dry-runbeforepush - Keep
.envfiles local and ignored - Use
project list/project searchto discover project IDs
Troubleshooting
command not found: bws-ctl- Use
npx @ksense-tech/bws-ctl - Or ensure your npm global bin directory is in PATH
- If using nvm, ensure the same Node version is active
- Use
- Missing project id
- Set
BWS_PROJECT_ID - Or add it to
.env - Or pass
--project-id
- Set
permission deniedfrom Bitwarden- Check the machine account's project access
- Run
bws-ctl doctor
