Skip to navigation

Protocol Buffer Reserved Fields: A Claude Code Wire Compatibility Guide

In short: Find which protobuf field names and numbers must be reserved before a schema rename or removal.

Published 21 min read
On this page

Direct answer

A protobuf field is identified on the wire by its field number, not its name, and a removed field’s number and name can be accidentally reused by a later edit unless they are reserved. The proto3 guide documents reserved field names and numbers for exactly that reason. Treating a schema edit as a rename is the mistake this post is about: removing old_field = 3 and later adding new_field = 3 reuses an identity that data already in flight may still be encoded with, and the result is a decoded message that means something different than the sender intended. The concrete win is a schema change you can defend against old data, because every removed identity is recorded as reserved. The concrete loss is that reservation is wire-level metadata; it does not prove that application code, storage, or another language’s generated bindings were updated to match.

Record the old field name, the field number, the replacement, and the reservation status before touching the message. The generated bindings are the last thing to review.

Why an unrecorded removal costs a data incident

Field-number reuse fails quietly and far from the edit. A producer stops writing field 3, a consumer upgrades, and messages encoded by the old producer still carry bytes for field 3. If a new field takes number 3 with a different type, the decoder reads the old bytes as the new field and produces a value nobody sent. If the type happens to match, the message decodes and means something different than it did.

Three costs follow. Debugging time goes up because the failure appears in a consumer that never changed. Data risk goes up because already-stored messages encode the old identity and cannot be rewritten retroactively. Cross-language risk goes up because each language’s generated bindings may report the collision differently, so one service can build while another fails.

Recording removals is cheaper than investigating a decode incident later. The proto3 guide describes field identity and the reserved mechanism. This post stays on the schema contract and the wire, and it does not claim reservation alone proves application compatibility.

Why Field Identity Matters

On the wire, a field is a number and a type. The name is a source-level convenience. Two messages that agree on numbers and types interoperate even if the names differ, and two messages that disagree on a number do not interoperate even if the names match.

Identity component Role on the wire What a rename affects
Field number The wire identifier Nothing, if the number is unchanged
Field type How bytes are interpreted Compatibility, if the type changes
Field name Source-level reference Generated code and source, not the wire

A rename that keeps the number and type is wire-compatible: old data still decodes, and new data still decodes, because nothing on the wire changed. A rename that changes the number is a removal plus an addition, and it is where the incident lives. This is the distinction the whole review turns on, and it is the one that is easiest to get wrong in a large schema file.

Read Field Numbers and Names

Before editing a message, read the current field numbers and names as a map. The map is what tells you whether an edit is a rename, a removal, or a reuse of an old identity.

bash
grep -n "= [0-9]" message.proto
# list every field with its number
grep -rn "reserved" message.proto
# list what is already reserved

The second grep matters as much as the first. A message that already has reservations has a history, and reusing a number that is reserved is a compile error in most toolchains. The reservations are the record of past removals, and reading them before an edit prevents repeating a mistake the schema already documents.

What to record Why Where it lives
Every field number in use Prevents accidental reuse of a live number The message body
Every reserved number Prevents reuse of a removed number reserved declarations
Every reserved name Prevents reuse of a removed name reserved declarations
Every field type Determines whether a change is wire-compatible The message body

Read the table as a pre-edit inventory. The guardrail for this topic is explicit: do not reuse a removed field number casually. The inventory is how that guardrail becomes a check rather than a memory test.

Classify Renames and Removals

Every field edit falls into a small set of categories, and each category has a different compatibility consequence. Classifying before editing is the review step that prevents the incident.

Edit Wire effect Compatibility Action
Rename, number and type unchanged None Compatible Optional: reserve the old name
Remove a field Identity leaves the schema Compatible if number is reserved Reserve the number and the name
Add a field with a new number New identity appears Compatible Use an unused number
Reuse an old number Identity is redefined Incompatible Do not do this; reserve instead
Change a field’s type Bytes are reinterpreted Often incompatible Treat as removal plus addition

Official, F051: The proto3 guide documents reserved field names and numbers so removed or renamed identities are not reused accidentally. The protobuf pages were not fetched in this pass, so the exact reserved syntax and compatibility wording should be verified against the current guide before relying on a fine detail.

The table works as decision aid. Two rows are safe and three require a decision. The rename row is the one teams get wrong most often, because a rename feels like a text edit and is actually a wire-neutral change only when the number and type stay put. The Go module compatibility guide makes the same distinction for Go: an exported change is compatible or it is not, and the label depends on the contract rather than on how small the diff looks.

Use Reserved Declarations

Reserved declarations are how a schema records that an identity is retired. A reserved number cannot be reused by a later field, and a reserved name cannot be reused either. Together they turn a removal into a documented decision.

bash
message Order {
reserved 3, 7;
reserved "old_status", "legacy_note";
string status = 4;
string note = 5;
}

The two forms are separate. Numbers are reserved as a list, and names are reserved as a list of strings. A message can reserve both. The exact syntax should be verified against the current proto3 guide, because this post does not claim a specific protobuf version requirement.

Reservation What it prevents What it records
reserved 3; A future field taking number 3 Number 3 belonged to something and was removed
reserved "old_status"; A future field taking the name The name belonged to something and was removed
Both together Reuse of the full identity The identity was retired deliberately

Derived, F052: Recording the old field name, the field number, the replacement, and the reservation status before editing the message is an editorial compatibility checklist built on the proto3 guide. The checklist is a review method, not a guarantee about serialized data or application behavior.

Use the table as record-keeping aid. A reservation is a comment the compiler enforces. A reservation costs one line and prevents a class of incident that is expensive to debug, which is a good trade in any schema that more than one team reads.

Review Generated Language Bindings

Reservation protects the wire and the source-level identity. Generated bindings are the per-language output the compiler produces from the schema, and they are the place where a schema change shows up as code. Do not hand-edit them; regenerate.

bash
protoc --<language>_out=./gen ./message.proto
# regenerate bindings from the schema, not by editing ./gen

The review question for bindings is whether every language that reads the message was regenerated from the same schema. A schema change that regenerates one language and not another produces services that disagree about the message, and the disagreement can be invisible until a message crosses the boundary.

Language Binding artifact Review action
Go Generated struct types Regenerate and review the diff
Python Generated message classes Regenerate and review the diff
Java Generated classes Regenerate and review the diff
C++ Generated headers and sources Regenerate and review the diff

The C++ generated-code reference at protobuf.dev is one example of the per-language documentation. This post does not present one language’s output as universal, and the guardrail is explicit: do not present one language generator’s output as universal. Each language has its own generated surface and its own collision behavior.

Check Cross-Language Consequences

A schema change is a cross-language event. The wire contract is shared, so a change that is safe in one language’s bindings can be a build failure or a silent misread in another. Checking across languages is the step that catches what a single-language review misses.

Consequence Where it appears Review action
Compile error on a reserved reuse Any language with strict tooling Fix the schema, not the binding
Silent field mismatch A consumer reading old bytes Confirm reservation before merge
Name collision in a binding A language where the old name still exists Regenerate every language
Type reinterpretation Any consumer decoding the field Treat as removal plus addition

Every row of the table is cross-language checklist. Every row is a consequence that a single-language build cannot detect. The Conan CMakeDeps guide covers the parallel for C++ dependencies: a consumer-facing contract has to stay stable across the consumers that read it, and each consumer may surface the change differently. The honest limit of this section is that whether a specific language’s tooling rejects a reserved reuse is a property of that tooling and version. This post does not claim a universal behavior, and the guardrail against inventing a protobuf version requirement applies here.

Document the Schema Decision

A schema decision worth keeping is a record of what changed, why, and what was reserved. The record turns a future schema question into a lookup, and it is the artifact that survives the engineer who made the change.

Decision field Content Example
Old field name The name that was removed old_status
Old field number The number that was removed 3
Replacement The new field, if any status = 4
Reservation Numbers and names reserved reserved 3; reserved "old_status";
Reason Why the identity was retired Field renamed for clarity; wire number retired

Approach the table as changelog entry. Each row is something a reviewer or a future reader needs. The reason row is the one most often skipped, and it is the one that prevents a well-meaning later edit from undoing the decision. The sqlc query annotations guide keeps the same record for generated query APIs: what changed, why, and what the generated contract now is. The record also makes the agent conversation concrete. When Claude Code proposes a schema edit, the review question is whether the record exists, not whether the generated bindings compile.

The concrete win, loss, and implication

The concrete win is a schema that can be changed without fear of old data. Every removed identity is reserved, so a future field cannot accidentally take a number that stored messages still use. That property is what lets a long-lived protobuf service evolve at all.

The concrete loss is that reservation is wire metadata, not application proof. Reserved identities prevent reuse at the schema and wire level. They do not confirm that every consumer was redeployed, that stored data was migrated, or that application logic that referenced the old field was updated. Those are separate verifications.

The practical implication is that field numbers are a permanent budget. Teams that treat numbers as reusable free up a number and pay for it later. Teams that reserve on removal treat the number space as append-only, which is the discipline that keeps old messages decodable for the life of the data.

Working with Claude Code on a schema change

Give the agent three inputs: the message and the change you want, the commands it may run, and the definition of done. The definition of done includes a reservation for any removed identity and regeneration of every affected language’s bindings. Read-only inventory first.

bash
grep -n "= [0-9]" message.proto
# ask for the field inventory before any edit
grep -n "reserved" message.proto
# ask for the existing reservations next

Review the agent’s classification claim. The agent can read the schema accurately and still propose reusing a number, because a reused number makes the diff smaller. Deciding whether an identity is retired is a compatibility decision, and the reviewer owns it. The Claude Code verification guide covers what to ask before accepting the change.

A schema change that regenerates bindings in many languages at once is worth pausing on. The Claude Code database migration safety guide covers the adjacent risk of destructive schema changes in databases, and a proto removal is destructive in the same sense: the old identity cannot be recovered from the new schema.

Evidence map showing field number and name as wire identity, and reserved declarations as the record that prevents reuse of a removed identity.
Editorial evidence map based on F051 and F052. Reserved field names and numbers are compatibility metadata; review them before reusing an old identity.

Stored data and in-flight messages

The reason reservation matters is that protobuf data outlives the schema that wrote it. A message encoded last month still carries bytes for every field the producer set, and the schema you edit today has to keep decoding those bytes. Two populations of data are always in play during a schema change.

Stored data is the durable population. Rows in a database, objects in a bucket, entries in a cache, and event-log records all encode fields under the numbers the schema used when they were written. Those bytes cannot be rewritten retroactively by deploying a new schema, because the data is already on disk. A number that is removed and reused will be read against the new field’s type when an old record is decoded.

In-flight messages are the transient population. A producer mid-deploy may still encode the old field while a consumer is already running the new schema, and the window can last as long as a rollout. Reservation is what makes that window safe, because the consumer’s schema still remembers that the number belonged to something and will not hand it to a new field.

Data population Where it lives Why reservation matters
Stored records Databases, buckets, caches, logs Bytes cannot be rewritten retroactively
In-flight messages Producers and consumers mid-rollout Old and new encoders overlap during deploy
Backups and archives Cold storage Decoded long after the schema changed

Read the table as the reason the discipline exists. Field-number reuse is not a theoretical concern about future data. The concern is present-tense: data that already exists, and reservation is the only mechanism in the schema that remembers the old identity after the field is gone.

The storage case has a practical consequence worth naming. If your project stores protobuf messages in a database, the schema file and the stored data are two artifacts that must be kept compatible, and the schema is the one that changes. The Claude Code database migration safety guide covers the same asymmetry for SQL schemas: the migration is destructive in one direction, and the data outlives the change.

A worked removal and its reservation

A concrete example makes the checklist readable. Suppose a message carries a status field at number 3 and a note field at number 7, and a change removes both in favor of a single status field at a new number.

bash
message Order {
string status = 4;
reserved 3, 7;
reserved "old_status", "legacy_note";
}

The change is readable as four decisions. The new status field takes number 4, a number that was never used, so no old data can collide with it. Numbers 3 and 7 are reserved, so no future field can take them. The names old_status and legacy_note are reserved, so no future field can take those names either. A reviewer can confirm all four from the message body without reading any generated code.

The unreserved version of the same change is the incident. If status had taken number 3 instead of 4, every stored record that encoded old_status at number 3 would decode as status, and the value would be interpreted as a string the sender never wrote as the new field’s meaning. The type happens to match in this example, which is the most dangerous case: the message decodes cleanly and means something different.

Decision Reserved version Reused-number version
New field number 4, never used 3, formerly old_status
Old number 3 Reserved, cannot be reused Reused by the new field
Old bytes for field 3 Decode as unknown, ignored Decode as the new field
Reviewer check Reservation visible in schema Nothing records the old identity

The table works as whole argument in four rows. The reserved version costs two lines. The reused-number version costs a data incident that appears in a consumer nobody changed, at a time nobody is watching. The comparison is also why the pre-edit inventory matters: without reading the old numbers first, the reuse is easy to commit by accident, because the new field looks like a simple addition. The same worked reasoning applies to names. Reserving the old name prevents a future field from taking old_status at a different number, which would compile in every language and still mislead every reader who remembers the old field by its name. Names are cheaper to reserve than numbers, because they cost nothing on the wire, and they protect the human layer that reads the schema.

Checklist before you change a message

Check Pass condition If it fails
Field inventory read Every number and name in the message is listed Grep the message before editing
Existing reservations read Current reserved numbers and names listed Grep for reserved declarations
Edit classified The change is labeled rename, removal, or addition Classify before editing
Wire effect stated Whether the wire bytes change is answered Read the field number and type
Removals reserved Every removed number and name is reserved Add the reservation
Bindings regenerated Every affected language regenerated from schema Regenerate, do not hand-edit
Cross-language check Each consuming language builds Regenerate the missing language
Decision recorded Name, number, replacement, reservation, reason written down Record before merge
Workflow from reading the field inventory through classifying the edit, reserving removed identities, regenerating bindings, and recording the decision.
Editorial workflow based on F052. The sequence is a review routine; exact reserved syntax should be verified against the current proto3 guide.

Data gap and future update

The proto3 guide, the updating-a-message-type section, the reserved fields section, and the C++ generated-code reference are the sources used here, and they were not fetched in the research pass. Exact reserved syntax, the precise compatibility wording, and any version-specific behavior should be verified against the current documentation before relying on a fine detail. F051 is official in its broad claim and F052 is derived.

No protobuf version requirement is claimed. Whether a specific toolchain version rejects a reserved reuse, and how it reports it, is a property of that toolchain. A future update producing a per-language collision-behavior table would need a measured pass across toolchains, and no such data was collected.

Application-level compatibility is out of scope. Whether a consumer’s logic correctly handles the replacement field is a property of that consumer, and reservation does not certify it. This post deliberately treats wire compatibility and application compatibility as different claims.

Tradeoff between reserving every removed identity to protect old data and the growing reserved block that records a message's removal history.
Editorial tradeoff diagram based on F051 and F052. Reservation costs one line per removal and prevents a class of decode incident that is expensive to debug after the fact.

Wire and schema compatibility appear across this batch. OpenAPI Generator Customization and GraphQL Code Generator Client Presets cover keeping generated output attributable to its inputs. sqlc Query Annotations covers the SQL-to-generated-code contract. C# Source Generators covers compiler-emitted contracts.

Compatibility and version discipline appear in Go Module Compatibility, Cargo Feature Unification, and Gradle Capability Conflicts. Build and dependency boundaries appear in TypeScript Project References, Conan CMakeDeps, and pnpm Peer Diagnostics.

Compatibility and version discipline appear in Go Module Compatibility, Cargo Feature Unification, and Gradle Capability Conflicts. Build and dependency boundaries appear in TypeScript Project References, Conan CMakeDeps, and pnpm Peer Diagnostics.

Input ownership beyond schema compatibility is covered by OpenAPI Generator Customization, sqlc Query Annotations, and GraphQL Code Generator Client Presets. Verification habits for generated output appear in Claude Code Verification, Claude Code False Success, and Claude Code License Compliance.

More from this batch

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. Free IDs are a different client and request format, not a workaround for Claude Code authentication. Check the free model list before choosing an agent route, or read the quickstart for the request shape.

FAQ

Why reserve a field number I am never going to use again?

Because old data and in-flight messages may still encode that number. If a later field takes the number, the decoder reads the old bytes as the new field. A reservation turns that from a silent misread into a compile-time error at the moment someone tries to reuse the number.

Does a rename that keeps the field number break the wire?

No, provided the number and the type stay the same. The wire identity is the number and the type. The name is a source-level reference. Reserving the old name is still worth doing so a future field cannot take it, but the wire is unaffected by the name change.

Does reservation prove my application is compatible?

No. Reservation is wire and schema metadata. A reservation prevents reuse of a retired identity. Whether every consumer was redeployed, whether stored data was migrated, and whether application logic was updated are separate verifications that reservation does not cover.

Can I hand-edit the generated bindings to speed things up?

No. Generated bindings are compiler output, and hand edits are overwritten on the next generation. Regenerate from the schema. A hand-edited binding can disagree with the schema and with other languages’ bindings, which is exactly the cross-language failure this post warns about.

What proves a schema change is complete?

Four conditions. Every removed number and name is reserved, every affected language’s bindings were regenerated from the same schema, each consuming language builds, and the decision is recorded with the reason. A schema that compiles in one language is not a pass.

More Claude Code troubleshooting

Sources

Control checklist covering field inventory, edit classification, reservations, binding regeneration, cross-language builds, and decision recording.
Editorial control checklist derived from F051 and F052. Passing the checklist shows the schema change was reviewed honestly; it does not prove application compatibility across every consumer.
Verdict that treating field numbers as an append-only budget and reserving removed identities keeps old data decodable.
Editorial verdict based on F051 and F052. Reserve removed identities before reusing a number, and treat reservation as wire metadata rather than application proof.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →