Skip to content

Conversation

@amithkk
Copy link

@amithkk amithkk commented Jan 18, 2026

This PR adds a new postprocess_cmd option to plugin configurations in buf.gen.yaml. This allows users to specify commands that run after code generation for each plugin, enabling automatic formatting, linting, or other post-processing of generated files.

Motivation

Solves #3207

Many protoc plugins generate code that doesn't conform to a project's formatting standards and some languages need postprocessing (eg. python) for the modules to be importable. Currently, users must manually run formatters and cleanup scripts after buf generate, or maintain separate scripts. This feature allows integrating post-processing directly into the generation workflow.

Common use cases:

  • Running gofmt or goimports on generated Go code
  • Running proletariat on generated python code to fix imports

Usage

version: v2
plugins:
  - local: protoc-gen-python_betterproto
    out: gen/python
    postprocess_cmd:
      - "ruff check --fix $out"
      - "black $out"

Supported Variables

Commands support variable substitution:

  • $out - output directory (resolved with any base output path)
  • $name - plugin name
  • $opt - plugin options (comma-separated)
  • $path - plugin path (for local plugins)
  • $strategy - generation strategy ("directory" or "all")

Unit tests have been added

@CLAassistant
Copy link

CLAassistant commented Jan 18, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants