Skip to content

CLI Reference

bz provides commands for managing Bazel module dependencies, analyzing your dependency graph, scanning for security issues, and preparing for offline/air-gapped environments.

Global Flags

These flags are available for all commands:

FlagDescription
-q, --quietReduce output, only show errors and essential info
--no-colorDisable colored output (auto-detected when not a TTY)
--offlineDisable all network access, use cache only
--prefer-offlinePrefer cached data, fallback to network if needed
--registry <url>Override the default registry URL
-h, --helpShow help for any command
-v, --versionShow version information (on root command)
Terminal window
bz mod list --quiet # minimal output
bz mod info rules_go --no-color # no ANSI colors
bz mod list --offline # cache only
bz mod outdated --prefer-offline # cache first
bz mod search --registry=https://my.registry rules_go

Command Categories

Module Management

init, mod add, mod rm, mod list, mod info, mod update, mod outdated, mod search, mod sync

Dependency Analysis

mod graph, mod stats, mod why

Security & Compliance

audit, mod licenses, sbom

Cache & Offline

cache download, cache stats, cache verify, cache clear

Utilities

doctor, registry ping, completion, version


Module Initialization

bz init

Initialize a new Bazel module by creating a MODULE.bazel file.

Terminal window
bz init # use directory name as module name
bz init --name=my_module # set module name
bz init --name=foo --version=1.0.0
bz init --force # overwrite existing MODULE.bazel
FlagDescription
--nameModule name (defaults to directory name)
--versionInitial module version (default: 0.0.0)
--forceOverwrite existing MODULE.bazel

Module Management

bz mod add

Add one or more dependencies to MODULE.bazel.

Terminal window
bz mod add rules_go@0.50.1
bz mod add rules_go@0.50.1 rules_python@0.35.0
bz mod add --dev gazelle@0.38.0
FlagDescription
--devAdd as a dev dependency

bz mod rm

Remove dependencies from MODULE.bazel.

Terminal window
bz mod rm rules_go
bz mod rm rules_go rules_python
bz mod rm --dry-run rules_go
FlagDescription
--dry-runShow what would be removed without making changes

bz mod list

List dependencies in MODULE.bazel.

Terminal window
bz mod list
bz mod list --all # include extensions, overrides, toolchains
bz mod list --json
FlagDescription
-a, --allShow all contents (extensions, overrides, etc.)
--jsonOutput as JSON

JSON output format:

{
"dependencies": [
{"name": "rules_go", "version": "0.50.1", "dev_dependency": false},
{"name": "gazelle", "version": "0.38.0", "dev_dependency": true}
]
}

bz mod info

Show information about a module from the registry.

Terminal window
bz mod info rules_go # show metadata and all versions
bz mod info rules_go@0.50.1 # show specific version details
bz mod info rules_go --json
FlagDescription
--jsonOutput as JSON

bz mod update

Update dependencies to latest stable versions.

Terminal window
bz mod update # update all dependencies
bz mod update rules_go # update specific module
bz mod update rules_go gazelle # update multiple modules
bz mod update --dry-run # preview changes
FlagDescription
--dry-runShow what would be updated without making changes

bz mod outdated

Check all dependencies for newer versions.

Terminal window
bz mod outdated
bz mod outdated --json
FlagDescription
--jsonOutput as JSON

Example output:

Module Current Latest
------ ------- ------
rules_go 0.49.0 0.50.1
gazelle 0.37.0 0.38.0

Search for modules in the registry.

Terminal window
bz mod search rules_go
bz mod search python
bz mod search protobuf -v # show version info
bz mod search grpc -n 5 # limit to 5 results
FlagDescription
-v, --verboseShow version info for each result
-n, --limitMaximum number of results (default: 20)

bz mod sync

Sync modules from a source registry to a destination based on a workflow defined in bz.star configuration.

Terminal window
bz mod sync mirror-essential # run a workflow
bz mod sync mirror-essential --dry-run # preview what would be synced
bz mod sync --list # list available workflows
FlagDescription
-c, --configPath to config file (default: bz.star)
--dry-runShow what would be synced without making changes
-l, --listList available workflows
--modulesOverride modules to sync (comma-separated)
-v, --verbosePrint detailed progress

See Configuration for details on writing Starlark sync workflows.


Dependency Analysis

bz mod graph

Display the dependency graph of your Bazel module.

Terminal window
bz mod graph # ASCII tree output
bz mod graph --format=dot # Graphviz DOT format
bz mod graph --format=mermaid # Mermaid diagram
bz mod graph --format=json # JSON structure
bz mod graph --json # shortcut for --format=json
bz mod graph --depth=2 # limit depth
FlagDescription
--formatOutput format: ascii (default), dot, json, mermaid
--jsonShortcut for --format=json
--depthMaximum depth to traverse (0 = unlimited)

Example ASCII output:

my_project
├── rules_go@0.50.1
│ ├── bazel_skylib@1.5.0
│ └── platforms@0.0.8
└── rules_python@0.35.0
└── bazel_skylib@1.5.0

Generate visualization:

Terminal window
bz mod graph --format=dot | dot -Tpng -o deps.png

bz mod stats

Display statistics about module dependencies.

Terminal window
bz mod stats
bz mod stats --json
FlagDescription
--jsonOutput as JSON

Example output:

Dependency Statistics:
Direct dependencies: 5
Transitive dependencies: 12
Total modules: 17
Max depth: 4
Dev dependencies: 2

bz mod why

Show the dependency path(s) that bring a module into your project.

Terminal window
bz mod why protobuf # why is protobuf included?
bz mod why protobuf --all # show all paths, not just shortest
bz mod why protobuf --json
FlagDescription
--allShow all paths (default: shortest paths only)
--jsonOutput as JSON

Example output:

protobuf is a direct dependency
protobuf is required by:
my_project -> rules_go@0.50.1 -> protobuf@25.3
my_project -> protobuf@25.3

Security & Compliance

bz audit

Scan dependencies for security vulnerabilities using the OSV database.

Terminal window
bz audit # scan all dependencies
bz audit --json # output as JSON
bz audit --severity=high # only high/critical vulnerabilities
bz audit --fix # show suggested updates
bz audit --ecosystem=Go # specify ecosystem manually
FlagDescription
--jsonOutput as JSON
--severityMinimum severity to report: critical, high, medium, low
--fixShow suggested updates to fix vulnerabilities
--ecosystemOSV ecosystem to query (e.g., Go, PyPI, crates.io, npm, Maven)

Example output:

Module Version ID Severity Summary
------ ------- -- -------- -------
protobuf 25.3 GHSA-xxxx-xxxx HIGH Buffer overflow in...
Suggested fixes:
bz mod update protobuf --version=25.4

The command returns a non-zero exit code if vulnerabilities are found.

bz mod licenses

Display license information for all dependencies.

Terminal window
bz mod licenses # list all licenses
bz mod licenses --json # output as JSON
bz mod licenses --summary # show license counts only
bz mod licenses --check --deny=GPL-3.0 # check for denied licenses
bz mod licenses --check --allow=MIT,Apache-2.0
FlagDescription
--jsonOutput as JSON
--summaryShow license summary only
--checkCheck licenses against policy (requires --allow or --deny)
--allowComma-separated list of allowed licenses
--denyComma-separated list of denied licenses

Example output:

Module Version License
------ ------- -------
bazel_skylib 1.5.0 Apache-2.0
rules_go 0.50.1 Apache-2.0
rules_python 0.35.0 Apache-2.0
Summary: 3 Apache-2.0

Policy checking:

Terminal window
# Fail if any GPL licenses are found
bz mod licenses --check --deny=GPL-2.0,GPL-3.0,LGPL-3.0
# Only allow specific licenses
bz mod licenses --check --allow=MIT,Apache-2.0,BSD-3-Clause

bz sbom

Generate a Software Bill of Materials (SBOM) for your Bazel module.

Terminal window
bz sbom # SPDX 2.3 JSON to stdout
bz sbom --format=cyclonedx # CycloneDX 1.4 JSON
bz sbom --output=sbom.json # write to file
bz sbom --include-transitive=false
FlagDescription
--formatOutput format: spdx (default), cyclonedx
--outputOutput file path (default: stdout)
--include-transitiveInclude transitive dependencies (default: true)
--registryRegistry URL

Supported formats:

  • SPDX 2.3 - ISO/IEC 5962:2021 standard
  • CycloneDX 1.4 - OWASP standard

Cache Management

For air-gapped environments, bz provides cache management commands.

bz cache download

Download modules and their transitive dependencies to the local cache.

Terminal window
bz cache download # cache deps from MODULE.bazel
bz cache download rules_go gazelle # cache specific modules
bz cache download rules_go@0.50.1 # cache specific version
bz cache download --all # cache ALL modules (large!)
FlagDescription
--allDownload ALL modules from registry (warning: very large)
--jsonOutput as JSON
--registryRegistry URL to download from
--cache-dirCache directory (default: ~/.cache/bz)

bz cache stats

Show statistics about the local module cache.

Terminal window
bz cache stats
bz cache stats --json
bz cache stats --cache-dir=/path/to/cache
FlagDescription
--jsonOutput as JSON
--cache-dirCache directory (default: ~/.cache/bz)

Example output:

Cache directory: /home/user/.cache/bz
Total modules: 15
Total versions: 42
Total size: 12.5 MB
Last updated: 2024-01-15 10:30:00

bz cache verify

Verify that the local cache contains all dependencies required for offline use.

Terminal window
bz cache verify
bz cache verify --json
bz cache verify --cache-dir=/path/to/cache
FlagDescription
--jsonOutput as JSON
--cache-dirCache directory (default: ~/.cache/bz)

Example output:

Verifying cache for MODULE.bazel dependencies...
✓ rules_go@0.50.1
✓ rules_python@0.35.0
✗ gazelle@0.38.0 (missing)
Cache is INCOMPLETE. Run 'bz cache download' to fix.

Returns non-zero exit code if cache is incomplete.

bz cache clear

Clear the local module cache.

Terminal window
bz cache clear # clear all (with confirmation)
bz cache clear --force # skip confirmation
bz cache clear rules_go # clear specific module
bz cache clear --json
FlagDescription
-f, --forceSkip confirmation prompt
--jsonOutput as JSON
--cache-dirCache directory (default: ~/.cache/bz)

Utilities

bz doctor

Check Bazel/bzlmod setup and diagnose common issues.

Terminal window
bz doctor
bz doctor --json
FlagDescription
--jsonOutput as JSON

Checks performed:

  • Bazel installation and version
  • MODULE.bazel file existence
  • .bazelversion file existence
  • Bzlmod enabled status (Bazel 7+ has it on by default)
  • Registry connectivity

Example output:

Checking Bazel setup...
✓ Bazel installed (7.0.0)
✓ MODULE.bazel found
✓ .bazelversion found (7.0.0)
✓ Bzlmod enabled (default in Bazel 7+)
✓ Registry reachable (bcr.bazel.build)
All checks passed!

bz registry ping

Test registry connectivity.

Terminal window
bz registry ping # check default BCR
bz registry ping https://my.registry # check specific registry
bz registry ping --json
FlagDescription
--jsonOutput as JSON

bz completion

Generate shell completion scripts.

Terminal window
# Linux
bz completion bash > /etc/bash_completion.d/bz
# macOS (Homebrew)
bz completion bash > $(brew --prefix)/etc/bash_completion.d/bz

bz version

Print version information.

Terminal window
bz version
bz version --json
FlagDescription
--jsonOutput as JSON

JSON output:

{
"version": "0.5.0",
"commit": "abc1234",
"date": "2024-01-15T10:30:00Z"
}

Exit Codes

CodeDescription
0Success
1General error (command failed, invalid arguments, etc.)

Commands that perform checks (audit, cache verify, mod licenses --check) return non-zero exit codes when issues are found, making them suitable for CI/CD pipelines.


Environment Variables

VariableDescription
BZ_OFFLINEEnable offline mode (1, true, yes)
BZ_PREFER_OFFLINEEnable prefer-offline mode
BZ_REGISTRYDefault registry URL
BZ_CACHE_DIRCache directory path
BZ_DISABLE_COMMANDSDisable specific commands (comma-separated)

See Configuration for full configuration options.