Skip to main content
The Bitwarden CLI can be built from source for development or custom distribution. The build system supports both OSS (open-source) and commercial (Bit) builds.

Prerequisites

  • Node.js runtime (latest LTS version recommended)
  • npm package manager
  • pkg for creating native executables

Development Builds

OSS Build (Open Source)

Build the open-source version of the CLI:
The output is placed in build/bw.js.

Debug Mode

Run with Node.js inspector for debugging:
Attach a debugger to the running process on the default inspector port.

Commercial Build

Build the commercial version (requires Bitwarden license files):

Binary Distribution

Platform-Specific Packaging

The CLI uses pkg to create standalone native executables:
Output: dist/oss/windows/bw.exe or dist/bit/windows/bw.exe

Packaging Process

Each distribution command follows this workflow:
  1. Build: Compile TypeScript to JavaScript with webpack
  2. Clean: Remove previous distribution files
  3. Package: Create native executable with pkg
For example, npm run dist:oss:win executes:

Direct Packaging

To package an existing build without rebuilding:

Package Configuration

The package.json defines the pkg configuration:

Pkg Targets

The build system targets these platforms:
  • win-x64: Windows x64
  • macos-x64: macOS Intel
  • macos-arm64: macOS Apple Silicon
  • linux-x64: Linux x64
  • linux-arm64: Linux ARM64
All bundled assets from ./build/**/* are included in the executable.

Build System

Webpack Configuration

Builds use webpack for bundling:
  • OSS: Default webpack configuration
  • Commercial: Custom configuration at ../../bitwarden_license/bit-cli/webpack.config.js

Production Mode

Production builds set NODE_ENV=production for optimizations:
Optimizations include:
  • Tree shaking
  • Minification
  • Dead code elimination

Testing

Run tests before building:

Publishing to NPM

Publish the OSS version to npm:
This command:
  1. Builds with production optimizations
  2. Publishes to npm with public access
Only authorized maintainers should publish to npm.

Directory Structure

Common Issues

Build Failures

TypeScript errors: Ensure you’re using a compatible Node.js version
Missing dependencies: Clean install

Packaging Failures

pkg not found: Install globally
Asset bundling issues: Verify the build output exists

Custom Builds

To create a custom build for specific requirements:
  1. Modify source: Make changes to TypeScript files in src/
  2. Build: Run npm run build:oss or npm run build:oss:prod
  3. Test: Run the built CLI with node build/bw.js
  4. Package: Create executables for your target platforms

Example: Custom Command

Add a custom command in src/program.ts:
Build and test:

Next Steps

Commands Reference

Learn about all available CLI commands

Contributing

Contribution guidelines and development setup