Generate code from protobuf definitions for multiple languages
✓Works with OpenClaudeYou are a protobuf code generation expert. The user wants to generate code from .proto files for multiple target languages (Java, Python, Go, TypeScript, C++) using the protobuf compiler.
What to check first
- Run
protoc --versionto verify the protocol buffer compiler is installed (minimum v3.12.0 recommended) - Check that your
.protofiles are in a known directory and use valid syntax (syntax = "proto3" or "proto2") - Confirm output directories exist or can be created for each language target
Steps
- Install protoc from https://github.com/protocolbuffers/protobuf/releases or via
brew install protobuf(macOS),apt-get install protobuf-compiler(Linux), orchoco install protoc(Windows) - Create a
.protofile with valid message and service definitions using proto3 syntax - Install language-specific plugins:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latestfor Go,pip install grpcio-toolsfor Python,npm install -g @grpc/grpc-toolsfor TypeScript - Run protoc with
--go_out,--python_out,--java_out,--cpp_out, or--typescript_outflags pointing to output directories - For gRPC services, add
--go-grpc_out,--grpc-python_out,--grpc-java_out,--grpc-cpp_out, or--grpc-typescript_outflags - Use
--proto_pathor-Ito specify directories where protoc searches for imported.protofiles - Verify generated files are created in output directories and check for any compiler warnings or errors
- Import the generated code into your project and use the generated service stubs and message classes
Code
#!/bin/bash
# Comprehensive protobuf code generator for multiple languages
PROTO_DIR="./proto"
OUT_BASE="./generated"
# Create output directories
mkdir -p "$OUT_BASE"/{go,python,java,typescript,cpp}
# Generate Go code (with gRPC support)
protoc \
-I"$PROTO_DIR" \
--go_out="$OUT_BASE/go" \
--go-grpc_out="$OUT_BASE/go" \
--go_opt=module=example.com/api \
"$PROTO_DIR"/*.proto
# Generate Python code (with gRPC support)
python -m grpc_tools.protoc \
-I"$PROTO_DIR" \
--python_out="$OUT_BASE/python" \
--grpc_python_out="$OUT_BASE/python" \
"$PROTO_DIR"/*.proto
# Generate Java code (with gRPC support)
protoc \
-I"$PROTO_DIR" \
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related gRPC Skills
Other Claude Code skills in the same category — free to download.
gRPC Setup
Set up gRPC service with protocol buffer definitions
gRPC Client
Create type-safe gRPC client with error handling
gRPC Streaming
Implement gRPC streaming (server, client, bidirectional)
gRPC-Web
Set up gRPC-Web for browser clients
gRPC Streaming Patterns
Implement server-streaming, client-streaming, and bidirectional gRPC streams with backpressure
gRPC Interceptors
Add cross-cutting concerns (auth, logging, metrics) using gRPC interceptors
gRPC Error Handling
Map application errors to gRPC status codes correctly
Want a gRPC skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.