Direct answer
A feature in Cargo is a name attached to optional dependencies and other features, and which of those names end up active in a build depends on the set of packages Cargo selects, not only on the one manifest entry you edited. When two packages in the same dependency graph enable different features of a shared dependency, Cargo unifies them, and the shared dependency is built once with the union of the requested features. That union is why a feature you never enabled in your own crate can still appear active, and why removing it from your Cargo.toml sometimes has no effect at all. The concrete win is being able to predict which optional APIs exist in a build before you write code against them. The concrete loss is that a feature being enabled is not proof the feature’s code path runs or works, so feature flags describe availability rather than verified behavior.
Ask Claude Code to map the selected packages and the feature requests that reach each one before changing a feature declaration. An edit made against a single manifest line, judged without the resolver context, is the change that surprises everyone in review. The artifact worth keeping is a small table of which package enables which feature and why.
Why a surprise feature costs a build
Three symptoms come from reasoning about features one manifest at a time. A binary that should stay small pulls in a heavy optional dependency because another member of the workspace enabled it. A #[cfg(feature = "...")] block compiles in one crate and not another, and the difference looks like a mystery until someone notices the feature was unified in from a sibling. A default feature removal appears to do nothing because a transitive dependency re-enables it.
None of these are resolver bugs. They are the expected result of a resolver that has to produce one build for a whole graph. The cost is paid in build times, in binary size, and in review time spent arguing about a line that was never the real cause. Understanding the selected package set and the feature union is cheaper than debugging it after a surprise appears in the build.
There is a revert advantage too. Feature changes live in Cargo.toml and in the command line, so exploring them does not rewrite source. A cargo tree run is read-only, which makes feature investigation a reasonable Claude Code task: the agent proposes a mapping and a change, and a reviewer checks it against the tree rather than against intuition.
Evidence and its limits
Official, F015: The Cargo Book documents features as named optional dependency and feature relationships, with resolver behavior documented separately on the resolver page. A feature can enable optional dependencies, enable other features of the same package, or enable features of dependencies. The feature and resolver pages were not full-page fetched during research, so exact wording for a specific version should be rechecked before relying on a fine detail.
Official, workspaces: The workspaces reference documents how members relate to a workspace and how package selection works across it. Feature unification happens in the context of the packages a build selects, so the workspace structure is part of the answer rather than a side note.
Official, F016 support: Claude Code best practices recommends giving the agent a check that returns pass or fail. For a feature change the check is a build of the affected packages plus a cargo tree comparison. Claude Code common workflows covers iterating an edit against a command.
Derived, F016: A review method that maps defaults, optional dependencies, workspace members, and command-line selections before predicting the exposed API surface is an editorial workflow built on the official feature and resolver documentation. It is not a claim that the resulting API has been exercised or that any specific build succeeded.
No benchmark, compile-time measurement, or binary-size number is reported here, because none was measured. The post describes how features are requested and combined, not how fast any configuration builds.
What Cargo features declare
A feature is declared in a [features] table in Cargo.toml. Each feature is a name mapped to a list of things it enables: optional dependencies by name, other features of the same package, or features of dependencies written as dep/feature. A feature with an empty list is still a valid switch that other code can test with #[cfg(feature = "...")].
Optional dependencies and features are linked but distinct. Writing dep = { version = "1", optional = true } makes the dependency optional, and Cargo implicitly creates a feature named after it so dep = ["dep"] style activation works. An explicit feature that names the optional dependency makes the relationship readable and lets you layer extra behavior on top.
| Declaration | What it expresses | Effect when enabled |
|---|---|---|
serde = { version = "1", optional = true } |
An optional dependency | Dependency is included; implicit serde feature exists |
json = ["serde"] |
A named feature enabling a dependency | Enabling json pulls in serde |
full = ["json", "yaml"] |
A meta feature enabling others | Enabling full enables both listed features |
tls = ["native-tls"] |
Feature enabling an optional backend | Enabling tls includes the TLS backend |
Read the table as a wiring diagram. A feature is not behavior; it is a request that changes what gets compiled. The behavior lives in the #[cfg] code and in the optional dependency, and the feature only decides whether those are present in a given build.
Read optional dependencies
An optional dependency is a dependency that is only compiled when something enables it. That something can be your own feature declaration, another package enabling the feature, a command-line flag, or a default feature you did not disable.
[dependencies]
serde = { version = "1", optional = true }
[features]
serde = ["dep:serde"]
default = []The dep: prefix in a feature list names the optional dependency directly without exposing an implicit feature of the same name. The dep form is the clearer one to prefer when you want a single named switch, because it separates the name a consumer enables from the dependency that gets pulled in.
The distinction matters during review. An implicit feature named after the dependency means any package that writes features = ["serde"] enables it. With the dep: form the same text enables nothing unless you declared a matching feature. Teams that do not know which form they used spend review time chasing a feature name that exists in one crate and not another.
Map feature propagation
Features propagate along dependency edges. When package A depends on package B and enables a feature of B, that feature is active for B in the build. When two packages both depend on B with different features, the union is used, because Cargo builds B once per graph. This union is the heart of unification.
| Selected package | Enables on shared dependency | Shared dependency builds with |
|---|---|---|
| your crate | serde |
serde |
| workspace sibling | serde, derive |
serde plus derive |
| a transitive dependency | std |
union of all three so far |
Reading the table bottom up, the shared dependency ends up with the union of every feature any selected package requested. The union rule is what makes a single dependency build coherent: there is one compiled version of it, and it has to satisfy every requester at once. The same property is why you cannot have two mutually exclusive configurations of one dependency in a single build.
Command-line selections add to the union. cargo build --features json adds json to whatever the manifests already request, and --no-default-features removes the default set for the package being built. Because these add rather than replace, a flag can quietly enable a feature you thought you had turned off in the manifest.
Understand resolver context
The resolver is the part of Cargo that decides which versions and which feature sets satisfy the graph. Features are resolved in the context of the packages being built, so the same manifest can produce different feature activation depending on what is selected. The resolver reference documents this behavior separately from the feature declaration syntax.
| Resolver question | What it decides | Where it shows up |
|---|---|---|
| Which packages are selected | The set being built, including workspace members and their deps | cargo tree, build plan |
| Which features each selected package requests | The union applied to shared dependencies | cargo tree -f "{f}" |
| Which versions satisfy requirements | One version per package per graph | Cargo.lock |
| Whether features are additive or replace | Whether a flag adds to or overrides manifest requests | Command-line behavior |
One resolver mode is not universally better than another for every project. The resolver pages were not full-page fetched during research, so this post does not recommend a specific resolver setting or enumerate version-specific behavior. What carries over to any resolver is the union principle: a shared dependency is built once with the features its requesters asked for.
The practical consequence of resolver context is that a feature’s presence depends on the whole selected set. A feature you never wrote can arrive because a newly added dependency requested it. The mapping in the next section is how you make that visible before it reaches a build.
Trace workspace selection
In a workspace, the packages a single command selects determine the feature union. Building one member selects that member and its dependencies. Building the whole workspace selects every member, and the shared dependencies get the union of every member’s requests. This is the mechanism behind the surprise where a feature appears only in a full workspace build.
| Command | Packages selected | Feature union scope |
|---|---|---|
cargo build -p app |
app and its dependencies |
Features requested by app and its deps |
cargo build at workspace root |
All workspace members | Union across every member |
cargo test --workspace |
All members plus test deps | Union including dev and test requests |
cargo build --features json -p app |
app and deps |
app requests plus json |
The workspace reference documents membership and how the workspace root relates to members. For feature work the important property is that selection changes the union. A feature that is absent in a single-package build and present in a workspace build is not a bug; it is the union doing exactly what the requests say.
This is where the Cargo workspace inheritance guide connects. Inheritance centralizes manifest metadata such as shared version and license fields. It does not change which features a member requests. A shared metadata field and a feature request are different mechanisms, and conflating them makes both harder to reason about.
Review a feature change
A feature change is reviewable when you can say which packages it affects and what API surface appears as a result. The review starts before the edit, with a mapping of the current activation.
| Step | Command or source | What it answers |
|---|---|---|
| List features of a dependency | cargo tree -f "{p} {f}" |
Which features are active on each package |
| See who enables a feature | Search member manifests for features = |
Which package requested the feature |
| Check defaults | [features] default in the manifest |
What is on when nothing is specified |
| Confirm the API surface | #[cfg(feature = ...)] blocks in source |
Which code compiles under the feature |
Two defects to catch during review. A feature removed from your manifest that reappears in the build was being re-enabled by a transitive dependency or a sibling, so the removal needs to be accompanied by a decision about the dependency rather than a line deletion. A feature added for one member that changes another member’s build is the union at work, and the reviewer should confirm the second member still builds and its behavior is acceptable.
cargo tree -f "{p} {f}" > before.txt
# make the feature change
cargo tree -f "{p} {f}" > after.txt
cargo build -p appThe pass condition is concrete. The build of every affected package succeeds, and a diff of the two tree files shows feature changes only where you intended them. The official best-practices guidance favors this kind of before-and-after check over a prose report, because a tree diff is unambiguous about what the union became.
Explain the resulting API surface
After the change, the artifact worth keeping is a table of which optional APIs exist in each build configuration you care about. A feature that is enabled compiles the code guarded by #[cfg(feature = "...")], which makes those types and functions available to callers. A feature that is not enabled means that code is not compiled and calling it is a compile error rather than a runtime failure.
The distinction that matters is availability versus correctness. A feature being enabled means the guarded code is present in the build. It does not mean the code path runs in your tests, and it does not mean the feature works in your configuration. Presenting an enabled feature as proven runtime behavior is the claim this post avoids.
| Build configuration | Features active | Optional API available |
|---|---|---|
-p lib default |
none beyond default | only unconditional API |
-p app |
serde from app request |
serialization types compiled in |
| workspace build | union incl. sibling requests | full set across members |
--no-default-features |
defaults off | reduced surface, may not compile if code assumes defaults |
Read the last row as the honest caveat of feature work. Removing defaults can leave code that assumed a feature broken at compile time, which is why the pass condition includes building every affected package rather than only the one you edited.
The concrete win, loss, and implication
The concrete win is a build you can predict. Once someone writes down which package enables which feature, the question “why is this optional API here” becomes a lookup instead of an archaeology exercise. New dependencies get added with a conscious decision about the features they request, and binary size surprises get traced to a named requester.
The concrete loss is that a feature map goes stale. Features are requested in many places across a workspace, and the union changes whenever a dependency is added or upgraded. A mapping produced today describes today’s graph, and the next dependency bump can change it. Keeping the map accurate is a maintenance cost, not a one-time task.
The practical implication is that feature flags are a graph property, not a per-file property. Teams that review feature changes against cargo tree spend less time reverting edits that did not do what they expected. Teams that judge a feature change from one manifest line keep rediscovering the union rule the hard way.
Related reading on build and resolution boundaries
Feature activation is one resolution boundary among several this batch covers. On the same crate, the Cargo profile boundaries guide covers separating diagnostic and optimization settings from settings that change program behavior, which is the same review-by-purpose discipline applied to build profiles. The Cargo build scripts guide covers generated artifacts and rerun conditions, which is where a feature can change what a build script emits.
Version and graph selection in other ecosystems appear in Go Module Graph Pruning, which covers minimal version selection and indirect requirements, and Gradle Constraints vs Dependencies, which covers influencing a version without adding a graph edge. Gradle Variant Attributes covers selecting the right artifact for a consumer, a close cousin of feature selection.
Optional and transitive expectations have their own guides: Maven Optional Dependencies covers keeping transitive expectations explicit, and pnpm Peer Diagnostics covers reading a peer resolution report before pinning. NuGet Central Package Management covers centralizing versions across projects.
Review and verification habits around feature work
Feature changes are easy to get wrong quietly, which makes verification habits relevant. Before calling a feature change done, ask what Claude Code verification requires, and prevent false success from passing tests when the check is a green build that never exercised the enabled code path. A feature that compiles is present, not proven.
The cost of building every affected package to verify a small feature edit connects to Claude Code cost per verified change. A tree diff is a cheap check that earns its place on every feature change. When a feature edit turns into a workspace-wide reformat, that is the pattern the Claude Code overengineering guide warns about.
What a dependency does during installation, as distinct from what it does when compiled with a feature, is covered by the Claude Code dependency install side effects guide. The risk of a proposed dependency that does not exist is covered by the Claude Code hallucinated packages guide.
Checklist before you change a feature
Run this list before approving a feature change. Each row is a pass condition.
| Check | Pass condition | If it fails |
|---|---|---|
| Activation map | Every package enabling the feature is named | Build the map before editing |
| Union accounted for | Sibling and transitive requests identified | Run cargo tree -f "{p} {f}" |
| Defaults understood | Default feature set recorded | Read [features] default |
| Affected packages build | Every package whose union changed compiles | Build each, not just the edited one |
| Tree diff scoped | Feature changes match intent | Investigate unexpected unions |
| Availability vs behavior | No claim that an enabled feature is verified runtime behavior | Add a test that exercises the path |
| Command-line flags | Any --features or --no-default-features usage documented |
Record the invocation used |
Working with Claude Code on a feature change
Give the agent three inputs: the feature and package you want to change, the commands it may run, and the definition of done. Ask for a cargo tree before-and-after and a build of every package whose feature union changed, and ask it to report which packages enable the feature rather than a summary judgment.
Reviewing the agent’s mapping is the reviewer’s job. The agent can read manifests and run read-only tree commands, but deciding whether a feature should be enabled for a given build is a product and architecture decision. The Claude Code verification guide covers the review questions: what changed, what proves it, and what was not checked.
Data gap and future update
The feature and resolver pages were not full-page fetched during the research pass behind this post, so exact directive syntax and any resolver-version-specific behavior should be rechecked against the current Cargo Book before relying on a fine detail. The union principle in F015 is documented behavior, but the precise interaction with a specific resolver setting is left to the reference.
No compile-time, binary-size, or build-time measurement is reported here, because none was measured. A future update quantifying how a feature union affects binary size for a specific crate would need a measurement pass with a fixed toolchain. No such data was collected.
Feature support in third-party crates is also out of scope. Whether a given crate honors a feature in a documented way is a property of that crate, and this post does not generalize from Cargo’s mechanism to any crate’s implementation.
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. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.
FAQ
Why does a feature stay enabled after I remove it from my manifest?
Another selected package is requesting it. Cargo unifies features across the graph, so a workspace sibling or a transitive dependency can keep the feature active even after you remove your own request. Run cargo tree -f "{p} {f}" and search the member manifests to find the requester.
Does an enabled feature prove the feature works?
No. An enabled feature means the code guarded by #[cfg(feature = "...")] is compiled into the build. Whether that code path is correct in your configuration is a separate question that needs a test exercising it. This post deliberately treats availability and verified behavior as different claims.
Is one resolver mode always better?
The claim stops here. The resolver decides which versions and feature sets satisfy the graph, and the right setting depends on the project. The resolver pages were not full-page fetched during research, so specific version behavior should be rechecked against the current Cargo Book.
Can two members of a workspace request conflicting features?
They can request different features, and the shared dependency builds with the union of all requests. Truly incompatible configurations of a single dependency cannot coexist in one build graph, because there is one compiled copy of the dependency. Resolving a genuine conflict is a dependency decision, not a feature-flag tweak.
What proves a feature change is complete?
Two conditions. Every package whose feature union changed builds successfully, and a cargo tree before-and-after diff shows feature changes only where you intended them. A build of just the edited package is not enough, because the union can change a sibling’s build.
Related reading in this batch
This post is one of six language and build-system guides written together. The Rust side continues with Cargo Profile Boundaries, Cargo Build Scripts, and Cargo Workspace Inheritance. The Go side is covered by Go Module Compatibility, Go Workspace Boundaries, and Go Module Graph Pruning.
JVM and .NET posts cover version and variant selection: Gradle Constraints vs Dependencies, Gradle Capability Conflicts, Gradle Variant Attributes, Maven Optional Dependencies, and NuGet Central Package Management.
Generated-code and framework boundaries appear in C# Source Generators, OpenAPI Generator Customization, GraphQL Code Generator Client Presets, Django Deprecation Runway, Rails Upgrade Sequence, and Angular Update Guide.
More from this batch
- Cargo Profile Boundaries: Keep Debug and Release Behavior Aligned
- Cargo Build Scripts: Define Generated-Artifact Contracts for Claude Code
- Cargo Workspace Inheritance: Centralize Metadata Without Hiding Crates
- Go Module Graph Pruning: Explain Indirect Dependencies With Claude Code
- Gradle Constraints vs Dependencies: Fix Resolution Without Adding Edges
More Claude Code troubleshooting
- Python Dependency Groups vs Extras: A Claude Code Migration Map
- Python Protocols vs ABCs: Preserve Interface Contracts With Claude Code
- Python TypedDict Boundaries: Stop Model Drift With Claude Code
- Python Stub Drift: Audit Third-Party Types With Claude Code
- .NET Multi-Targeting: Separate Framework Dependencies for Claude Code
- CMake Presets: Give Claude Code Reproducible Configure Inputs
- CMake find_package vs FetchContent: Choose a Dependency Boundary
- Conan CMakeDeps: Keep Consumer Targets Stable for Claude Code
- TypeScript Project References: A Claude Code Boundary Guide
- Protocol Buffer Reserved Fields: A Claude Code Wire Compatibility Guide
- sqlc Query Annotations: Align SQL and Generated Types With Claude Code
Sources
- Official: The Cargo Book: Features, supporting features as named optional dependency and feature relationships (F015).
- Official: The Cargo Book: Resolver, reference for resolver context behind feature activation (F016).
- Official: The Cargo Book: Workspaces, reference for workspace membership and package selection.
- Official: Claude Code Docs: Best Practices, supporting the pass-or-fail check loop used as verification.
- Official: Claude Code Docs: Common Workflows, reference for iterating an edit against a command.