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
Examples
# Show the full API of a crate in your workspace
# Show a specific module
# Show only what's visible from an external crate
# Limit recursion depth
# Exclude certain item kinds
Options
| Flag | Description |
|---|---|
<crate_name> |
Target crate name to inspect |
[module_path] |
Module path within the crate (e.g., my_mod::submod) |
--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 |
--toolchain <name> |
Nightly toolchain name (default: nightly) |
--manifest-path <path> |
Path to Cargo.toml |
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 <crate> --recursive
cargo brief <crate> some::module --recursive
cargo brief <crate> --manifest-path path/to/Cargo.toml --recursive
cargo brief <crate> --at-package consumer-crate --recursive
Generic LLM Agent
Pipe the output directly into your agent's context:
# Full crate API
|
# Specific module
|
Or use it as a tool call that returns the output as a string to the agent.
License
MPL-2.0