CLI Reference
Commands
Section titled “Commands”bwenv init
Section titled “bwenv init”Initialize secrets for the current project with manual folder selection.
bwenv init [OPTIONS]Behavior:
- Prompts for Bitwarden folder name
- Unlocks Bitwarden vault (if needed)
- Loads all custom fields from items in the specified folder
- Creates
.envrcfile with environment variables - Instructions for activating with
direnv allow
Example:
$ bwenv initEnter Bitwarden folder name: Production API KeysUnlocking Bitwarden vault...Loading secrets from folder: Production API KeysFound 5 items with 12 environment variablesCreated .envrc with environment variablesRun 'direnv allow' to activate environment variablesbwenv interactive
Section titled “bwenv interactive”Select Bitwarden folder interactively from a numbered list.
bwenv interactive [OPTIONS]Behavior:
- Lists all Bitwarden folders with numbers
- Prompts for folder selection by number
- Loads secrets and creates
.envrcfile - Same result as
initbut with folder selection UI
Example:
$ bwenv interactiveAvailable Bitwarden folders:1) Development Secrets2) Staging Environment3) Production API Keys4) Shared ToolsEnter folder number (1-4): 3Loading secrets from folder: Production API Keys...bwenv test
Section titled “bwenv test”Test installation and verify all dependencies.
bwenv test [OPTIONS]Checks:
- Bitwarden CLI installation and login status
- direnv installation and shell integration
- jq availability
- bwenv helper script installation
- File permissions and PATH configuration
Example:
$ bwenv test✓ Bitwarden CLI: Found (version 2024.1.0)✓ Bitwarden Login: Authenticated✓ direnv: Found (version 2.32.2)✓ direnv Hook: Configured in shell✓ jq: Found (version 1.6)✓ Helper Script: Installed at ~/.config/direnv/lib/bitwarden_folders.sh✓ PATH: ~/.local/bin is in PATHAll checks passed!bwenv remove
Section titled “bwenv remove”Remove .envrc file from the current directory.
bwenv remove [OPTIONS]Behavior:
- Deletes
.envrcfile if it exists - Creates backup as
.envrc.bakbefore deletion - Confirms removal with user
Example:
$ bwenv removeRemoving .envrc from current directory...Backup created: .envrc.bak.envrc removed successfullybwenv --help
Section titled “bwenv --help”Show help information and usage examples.
bwenv --helpbwenv -hbwenv --version
Section titled “bwenv --version”Display version information.
bwenv --versionbwenv -vGlobal Options
Section titled “Global Options”--debug[=LEVEL], -d
Section titled “--debug[=LEVEL], -d”Enable debug output with optional level specification.
--debugor--debug=2: Full debug (show steps and secret values)--debug=1: Show steps only, hide secret values- No flag: Default behavior (steps only, hide secrets)
Examples:
bwenv --debug init # Full debug (level 2)bwenv --debug=1 init # Steps only (level 1)bwenv -d interactive # Full debug (level 2)--quiet, -q
Section titled “--quiet, -q”Quiet mode - minimal output, errors only.
Examples:
bwenv --quiet init # Minimal outputbwenv -q interactive # Minimal outputExit Codes
Section titled “Exit Codes”0: Success1: General error2: Missing dependencies3: Bitwarden authentication failure4: direnv not configured5: File permission error
Environment Variables
Section titled “Environment Variables”Input Variables
Section titled “Input Variables”BWENV_DEBUG: Set debug level (0=silent, 1=steps, 2=full)BW_SESSION: Bitwarden session token (auto-managed)
Output Variables
Section titled “Output Variables”All custom fields from Bitwarden items become environment variables:
# Example Bitwarden item custom fields:DATABASE_URL=postgresql://...API_KEY=sk_test_...JWT_SECRET=your-jwt-secret
# Available after 'direnv allow':echo $DATABASE_URLecho $API_KEYecho $JWT_SECRETFile Operations
Section titled “File Operations”Created Files
Section titled “Created Files”.envrc: Main environment file for direnv.envrc.bak: Backup of previous.envrc(if exists)
File Format
Section titled “File Format”Generated .envrc files use this format:
#!/usr/bin/env bash# Generated by bwenv from Bitwarden folder: "Folder Name"# Generated on: 2024-01-15 10:30:00
# Load secrets from Bitwarden folderload_bitwarden_folder "Folder Name"Integration Examples
Section titled “Integration Examples”Shell Aliases
Section titled “Shell Aliases”Add to your shell config (.bashrc, .zshrc):
# Quick aliasesalias bwi='bwenv interactive'alias bwt='bwenv test'alias bwr='bwenv remove'
# Debug aliasesalias bwd='bwenv --debug'alias bwq='bwenv --quiet'Git Hooks
Section titled “Git Hooks”Pre-commit hook to ensure no secrets in git:
#!/bin/shif [ -f .envrc ]; then echo "Warning: .envrc file found" echo "Make sure .envrc is in .gitignore" grep -q "\.envrc" .gitignore || { echo "Adding .envrc to .gitignore" echo ".envrc" >> .gitignore }fiMakefile Integration
Section titled “Makefile Integration”Add to your project Makefile:
.PHONY: secrets secrets-dev secrets-prod
secrets: @bwenv interactive @direnv allow
secrets-dev: @echo "Development Secrets" | bwenv init @direnv allow
secrets-prod: @echo "Production Secrets" | bwenv init @direnv allowError Messages
Section titled “Error Messages”Common Errors
Section titled “Common Errors”“Bitwarden CLI not found”
Error: Bitwarden CLI not foundInstall with: npm install -g @bitwarden/cli“Not logged into Bitwarden”
Error: Not logged into BitwardenRun: bw login“direnv not configured”
Error: direnv hook not found in shell configAdd to ~/.bashrc: eval "$(direnv hook bash)"“Folder not found”
Error: Bitwarden folder 'Invalid Folder' not foundAvailable folders:- Development Secrets- Production API KeysDebug Output Example
Section titled “Debug Output Example”With --debug=2:
$ bwenv --debug=2 init[DEBUG] Checking Bitwarden status...[DEBUG] Bitwarden status: unlocked[DEBUG] Folder name: Production API Keys[DEBUG] Found folder ID: abc-123-def[DEBUG] Loading items from folder...[DEBUG] Found 3 items:[DEBUG] - API Configuration[DEBUG] - Database Settings[DEBUG] - Third-party Keys[DEBUG] Processing custom fields...[DEBUG] API_KEY=sk_test_1234567890abcdef[DEBUG] DATABASE_URL=postgresql://user:pass@host:5432/db[DEBUG] REDIS_URL=redis://localhost:6379[DEBUG] JWT_SECRET=your-secret-key-here[DEBUG] Writing .envrc file...[DEBUG] Created .envrc with 4 environment variables