CodeContexter is a lightning-fast, safety-first CLI tool written in Rust. It aggregates your entire codebase into a single, structured file (Markdown, JSON, or XML).
It is designed specifically for providing context to Large Language Models (LLMs) like ChatGPT, Claude, and GitHub Copilot without manual copy-pasting.
When working with LLMs, you often need to share multiple files to explain a problem. Copying them one by one is tedious and prone to missing context.
CodeContexter:
- Walks your directory (respecting
.gitignore). - Generates a visual tree of your project structure.
- Aggregates file contents into a single formatted output.
- Redacts secrets automatically to keep your keys safe.
- β‘ High Performance: Parallel processing (Rayon) and streaming output for low memory usage on huge repos.
- π‘οΈ Security First: Automatically detects and redacts private keys, API tokens, and secrets before they leave your machine.
- π§ Smart Filtering: Respects
.gitignore, skips binary files, ignores whitespace-only files, and prevents symlink loops. - π Large File Handling: Smartly truncates files over 1MB (shows the first and last 50 lines) to preserve token limits while keeping context.
- π Clipboard Ready: Optional flag to copy the output directly to your clipboard.
- π¨ Multiple Formats: Output to Markdown (default), JSON, or XML.
Ensure you have Rust and Cargo installed.
# Clone the repository
git clone https://github.com/yourusername/codecontexter.git
cd codecontexter
# Install locally
cargo install --path .Navigate to your project root and run:
codecontexterThis generates a codebase_context.md file in the current directory.
Copy directly to clipboard:
codecontexter --clipboardChange output format (Markdown, JSON, XML):
Note: Use -t for format (type).
codecontexter -t json --output context.jsonExclude specific patterns:
codecontexter --exclude "*.lock" --exclude "tests/*"Point to a specific directory:
codecontexter ./src/my_componentUsage: codecontexter [OPTIONS] [PATH]
Arguments:
[PATH] Root directory to scan [default: .]
Options:
-o, --output <OUTPUT> Output file path [default: codebase_context.md]
-t, --format <FORMAT> Output format [default: markdown] [possible values: markdown, json, xml]
-c, --clipboard Copy result to clipboard
-e, --exclude <EXCLUDE> Exclude file patterns (glob), e.g. --exclude "*.log"
-f, --force Force overwrite of output file if it exists
-v, --verbose Show verbose logging
-h, --help Print help
-V, --version Print version
The generated file looks like this, optimized for LLM prompting:
# π¦ Codebase Context: my-project
> Generated on 2023-10-27 | Files: 12 | Tokens: ~4500
## π² Project Structure
π my-project/
βββ Cargo.toml
βββ src/
β βββ main.rs
β βββ utils.rs
## π File Contents
### `src/main.rs`
_Language: rust | Lines: 150 | Tokens: ~800_
```rust
fn main() {
println!("Hello, world!");
}CodeContexter includes a built-in sanitizer that scans file contents for sensitive patterns before writing to the output. It looks for and redacts:
- RSA/DSA Private Keys
- AWS Access Keys (
AKIA...) - OpenAI/Stripe Keys (
sk-...) - GitHub Personal Access Tokens
- Generic "API Key" / "Secret" string assignments
Note: While this feature catches common secrets, always review your output before sharing it with third-party AI services.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repo
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License.