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
Global flags (-C, -F, --no-cache, …) must appear before the subcommand name.
Subcommands
| Subcommand | Purpose |
|---|---|
api |
Extract API as pseudo-Rust documentation |
search |
Search for items by name |
summary |
Compact module overview with item counts |
examples |
Grep example/test/bench source files |
ts |
Run a tree-sitter structural query against source |
code |
Look up definitions by kind and name |
lsp |
Manage persistent rust-analyzer (references, call graph) |
clean |
Clear cached remote crate workspaces |
Run cargo brief <subcommand> --help for full options.
Core Subcommands
api — render a crate's API
# Current package (run inside a Cargo project)
# Specific module
# Recurse all submodules
# Limit depth
# Exclude item kinds
# Compact output (no doc comments, collapsed bodies)
# Show only what's visible from an external caller
Target resolution — the [TARGET] argument accepts:
| Syntax | Resolves to |
|---|---|
self |
Current package (cwd-based detection) |
self::module |
Current package, specific module |
crate::module |
Named crate + module in one arg |
src/foo.rs |
File path → auto-converted to module path |
my-crate |
Named workspace package |
unknown_name |
Treated as package name |
search — find items by name
# Substring search (smart-case: all-lowercase = insensitive)
# Multiple patterns are AND-matched
# Show methods/fields of a type
# OR-match with comma
# Glob and exact-match operators
Pattern DSL: space = AND, comma = OR. Operators per token:
word— substring matchw*ld— glob (*= 0+ chars,?= 1 char)=Name— exact final segment-term— exclude (use--for patterns starting with-)
summary — module overview
One line per module showing counts of traits, structs, enums, functions, types, constants, macros, and unions.
Remote Crates (-C)
Pass -C before the subcommand to treat TARGET as a crates.io spec:
# Overview of a crates.io package
# Browse a module
# Search
# Feature-gated APIs (omit -F and items are invisible)
Crate spec syntax: name (latest), name@1 (semver-compatible), name@1.2.3 (exact pin).
Downloaded crates are cached at ~/.cache/cargo-brief/crates/. Run cargo brief clean to clear.
Output Format
// crate my_crate
AI Agent Setup
Claude Code
Add to your project's CLAUDE.md:
Use `cargo brief` to inspect crate interfaces instead of reading source files directly.
cargo brief summary self # overview of modules
cargo brief api self::some_module # drill into a module
cargo brief search self SomeType --members # find a specific item
cargo brief code fn some_function --refs # read source + references
cargo brief api my-crate --recursive
cargo brief api my-crate --at-package consumer-crate
cargo brief -C summary tokio@1
cargo brief -C search serde@1 Deserialize
cargo brief api self --manifest-path path/to/Cargo.toml
Generic LLM Agent
|
|
License
MPL-2.0