sourcecrumb
Tree-sitter repository map in TOON format for LLM consumption.
What it does
sourcecrumb parses a codebase with tree-sitter, extracts symbols (classes, functions, methods, imports), builds a file-to-file dependency graph, and ranks files by PageRank. The output is a compact TOON-formatted map designed to fit in an LLM context window.
The goal: give an LLM agent a high-level map of a codebase so it can explore more effectively — knowing which files matter most, what symbols they define, and how they depend on each other.
Installation
Requires Python >= 3.13.
From PyPI
pip install sourcecrumb
Or with uv:
uv pip install sourcecrumb
Run without installing
uvx sourcecrumb .
From source
git clone https://github.com/phobologic/sourcecrumb.git
cd sourcecrumb
uv sync
Usage
sourcecrumb [ROOT] [OPTIONS]
| Option | Description |
|---|---|
ROOT |
Repository root directory (default: .) |
--max-files, -n |
Limit output to top N files by PageRank (min: 1) |
--language, -l |
Restrict to a specific language (e.g., python) |
--cache |
Cache file path; reuses if newer than all source files |
--max-file-size |
Skip files larger than this many bytes (default: 1MB) |
Example
$ sourcecrumb . -n 3
repo: sourcecrumb
root: sourcecrumb
files[3]{path,language,rank}:
sourcecrumb/models.py,python,0.2615
sourcecrumb/languages.py,python,0.1155
sourcecrumb/discovery.py,python,0.0590
symbols[17]{file,name,kind,line,signature}:
sourcecrumb/models.py,TagKind,class,10,TagKind(enum.Enum)
sourcecrumb/models.py,SymbolKind,class,17,SymbolKind(enum.Enum)
sourcecrumb/models.py,Tag,class,27,Tag
sourcecrumb/models.py,FileInfo,class,39,FileInfo
...
dependencies[1]{source,target,symbols}:
sourcecrumb/discovery.py,sourcecrumb/languages.py,language_for_extension
Claude Code integration
The primary use case is running sourcecrumb as a Claude Code hook so every subagent automatically gets a repo map injected into its context.
Add this to .claude/settings.json:
{
"hooks": {
"SubagentStart": [
{
"hooks": [
{
"type": "command",
"command": "uvx sourcecrumb \"$CLAUDE_PROJECT_DIR\" --cache \"$CLAUDE_PROJECT_DIR/.cache/sourcecrumb.toon\""
}
]
}
]
}
}
If you have sourcecrumb installed globally, you can use sourcecrumb directly instead of going through uvx.
The SubagentStart hook fires when any subagent launches. sourcecrumb's stdout is injected into the subagent's context, giving it an instant overview of the codebase.
--cache avoids re-parsing on every agent launch — the cache file is reused as long as no source files have changed. Add .cache/ to your .gitignore.
TOON format
The output uses TOON (Text Object Oriented Notation), a compact format designed for LLM consumption:
- Scalar fields —
key: value - Tabular arrays —
name[count]{col1,col2,...}:followed by indented CSV rows - Quoting — values containing special characters are double-quoted; numbers and plain strings are bare
How it works
- Discover files — uses
git ls-fileswhen available, falls back to.gitignore-based filtering - Parse with tree-sitter — extracts classes, functions, methods, and imports from each file
- Build dependency graph — creates file-to-file edges based on shared symbols (imports that resolve to definitions in other files)
- Rank with PageRank — scores files by importance in the dependency graph
- Select top N — when
--max-filesis set, keeps only the highest-ranked files - Encode to TOON — serializes the repo map into the compact output format
Supported languages
Python. Extensible by adding a .scm query file to sourcecrumb/queries/ and registering the language in sourcecrumb/languages.py.
Development
uv run pytest # run tests
uv run ruff check sourcecrumb/ tests/ # lint
uv run ruff format sourcecrumb/ tests/ # format
Metadata
Release files for sourcecrumb 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sourcecrumb-0.2.3.tar.gz | 261.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sourcecrumb-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 275.7 kB
Release files / sourcecrumb-0.2.3.tar.gz
| Download URL | sourcecrumb-0.2.3.tar.gz |
|---|---|
| Size | 261.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef8f8c90832d7b44d83b469a8141b47d4500d261ff286de2ec5990103d93f933
|
|
BLAKE2b-256 checksum How to use checksums |
d35907df97e1bbc93ed5c75afa1200bc02e6a4438d1bffcecaee2752e03a0f13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / sourcecrumb-0.2.3-py3-none-any.whl
| Download URL | sourcecrumb-0.2.3-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04ed5c5934b28803cfcd923b417a6db2ca858f6cace0a3837f5eb1bf962f5e1d
|
|
BLAKE2b-256 checksum How to use checksums |
2523e4c6b98da2f47170f91bbc52bd15cf3b0de76fd69c6118ae22b4a59c91d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|