repo2prompt
A Rust tool for extracting repository content into structured formats (XML, JSON, or text) for use with LLMs and other tools.
Features
- Multiple Output Formats: XML, JSON, or plain text with file markers
- Flexible File Selection: Include/exclude files using glob patterns
- Directory Filtering: Skip irrelevant directories
- Size Limits: Skip files larger than a specified size
- Pretty Printing: Formatted output for XML and JSON
Installation
From crates.io
From source
Usage
repo2prompt [OPTIONS]
Options
-d, --directory <DIRECTORY> Root directory to process [default: .]
-o, --output <o> Output file (default: stdout)
-f, --format <FORMAT> Output format [default: xml] [possible values: xml, json, text]
-i, --include <INCLUDE> File patterns to include (can specify multiple)
-e, --exclude <EXCLUDE> File patterns to exclude (can specify multiple)
--exclude-dirs <EXCLUDE_DIRS> Directory patterns to exclude (can specify multiple)
--max-size <MAX_SIZE> Maximum file size in bytes [default: 1000000]
--pretty Pretty-print output (for XML and JSON)
-v, --verbose Enable verbose logging
-h, --help Print help
-V, --version Print version
Examples
Command Line Examples
Basic usage (XML output to stdout)
Generate JSON output for Python and Markdown files
Save text output to a file, excluding tests
Process a specific directory, excluding multiple directories
Library Usage Examples
The repo2prompt crate can also be used as a library in your Rust projects. Check the examples/ directory for runnable examples:
# Run the basic example
# Run the JSON output example
# Run the programmatic processing example
# Run the custom filtering example
Basic library usage:
use PathBuf;
use ;
// Create a configuration
let config = Config ;
// Run the extraction
run?;
Output Formats
XML
<!-- More files -->
JSON
Text
# src/main.rs
// File content here
# src/lib.rs
// File content here
License
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright
Copyright © 2025 Amund Tveit