The buf CLI is the best tool for working with Protocol Buffers, providing linting, breaking change detection, code generation, formatting, and integration with the Buf Schema Registry for modern Protobuf development workflows
npx @tessl/cli install tessl/golang-bufbuild--buf@1.57.0Buf is a comprehensive CLI toolkit for Protocol Buffer development that modernizes the Protobuf ecosystem through advanced tooling and workflow automation. It provides essential features including API linting, breaking change detection, code generation, automatic formatting, and seamless integration with the Buf Schema Registry for centralized schema management.
brew install bufbuild/buf/bufcurl -sSL https://github.com/bufbuild/buf/releases/latest/download/buf-Linux-x86_64.tar.gz | tar -xvzf - -C /usr/local --strip-components 1docker run --rm -v "$(pwd):/workspace" --workdir /workspace bufbuild/bufgo install github.com/bufbuild/buf/cmd/buf@latestnpm install @bufbuild/buf# CLI binary execution
buf [command] [flags] [arguments]
# Docker usage
docker run --rm -v "$(pwd):/workspace" --workdir /workspace bufbuild/buf [command]
# NPM/Node.js usage
npx @bufbuild/buf [command]# Initialize a new buf module
buf config init
# Lint Protocol Buffer files
buf lint
# Check for breaking changes
buf breaking --against '.git#branch=main'
# Generate code from proto files
buf generate
# Format proto files
buf format --write
# Build proto files into an image
buf build -o image.bin
# Push module to registry
buf push
# Export proto files
buf export -o exported/Buf is built around several key components:
Essential Protocol Buffer development operations including compilation, validation, and code generation.
# Build proto files into various output formats
buf build [flags] [input]
# Lint proto files with configurable rules
buf lint [flags] [input]
# Check for breaking changes between proto versions
buf breaking [flags] [input] --against [against-input]
# Generate code using protoc plugins and templates
buf generate [flags] [input]
# Format proto files following industry standards
buf format [flags] [input]Complete Buf Schema Registry (BSR) integration for centralized schema management, module publishing, and dependency resolution.
# Push a module to the registry
buf push [flags] [input]
# Registry authentication
buf registry login [domain]
buf registry logout [domain]
# Module management
buf registry module create <name>
buf registry module info <module>
buf registry module delete <module>Tools for initializing, managing, and migrating buf configuration files and workspace settings.
# Initialize buf configuration
buf config init [flags]
# List available lint rules
buf config ls-lint-rules
# List available breaking change rules
buf config ls-breaking-rules
# Migrate configuration to latest version
buf config migrate [flags]Manage Protocol Buffer dependencies and workspace configurations.
# Show dependency graph
buf dep graph [flags] [input]
# Update dependencies to latest versions
buf dep update [flags] [input]
# Remove unused dependencies
buf dep prune [flags] [input]Additional utilities for working with Protocol Buffer files and modules.
# Export proto files to another location
buf export [flags] [input] [output]
# Convert messages between formats (JSON, binary, text)
buf convert [flags] --type [type] [input]
# Make RPC requests (gRPC curl functionality)
buf curl [flags] [input] [server]
# List proto files in a module
buf ls-files [flags] [input]
# Show statistics about proto files
buf stats [flags] [input]Available across most commands:
--config string Override config file path
--disable-symlinks Disable symlink resolution for security
--error-format string Error output format (text, json, msvs, junit, github-actions)
--path strings Include only specified paths
--exclude-path strings Exclude specific paths from processingBuf supports multiple input sources:
git_repo#branch=main)buf.build/owner/module[:ref])- for stdin input# buf.yaml - Main module configuration
version: v1
name: buf.build/acme/petapis
deps:
- buf.build/googleapis/googleapis
# buf.gen.yaml - Code generation template
version: v1
plugins:
- name: go
out: gen/go
opt: paths=source_relative
- name: go-grpc
out: gen/go
opt: paths=source_relative
# buf.work.yaml - Workspace configuration
version: v1
directories:
- proto
- vendor-protosKey environment variables for configuration:
BUF_TOKEN # Authentication token for BSR
BUF_REGISTRY # Custom registry URL
BUF_CONFIG_OVERRIDE # Override config file path
BUF_CACHE_DIR # Custom cache directory
BUF_INPUT_HTTPS_USERNAME # HTTPS authentication username
BUF_INPUT_HTTPS_PASSWORD # HTTPS authentication password
BUF_INPUT_SSH_KEY_FILE # SSH key file path
BUF_LOG_LEVEL # Log level (debug, info, warn, error)Buf provides structured error reporting with multiple output formats:
Exit codes:
Manage check policies for organizational compliance and governance.
# Push policies to registry
buf policy push [policy]
# Update policy dependencies
buf policy update
# Remove unused policies
buf policy prune
# Registry policy management
buf registry policy create <name>
buf registry policy info <policy>
buf registry policy delete <policy>Beta and alpha commands for advanced use cases and experimental functionality with potential for breaking changes.
# Language Server Protocol support
buf beta lsp
# Buf Studio integration
buf beta studio-agent
# Registry webhooks
buf beta registry webhook create <repo>
buf beta registry webhook list <repo>
buf beta registry webhook delete <webhook>
# Plugin management
buf plugin push <plugin>
buf plugin update
buf plugin prune
# Protoc compatibility
buf alpha protoc [files...]
# Token management
buf alpha registry token get
buf alpha registry token list
buf alpha registry token delete <token>