| Crates.io | txt |
| lib.rs | txt |
| version | 0.1.4 |
| created_at | 2026-01-08 10:00:54.195365+00 |
| updated_at | 2026-01-18 08:48:35.665769+00 |
| description | cargo doc for coding agents |
| homepage | |
| repository | https://github.com/pyk/cargo-txt |
| max_upload_size | |
| id | 2029882 |
| size | 604,115 |
cargo doc for coding agents
[!IMPORTANT]
cargo-txtis in early active development.
cargo-txt is a cargo subcommand that your LLM or Coding Agents can use to
access the crate documentation locally.
To use it, install the binary with this command:
cargo install txt
Add this instruction to your coding agent:
Use `cargo txt` to access the crate documentation locally.
The workflow is:
1. Build documentation: `cargo txt build <crate>`
2. List all items: `cargo txt list <lib_name>`
3. View specific item: `cargo txt show <lib_name>::<item>`
For example:
```shell
# Build the serde crate documentation
cargo txt build serde
# List all items in serde
cargo txt list serde
# View serde crate overview
cargo txt show serde
# View serde::Deserialize trait documentation
cargo txt show serde::Deserialize
```
I built cargo-txt to feed my coding agent with up-to-date context and reduce
hallucination. It converts cargo doc HTML to markdown so agents can access
actual crate documentation from my local machine, not training data or outdated
information.
Agents get accurate, comprehensive documentation that matches exactly what I'm working with.
$ cargo txt build --help
Generate markdown documentation from rustdoc HTML for coding agents
Usage: cargo txt build [OPTIONS] <CRATE>
Arguments:
<CRATE> Crate name to build documentation for
Options:
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-h, --help Print help
This command generates HTML documentation using cargo doc, converts all HTML
files to markdown, and writes them to the output directory. Output is placed in
the target directory's docmd subdirectory (determined by cargo metadata).
Output Directory Structure:
The output directory uses the library name (from cargo doc output), not
the crate name. For example, building rustdoc-types creates:
target/docmd/rustdoc_types/ # Library name directory (underscores)
├── metadata.json # Contains crate_name, lib_name, and item_map
├── index.md # Crate overview
├── all.md # Master index of all items
└── struct.Item.md # Individual item markdown files
Note: Only installed dependencies listed in your Cargo.toml can be built.
You cannot build documentation for arbitrary crates from crates.io.
Example:
# Build using crate name from Cargo.toml
cargo txt build rustdoc-types
Output:
✓ Built documentation for rustdoc_types (55 items)
Run `cargo txt list rustdoc_types` to see all items
List all items in a crate:
$ cargo txt list --help
List all items in a crate
Usage: cargo txt list [OPTIONS] <CRATE>
Arguments:
<CRATE> Crate name (e.g., 'serde')
Options:
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-h, --help Print help
Examples:
List all items:
cargo txt list rustdoc_types
How It Works:
metadata.json from docmd/<lib_name>/metadata.jsoncargo metadataall.md from the library name directoryOutput Format:
The list command displays formatted output with:
rustdoc_types::Item)cargo txt show examplesExample output for cargo txt list serde:
# serde
List of all items
### Structs
- serde::Error
- serde::de::IgnoredAny
- serde::ser::StdError
### Traits
- serde::Serialize
- serde::Deserialize
## Usage
To view documentation for a specific item, use the `show` command:
```shell
cargo txt show <ITEM_PATH>
```
Examples:
- Show struct: `cargo txt show serde::SomeStruct`
- Show trait: `cargo txt show serde::SomeTrait`
- Show enum: `cargo txt show serde::SomeEnum`
$ cargo txt show --help
Show and display crate documentation
Usage: cargo txt show [OPTIONS] <ITEM>
Arguments:
<ITEM> Item path (e.g., 'serde', 'serde::Error', 'serde::ser::StdError')
Options:
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-h, --help Print help
Important: Use the library name (with underscores), not the crate name (with hyphens). For example:
rustdoc_types::Item (library name)rustdoc-types::Item (crate name - this will fail)Examples:
View crate overview:
cargo txt show rustdoc_types
View specific item documentation:
cargo txt show rustdoc_types::Item
cargo txt show rustdoc_types::Abi
How It Works:
metadata.jsonindex.md (crate
overview)metadata.json to get the item mapError Handling:
metadata.json doesn't exist, shows error with available crate names from
cargo metadatacargo txt list <lib_name> where
lib_name comes from the metadatacargo-txt uses the env_logger and log crates for flexible logging. You can
control output verbosity using command-line flags or environment variables.
-v - Show warnings-vv - Show info messages (important milestones)-vvv - Show debug messages (detailed operational info, equivalent to old
--debug flag)-vvvv - Show trace messages (very detailed diagnostic info)-q, --quiet - Suppress all output (only errors are shown)Examples:
# Show warnings
cargo txt build serde -v
# Show info messages
cargo txt build serde -vv
# Show debug messages (equivalent to old --debug flag)
cargo txt build serde -vvv
# Show trace messages (very verbose)
cargo txt build serde -vvvv
# Suppress output (only errors)
cargo txt build serde -q
You can also control verbosity using the RUST_LOG environment variable:
# Show debug messages
RUST_LOG=debug cargo txt build serde
# Show warnings and errors only
RUST_LOG=warn cargo txt build serde
# Show info and above
RUST_LOG=info cargo txt build serde
# Show trace and above (very verbose)
RUST_LOG=trace cargo txt build serde
# Customize log levels for specific modules
RUST_LOG=txt=debug,cargo=warn cargo txt build serde
By default, cargo-txt shows only error messages.
cargo doc, converts HTML files to markdown, and writes:
metadata.json - Contains crate_name, lib_name, and item_mapall.md - Master index of all items from all.htmlindex.md - Crate overview from index.htmlstruct.Item.md,
trait.Serialize.md) Output directory uses library name (e.g.,
rustdoc_types) instead of crate name (e.g., rustdoc-types).all.md). Accepts library names.index.md) for library name requests or specific item
documentation for full item paths. Uses metadata.json for fast lookups.To install the binary locally for development:
cargo install --path .
This installs the cargo-txt binary directly from the source code in the
current directory.
To build and run the binary without installing:
cargo run -- --help
Run tests:
cargo test
Check code with clippy:
cargo clippy
Contributions are welcome! Please follow these guidelines:
cargo test before submitting changescargo clippy to ensure code qualitycargo install --path .For detailed development guidelines, see AGENTS.md.