cargo-brief
Visibility-aware Rust API extractor — pseudo-Rust output for AI agent consumption.
Why?
AI coding agents need to understand crate APIs without reading full source files. HTML docs waste tokens on navigation chrome, and cargo doc --json is too verbose. cargo-brief outputs concise pseudo-Rust that fits in a context window:
- Function bodies replaced with
; - Only items visible from the caller's perspective
- Doc comments preserved verbatim
- Compact module hierarchy
Installation
Requires the nightly toolchain (for rustdoc --output-format json):
Usage
The first argument is flexible — it can be a crate name, self, a crate::module path, or even a file path:
| Syntax | Resolves to |
|---|---|
my-crate |
Named crate (hyphen/underscore normalized) |
self |
Current package (detected from cwd) |
self::module |
Current package, specific module |
crate::module |
Named crate + module in one arg |
src/foo.rs |
File path → auto-converted to module path |
unknown_name |
If not a workspace package → treated as self module |
Examples
# Show the full API of a crate in your workspace
# Inspect the current package
# Show a specific module (multiple syntaxes)
# Show only what's visible from an external crate
# Limit recursion depth
# Exclude certain item kinds
# Search for items by name (fuzzy / imprecise search)
Options
| Flag | Description |
|---|---|
<target> |
Target to inspect: crate name, self, crate::module, or file path |
[module_path] |
Module path within the crate (e.g., my_mod::submod or src/my_mod.rs) |
--at-package <pkg> |
Caller's package name (for visibility resolution) |
--at-mod <path> |
Caller's module path (determines what is visible) |
--depth <n> |
How many submodule levels to recurse into (default: 1) |
--recursive |
Recurse into all submodules (no depth limit) |
--all |
Show all item kinds including blanket/auto-trait impls |
--no-structs |
Exclude structs |
--no-enums |
Exclude enums |
--no-traits |
Exclude traits |
--no-functions |
Exclude free functions |
--no-aliases |
Exclude type aliases |
--no-constants |
Exclude constants and statics |
--no-unions |
Exclude unions |
--no-macros |
Exclude macros |
--search <pattern> |
Search leaf items by name (case-insensitive, multi-word AND) |
--toolchain <name> |
Nightly toolchain name (default: nightly) |
--manifest-path <path> |
Path to Cargo.toml |
Search Mode
--search finds leaf items whose full path contains the given pattern (case-insensitive). Multiple words are AND-matched — all must appear somewhere in the path.
// crate hecs — search: "component" (11 results)
/// A collection of component types
;
Leaf items included in search: functions, methods, struct fields, enum variants, constants, statics, type aliases, macros, associated types/consts. Container types (struct, enum, trait, union) appear when their name matches directly.
Output Format
// crate my_crate
AI Agent Setup
Claude Code
Add a note to your project's CLAUDE.md so the AI knows to use cargo-brief when exploring crate APIs:
Use `cargo brief` to inspect crate interfaces instead of reading source files directly:
cargo brief self --recursive
cargo brief self::some_module --recursive
cargo brief src/some_module.rs --recursive
cargo brief <crate> --recursive
cargo brief <crate> --manifest-path path/to/Cargo.toml --recursive
cargo brief <crate> --at-package consumer-crate --recursive
cargo brief <crate> --search "spawn entity"
cargo brief --crates serde --search "deserialize"
Generic LLM Agent
Pipe the output directly into your agent's context:
# Current package API
|
# Specific module
|
Or use it as a tool call that returns the output as a string to the agent.
License
MPL-2.0