Use Buf
Use the Buf CLI as the source of truth for Protobuf compilation, dependency resolution, linting, breaking-change detection, and code generation.
Inspect Before Changing
- Read repository instructions.
- Search the repository root and likely API directories for
buf.yaml, buf.lock, buf.gen.yaml, and buf.gen.<domain>.yaml files.
- Inspect the configuration version, module paths, dependency declarations, lint policy, breaking policy, inputs, plugin pins, output paths, and existing generation scripts.
- Run
buf --version and check repository/CI tool pins before using features from a newer configuration schema.
- Diagnose configuration or dependency problems before changing
.proto files to work around them.
Use one default buf.gen.yaml. Introduce buf.gen.<domain>.yaml only when generation products genuinely require isolated plugin sets, inputs, or outputs. Pass non-default templates explicitly with buf generate --template <file>.
Keep Configuration Responsibilities Clear
- Use
buf.yaml for workspaces/modules, BSR dependencies, lint rules, breaking rules, policies, and Buf check plugins.
- Use
buf.gen.yaml or buf.gen.<domain>.yaml for protoc-gen-* code-generation plugins, inputs, output directories, options, and managed mode.
- Use
buf.lock as generated dependency resolution state. Do not edit it manually.
- Keep configuration in the repository root or the established API workspace directory unless repository structure requires otherwise.
Read references/configuration.md before adding modules, dependencies, check plugins, generation templates, or output paths.
Manage Dependencies Deliberately
- Prefer BSR modules for maintained dependencies, including Google APIs, well-known types, Protovalidate, and grpc-gateway annotations.
- Add or remove dependencies in
buf.yaml, then run buf dep update and inspect the buf.lock diff.
- Use
buf dep graph --format json to identify the resolved dependency chain.
- Use
buf dep prune only after confirming an import is genuinely unused.
- When a type appears missing, inspect configuration and the lockfile, run
buf dep update, then run buf build or buf generate to obtain the compiler's concrete import/type error.
- Never hardcode an operating system's Buf cache location. Export the pinned module with
buf export when source inspection is required.
Required Validation
After changing first-party Protobuf or Buf configuration, MUST run:
buf lint
buf generate
buf breaking --against '.git#branch=main'
Also run buf format --diff or the repository's format check and all language-specific tests/type checks for generated outputs.
Do not skip the breaking check merely because a break is intentional. Run it, capture the violations, and report that the change is an approved experimental/unreleased break. If the repository does not have a main branch, report that exact baseline failure and resolve the intended integration baseline rather than silently omitting compatibility validation.
Diagnose in Dependency Order
- Confirm the current directory and discovered
buf.yaml.
- Confirm module paths and import paths.
- Confirm dependencies and
buf.lock with buf dep graph.
- Compile with
buf build.
- Lint with
buf lint.
- Generate with the selected template.
- Inspect plugin stderr, output collisions, and generated diffs.
- Run the breaking check against main.
Use $use-buf-plugins for remote/local plugin selection, offline generation, rate limits, or plugin wrappers. Read references/commands-and-troubleshooting.md for precise inspection commands and failure handling.
1---2name: use-buf3description: Configure, inspect, update, validate, and troubleshoot Buf workspaces and modules. Use when working with buf.yaml, buf.lock, buf.gen.yaml or domain-specific Buf generation templates; managing BSR dependencies; formatting, linting, generating, detecting breaking Protobuf changes; locating dependency schemas; or diagnosing missing types and generation failures.4---56# Use Buf78Use the Buf CLI as the source of truth for Protobuf compilation, dependency resolution, linting, breaking-change detection, and code generation.910## Inspect Before Changing11121. Read repository instructions.132. Search the repository root and likely API directories for `buf.yaml`, `buf.lock`, `buf.gen.yaml`, and `buf.gen.<domain>.yaml` files.143. Inspect the configuration version, module paths, dependency declarations, lint policy, breaking policy, inputs, plugin pins, output paths, and existing generation scripts.154. Run `buf --version` and check repository/CI tool pins before using features from a newer configuration schema.165. Diagnose configuration or dependency problems before changing `.proto` files to work around them.1718Use one default `buf.gen.yaml`. Introduce `buf.gen.<domain>.yaml` only when generation products genuinely require isolated plugin sets, inputs, or outputs. Pass non-default templates explicitly with `buf generate --template <file>`.1920## Keep Configuration Responsibilities Clear2122- Use `buf.yaml` for workspaces/modules, BSR dependencies, lint rules, breaking rules, policies, and Buf check plugins.23- Use `buf.gen.yaml` or `buf.gen.<domain>.yaml` for `protoc-gen-*` code-generation plugins, inputs, output directories, options, and managed mode.24- Use `buf.lock` as generated dependency resolution state. Do not edit it manually.25- Keep configuration in the repository root or the established API workspace directory unless repository structure requires otherwise.2627Read [references/configuration.md](references/configuration.md) before adding modules, dependencies, check plugins, generation templates, or output paths.2829## Manage Dependencies Deliberately3031- Prefer BSR modules for maintained dependencies, including Google APIs, well-known types, Protovalidate, and grpc-gateway annotations.32- Add or remove dependencies in `buf.yaml`, then run `buf dep update` and inspect the `buf.lock` diff.33- Use `buf dep graph --format json` to identify the resolved dependency chain.34- Use `buf dep prune` only after confirming an import is genuinely unused.35- When a type appears missing, inspect configuration and the lockfile, run `buf dep update`, then run `buf build` or `buf generate` to obtain the compiler's concrete import/type error.36- Never hardcode an operating system's Buf cache location. Export the pinned module with `buf export` when source inspection is required.3738## Required Validation3940After changing first-party Protobuf or Buf configuration, MUST run:4142```sh43buf lint44buf generate45buf breaking --against '.git#branch=main'46```4748Also run `buf format --diff` or the repository's format check and all language-specific tests/type checks for generated outputs.4950Do not skip the breaking check merely because a break is intentional. Run it, capture the violations, and report that the change is an approved experimental/unreleased break. If the repository does not have a `main` branch, report that exact baseline failure and resolve the intended integration baseline rather than silently omitting compatibility validation.5152## Diagnose in Dependency Order53541. Confirm the current directory and discovered `buf.yaml`.552. Confirm module paths and import paths.563. Confirm dependencies and `buf.lock` with `buf dep graph`.574. Compile with `buf build`.585. Lint with `buf lint`.596. Generate with the selected template.607. Inspect plugin stderr, output collisions, and generated diffs.618. Run the breaking check against main.6263Use `$use-buf-plugins` for remote/local plugin selection, offline generation, rate limits, or plugin wrappers. Read [references/commands-and-troubleshooting.md](references/commands-and-troubleshooting.md) for precise inspection commands and failure handling.