mdlens
Token-efficient Markdown structure CLI for AI agents. Navigate, search, and pack Markdown documentation into bounded context windows.
Commands
- tree — Show section hierarchy with token estimates
- read — Extract a section by ID, heading path, or line range
- search — Find sections matching a query across files
- pack — Build a bounded context packet from selected sections
- stats — Inspect file sizes and token estimates
Usage
# Show section tree
# Read a specific section
# Read by full heading path
# Read only the section's direct body
# Search across files
# Pack sections into token budget
# Pack by search results
# Pack by regex search and keep duplicate selections
Section IDs
Sections are identified by dotted IDs reflecting hierarchy:
1— first H1 heading1.1— first child of section 11.2.3— third child of section 1.2
Heading paths are exact section paths from the document root. Escape literal > characters inside a title as \>.
JSON Output
All commands support --json for machine-readable output.
Installation
Prerequisites
Rust 1.70+ and Cargo. Install via rustup:
|
Install from this repo
Install directly from Git
Build from source
# Binary at target/release/mdlens
Verify
Benchmarks