Skip to content

s1ks1/bwenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bwenv Logo

πŸ” bwenv

Sync secrets from your password manager into your shell environment β€” beautifully.

Install Release License Build Go Report Card

πŸš€ Overview

bwenv is a cross-platform CLI tool that bridges your password manager and your shell environment using direnv. It lets you load secrets from Bitwarden or 1Password directly into your project's environment variables β€” no manual copy-pasting, no secrets in .env files committed to git.

Built with Go, Bubble Tea, and Lipgloss for a fast, beautiful, and truly cross-platform experience.

Why bwenv?

Managing secrets across projects is painful. .env files get committed by accident, tokens expire and break your workflow, and switching between projects means manual copy-pasting. bwenv solves this by fetching secrets directly from your vault β€” live, per-directory, automatically.

The original bwenv was built around Makefile, Bash, and PowerShell scripts. That version worked, but keeping the behavior consistent across macOS, Linux, and Windows became harder than it needed to be. The project was rewritten in Go for better cross-platform support, simpler installation, and a single static binary for every platform with zero runtime dependencies beyond your password manager CLI and direnv.

Why bwenv for AI Workflows?

AI coding assistants (Claude Code, Cursor, Copilot, etc.) read your project files and environment to understand context. This creates a unique challenge for secrets:

  • Leak prevention β€” .env files in your project are a risk; AI tools may read or suggest committing them. bwenv keeps secrets in your vault, never on disk.
  • AI sees zero secrets β€” The .envrc file contains only a reference to bwenv export; no keys, no tokens, no passwords.
  • Works with AI in the shell β€” Secrets loaded via direnv are available as environment variables that AI tools inherit from the terminal.
  • No more "oops, I committed the .env" β€” When AI suggests git add ., there's nothing sensitive to accidentally include.
  • Share context safely β€” Share your .envrc in repos, docs, or with AI without exposing any real credentials.

✨ Features

  • 🎯 Pinpoint selection β€” Load only specific items from a folder via TUI multi-select or --items CLI flag
  • πŸ”‘ Multi-provider support β€” Works with Bitwarden (bw CLI) and 1Password (op CLI)
  • 🎨 Beautiful TUI β€” Interactive provider and folder selection with arrow keys, search, and filtering
  • πŸ“ Automatic .envrc generation β€” Creates direnv-compatible files that auto-load your secrets
  • πŸ–₯️ True cross-platform β€” Single binary for Linux, macOS, and Windows (amd64 + arm64)
  • πŸ” Smart diagnostics β€” bwenv status checks every dependency, session, and config
  • βš™οΈ Configurable UI β€” Toggle emoji, direnv output, export summaries via bwenv config
  • πŸ”‘ Quick re-auth β€” Session expired? bwenv login re-authenticates and updates your .envrc in one step
  • πŸ”’ Secure logout β€” Lock vaults and terminate sessions with bwenv logout
  • ⚑ Zero runtime dependencies β€” Just the Go binary + your password manager CLI + direnv
  • πŸ“¦ Easy installation β€” Homebrew, Scoop, APT/DNF, go install, or direct download

πŸ“¦ Prerequisites

Tool Required? Description
direnv Yes Automatically loads/unloads environment variables from .envrc files
Bitwarden CLI One of these Access your Bitwarden vault from the terminal (bw)
1Password CLI One of these Access your 1Password vaults from the terminal (op)

You need at least one password manager CLI installed. bwenv will detect what's available and let you choose.

Important: You must be logged into your password manager's CLI before running bwenv. Depending on your provider:

  • Bitwarden: Run bw login first (one-time setup), then bwenv init will prompt for your master password to unlock.
  • 1Password: Run op signin first, or rely on desktop app biometrics (op v2).

If you haven't logged into the CLI yet, bwenv will fail at the authentication step. See INSTALL.md for detailed setup instructions.


πŸ› οΈ Installation

Homebrew (macOS)

brew tap s1ks1/bwenv
brew install --cask bwenv

Scoop (Windows)

scoop bucket add bwenv https://github.com/s1ks1/scoop-bwenv
scoop install bwenv

Linux (DEB β€” Debian / Ubuntu)

Download the .deb package from the latest release:

# Download (replace VERSION and ARCH as needed)
curl -LO https://github.com/s1ks1/bwenv/releases/latest/download/bwenv_VERSION_amd64.deb

# Install
sudo dpkg -i bwenv_*_amd64.deb

Linux (RPM β€” Fedora / RHEL / openSUSE)

# Download (replace VERSION and ARCH as needed)
curl -LO https://github.com/s1ks1/bwenv/releases/latest/download/bwenv_VERSION_amd64.rpm

# Install
sudo rpm -i bwenv_*_amd64.rpm

Go Install

go install github.com/s1ks1/bwenv@latest

Quick Install Script

macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/s1ks1/bwenv/main/install.sh | sh

Windows (PowerShell):

irm https://raw.githubusercontent.com/s1ks1/bwenv/main/install.ps1 | iex

From Source

git clone https://github.com/s1ks1/bwenv.git
cd bwenv
make build
make install

For local development, use make run ARGS="status" to build and run the CLI without installing it globally.

Direct Download

Download the latest binary for your platform from the Releases page, extract it, and place bwenv somewhere in your PATH.

Verify Installation

bwenv status

For detailed installation instructions on all platforms, including testing workflows for Bitwarden and 1Password, see INSTALL.md.


⚑ Usage

1. Interactive Setup

bwenv init

This launches a full interactive TUI flow:

  1. Select a provider β€” Choose between Bitwarden, 1Password (or whichever CLIs you have installed)
  2. Authenticate β€” Unlock your vault or sign in (master password, biometrics, etc.)
  3. Pick a folder β€” Browse, search, and select the folder/vault containing your secrets
  4. Pick specific items β€” Choose individual items to load, or load all items in the folder
  5. Generate .envrc β€” A direnv-compatible file is created in the current directory

Then just:

cd .    # Trigger direnv to load secrets

Your secrets are now loaded as environment variables every time you cd into this directory! πŸŽ‰

2. Non-Interactive Export

For CI/CD pipelines, scripts, or advanced usage, you can export secrets directly:

# Output "export KEY=VALUE" lines to stdout
bwenv export --provider bitwarden --folder "MySecrets"

# Export only specific items from a folder
bwenv export --provider bitwarden --folder "MySecrets" --items "item-id-1,item-id-2"

# Use with eval to set variables in the current shell
eval "$(bwenv export --provider bitwarden --folder "MySecrets")"

# Works with 1Password too
eval "$(bwenv export --provider 1password --folder "Production")"

3. Configure Preferences

bwenv config

Opens an interactive settings editor where you can toggle:

Setting Default Description
Show Emoji ON Display emoji icons in output (turn off for cleaner text-only output)
Show Direnv Output OFF Show/hide direnv's own loading/unloading messages
Show Export Summary ON Show the boxed summary when secrets are loaded via direnv
Auto Sync ON Automatically sync the vault before fetching secrets (Bitwarden)

Settings are persisted to ~/.config/bwenv/config.json.

4. Re-authenticate (Session Expired)

bwenv login

If your vault session has expired, bwenv login will:

  • Detect which provider is configured in your .envrc
  • Re-authenticate with that provider (unlock/sign in)
  • Update the session token in your .envrc
  • Auto-approve the updated .envrc via direnv

This is much faster than running bwenv init again β€” it skips provider and folder selection entirely.

Alias: bwenv auth works too.

5. Lock Vaults / Logout

bwenv logout

Terminates all active provider sessions for security:

  • Bitwarden β€” runs bw lock to lock the vault
  • 1Password β€” runs op signout to end the session
  • Shows any lingering session environment variables and how to clear them

Use this when you're done working with secrets or stepping away from your machine.

6. Status & Diagnostics

bwenv status

Shows a comprehensive overview of your current bwenv state:

  • Current directory and .envrc info (provider, folder)
  • direnv installation and hook status
  • Provider availability and active sessions
  • Relevant environment variables (masked for security)
  • Current config preferences

7. Remove Secrets

bwenv remove

Deletes the .envrc file from the current directory.

8. Version

bwenv version

🧩 How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  bwenv init  │────▸│ Provider CLI │────▸│   .envrc     β”‚
β”‚  (TUI flow)  β”‚     β”‚ (bw / op)    β”‚     β”‚  (generated) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                  β”‚
                                                  β–Ό
                                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                          β”‚   direnv     β”‚
                                          β”‚  (auto-load) β”‚
                                          β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                  β”‚
                                                  β–Ό
                                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                          β”‚ Environment  β”‚
                                          β”‚  Variables   β”‚
                                          β”‚  $API_KEY    β”‚
                                          β”‚  $DB_URL     β”‚
                                          β”‚  $SECRET     β”‚
                                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. bwenv init walks you through an interactive setup β€” pick your provider, folder, and optionally specific items
  2. It generates an .envrc file that contains a single eval call to bwenv export
  3. When direnv loads the .envrc, it runs bwenv export which fetches fresh secrets from your vault
  4. Each secret's custom fields (Bitwarden) or item fields (1Password) are exported as environment variables

No secrets are stored on disk (except session tokens which expire). The .envrc fetches secrets live from your vault each time direnv loads it.


πŸ“ Project Structure

bwenv/
β”œβ”€β”€ main.go                          # Entry point and CLI routing
β”œβ”€β”€ INSTALL.md                       # Detailed install & testing guide
β”œβ”€β”€ install.sh                       # macOS/Linux quick install script
β”œβ”€β”€ install.ps1                      # Windows quick install script
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ provider/
β”‚   β”‚   β”œβ”€β”€ provider.go              # Provider interface and registry
β”‚   β”‚   β”œβ”€β”€ bitwarden.go             # Bitwarden (bw CLI) implementation
β”‚   β”‚   └── onepassword.go           # 1Password (op CLI) implementation
β”‚   β”œβ”€β”€ ui/
β”‚   β”‚   β”œβ”€β”€ styles.go                # Lipgloss color palette and shared styles
β”‚   β”‚   β”œβ”€β”€ output.go                # Styled print helpers (success, error, etc.)
β”‚   β”‚   β”œβ”€β”€ provider_picker.go       # Bubble Tea model for provider selection
β”‚   β”‚   β”œβ”€β”€ folder_picker.go         # Bubble Tea model for folder selection
β”‚   β”‚   β”œβ”€β”€ init_flow.go             # Orchestrates the full init TUI flow
β”‚   β”‚   β”œβ”€β”€ login_flow.go            # Re-authentication flow for expired sessions
β”‚   β”‚   β”œβ”€β”€ config_flow.go           # Interactive config editor TUI
β”‚   β”‚   β”œβ”€β”€ logout_flow.go           # Vault locking and session termination
β”‚   β”‚   └── status_flow.go           # Status overview & diagnostics
β”‚   β”œβ”€β”€ envrc/
β”‚   β”‚   └── envrc.go                 # .envrc generation, export, allow/disallow
β”‚   └── config/
β”‚       └── config.go                # Persistent user preferences (~/.config/bwenv/)
β”œβ”€β”€ Makefile                         # Build, install, test, release targets
β”œβ”€β”€ .goreleaser.yml                  # GoReleaser config for cross-platform releases
β”œβ”€β”€ .github/workflows/               # GitHub Actions workflows
β”œβ”€β”€ packaging/
β”‚   β”œβ”€β”€ homebrew/bwenv.rb            # Homebrew formula template
β”‚   β”œβ”€β”€ windows/bwenv.cmd            # Windows command shim
β”‚   └── scoop/bwenv.json             # Scoop manifest template
β”œβ”€β”€ LICENSE
└── README.md

πŸ”§ Development

Build

make build        # Build for current platform β†’ dist/bwenv
make run          # Build and run
make run ARGS="status"  # Build and run with arguments

Test

make test         # Run all Go tests
make lint         # Run go vet + staticcheck
make fmt          # Format all Go source files
make tidy         # Clean up go.mod/go.sum

Git Workflow

main is the stable branch and release source. Work on feature branches, open a pull request, and merge the branch back into main when checks pass. This keeps the history easy to follow and makes a fresh clone straightforward:

git clone https://github.com/s1ks1/bwenv.git
cd bwenv
git switch main
make build

For local pulls, prefer merge-based updates:

git config pull.rebase false
git pull origin main

Release

# Local test build (no publish)
goreleaser release --snapshot --clean

# Full release (requires GITHUB_TOKEN)
goreleaser release --clean

# Or use the Makefile for a simple cross-compile
make release

Adding a New Provider

  1. Create a new file in internal/provider/ (e.g. doppler.go)
  2. Implement the Provider interface (including the Lock() method)
  3. Call Register(&YourProvider{}) in an init() function
  4. That's it β€” the provider will automatically appear in the TUI picker and CLI flags

🀝 Supported Providers

Provider CLI Tool Status Notes
Bitwarden bw βœ… Ready Reads custom fields from items in folders
1Password op βœ… Ready Reads fields from items in vaults

Want another provider? Open an issue or submit a PR! The provider interface is designed to be easy to extend.


πŸ“‹ Migration from v1 (Bash)

If you're upgrading from the original Bash-based bwenv:

  1. Uninstall the old version:

    # If installed via the old install.sh or make:
    rm -f ~/.local/bin/bwenv
    rm -f ~/.config/direnv/lib/bitwarden_folders.sh
    
    # If installed via Homebrew:
    brew uninstall --cask bwenv
  2. Install the new version:

    brew tap s1ks1/bwenv
    brew install --cask bwenv
  3. Re-initialize your projects:

    cd your-project
    bwenv init    # New interactive TUI flow
    direnv allow
  4. Configure preferences (optional):

    bwenv config  # Toggle emoji, direnv output, etc.

What changed?

v1 (Bash) v2 (Go)
Language Bash + batch scripts Go (single binary)
Providers Bitwarden only Bitwarden + 1Password (extensible)
Dependencies bw, jq, direnv bw or op, direnv (no jq needed!)
UI Basic terminal prompts Beautiful TUI with Bubble Tea + Lipgloss
Windows .bat file with PowerShell fallbacks Native .exe binary
Helper scripts bitwarden_folders.sh + bwenv bash script None β€” everything is in the single binary
Config None Persistent preferences via bwenv config
Session management Manual bwenv login to re-auth, bwenv logout to lock vaults
Status overview None bwenv status for quick state check

πŸ“ License

MIT License. See LICENSE for details.


🀝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.

The codebase is intentionally well-commented to make it easy for contributors who may not be deeply familiar with Go, Bubble Tea, or Lipgloss.


Made with ❀️ for developers who care about security and beautiful tools

About

πŸ” Sync secrets from password managers (Bitwarden, 1Password) into your shell via direnv β€” cross-platform CLI with beautiful TUI

Topics

Resources

License

Stars

Watchers

Forks

Contributors