Collect and bundle source code for LLM input
Project description
sourcerat
sourcerat collects, filters, and orders source code from a project so it can be used as high-quality context for LLMs.
The goal is not archiving, but signal over noise.
Project Vision
LLMs perform poorly on raw project dumps.
Too many files, wrong ordering, irrelevant clutter.
sourcerat addresses this structurally:
- identify relevant files
- prioritize entry points
- expose project structure
- keep output deterministic and reproducible
- no magic, everything explainable
Built for developers who want explicit control over what a model sees.
Installation
pip install sourcerat
or locally in a project:
pip install -e .
Usage
Basic form:
sourcerat [PATH]
By default, the current directory is scanned.
Example:
sourcerat .
Output:
- PROJECT TREE
- followed by the contents of selected files
- ordered by heuristic relevance
Common Workflows
Dry Run
Show which files would be included:
sourcerat . --dry-run
Write Output to File
sourcerat . -o context.txt
Markdown for ChatGPT / GitHub
sourcerat . --format markdown -o context.md
Restrict File Types
sourcerat . --file-suffixes py,rs
Explicitly Include Directories
sourcerat . --include src
Exclude Directories
sourcerat . --exclude tests,examples
Size and Count Limits
sourcerat . --max-files 20 --max-lines 400
Smart Sorting
By default, sourcerat tries to surface important files first.
Heuristics include:
- common entry points (
main.py,__main__.py,cli.py) - shallow directory depth
- detection of
main()functions - CLI indicators such as
argparse,click,typer - de-prioritization of
tests,examples,demo
Disable:
sourcerat . --no-smart-sort
Gitignore Support
sourcerat . --respect-gitignore
- reads
.gitignorefrom project root - simple, transparent pattern matching
- intentionally not a full Git implementation
Output Formats
Plain (default)
PROJECT TREE
├── src
│ └── app.py
FILE: src/app.py
<content>
Markdown
## src/app.py
```python
<content>
Designed for direct LLM consumption.
## Design Principles
- no dependencies
- no hidden defaults
- everything is text
- heuristic correctness over completeness
- errors are visible, not hidden
## Non-Goals
- not a documentation generator
- not a full parser
- no AST or semantic analysis
- not a project management tool
## Intended Audience
- developers using LLMs deliberately
- code-centric prompt engineering
- analyzing unfamiliar codebases
- fast project onboarding
## Status
Early version, intentionally small.
Heuristics are extensible but conservative by design.
Pull requests welcome if they respect the vision.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sourcerat-0.1.3.tar.gz.
File metadata
- Download URL: sourcerat-0.1.3.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29ef45d71a21fe46a45bdb7c5894ae1be06d4218cbe44af65e5ba1c7a35024c7
|
|
| MD5 |
e0111fa5f8680ace6c339d44ad536309
|
|
| BLAKE2b-256 |
3f4bb94f38dc7ff501b9d589015dc98d21f24426e225e04a9513d7f6916f3ff9
|
File details
Details for the file sourcerat-0.1.3-py3-none-any.whl.
File metadata
- Download URL: sourcerat-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
504c34b395fe1c2abcf2e3ef0468da09b02570e37b5cc2bfae9043e5d8fed1c8
|
|
| MD5 |
8ebc64a939dfc4ac1cdee7bfe3802224
|
|
| BLAKE2b-256 |
b6b1075e66d512c993f171d577627fd3b5b6f4d42d91ec535af8fef0b945b990
|