tree2md
Visualize your codebase structure for humans and AI agents.
|
Output Modes
Output format is auto-detected based on TTY:
| Mode | When | What |
|---|---|---|
| TTY | Terminal | Emoji, LOC bars, stats, tree characters |
| Pipe | | pbcopy, redirect, etc. |
Plain tree + (N lines) |
Pipe + -c |
AI context | Tree + code-fenced file contents |
TTY (terminal)
โโโ ๐ src/
โ โโโ ๐ฆ cli.rs [โโโโโโโโโโ] 156 (M)
โ โโโ ๐ฆ main.rs [โโโโยทยทยทยทยทยท] 65 (S)
โ โโโ ๐ render/
โ โโโ ๐ฆ pipe.rs [โโโโโโโโโยท] 148 (M)
โ โโโ ๐ฆ terminal.rs [โโโโโโโโโโ] 247 (M) โ
โโโ Cargo.toml [โยทยทยทยทยทยทยทยทยท] 36 (S)
**Totals**: ๐ 3 dirs โข ๐ 5 files โข ๐งพ ~652 LOC
Pipe
.
โโโ src/
โ โโโ cli.rs (156 lines)
โ โโโ main.rs (65 lines)
โ โโโ render/
โ โโโ pipe.rs (148 lines)
โ โโโ terminal.rs (247 lines)
โโโ Cargo.toml (36 lines)
Pipe + -c (AI context)
.
โโโ src/
โ โโโ main.rs (65 lines)
โโโ Cargo.toml (36 lines)
## src/main.rs
```rust
fn main() {
println!("Hello, world!");
}
Cargo.toml
[]
= "example"
---
## Installation
```bash
cargo install tree2md
Or from source:
Prebuilt binaries are on GitHub Releases. From v0.12.1 on, each archive has a signed build provenance attestation. Verify a download before running it:
This checks that the file was built by this repository's release workflow from the tagged commit. A replaced archive fails, even if its .sha256 was replaced too.
CLI Options
Filtering
| Flag | Description |
|---|---|
-L, --level <N> |
Limit traversal depth |
-I, --include <GLOB> |
Include patterns (repeatable) |
-X, --exclude <GLOB> |
Exclude patterns (repeatable) |
--use-gitignore {auto|never|always} |
Respect .gitignore |
-l, --follow-links |
Follow symbolic links (default: symlinks are skipped) |
--paths-from <FILE> |
Include only the paths listed in FILE, one per line (- = stdin). Literal paths, no globs; a listed directory includes its contents |
--files0-from <FILE> |
Same as --paths-from, NUL-separated (find -print0, git ls-files -z, fd -0) |
-I/-X can be combined with a path list to refine it โ rules are applied on top with the usual last-match-wins order (--paths-from list -X build prunes build/ inside listed directories).
Contents
| Flag | Description |
|---|---|
-c, --contents |
Append file contents as code blocks |
--max-chars <N> |
Limit total content to N characters (requires -c) |
--contents-mode {head|nest} |
Truncation strategy (default: head) |
Statistics
| Flag | Description |
|---|---|
--stats {off|min|full} |
Statistics display (default: full) |
--loc {off|fast|accurate} |
Line counting mode (default: fast) |
Hot spots
| Flag | Description |
|---|---|
--hot |
Mark the files that changed most often in git history |
--hot-since <SPAN> |
History window: 30d, 12w, 6m, 1y (default: 90d). Implies --hot |
--hot-top <N> |
Show only the N hottest files and their directories. Implies --hot |
--sort {name|hot} |
Order within each directory; hot puts the most changed first. Implies --hot |
--hot-metric <METRIC> |
What makes a file hot: commits (default), recency, churn, risk. Implies --hot |
See Hot spots below.
Fun & Style
| Flag | Description |
|---|---|
--fun {auto|on|off} |
Emojis and animations (default: auto) |
--emoji <MAPPING> |
Custom emoji (e.g., --emoji ".rs=๐") |
--emoji-map <FILE> |
Load emoji mappings from TOML file |
--no-anim |
Disable animations |
Safety
| Flag | Description |
|---|---|
--safe |
Apply safety filters (default) |
--unsafe |
Disable all safety filters |
Hot spots
--hot reads the target's git history and shows where the code is being edited:
Each changed file and directory gets its commit count, and a ranked list follows the stats:
โโโ fs_tree/ (9 commits/1y)
โโโ cli.rs (478 lines, 10 commits/1y)
โโโ main.rs (195 lines, 4 commits/1y)
**Hot spots** (commits in the last 1y):
1. cli.rs: 10 commits, 1 author, +280/-305, today
2. fs_tree/build.rs: 8 commits, 2 authors, +233/-130, 1mo ago
A directory's count is the number of commits that touched anything beneath it, so with -L the directories at the depth limit still show how busy their hidden contents are, and the ranking still lists files below the limit. In the terminal the ten hottest files and directories are marked with ๐ฅ and their commit count.
Narrow it down or reorder it:
With -c --max-chars, the budget favors what is being edited: in the default head mode a file keeps 1 + log2(1 + commits) times the lines an unchanged file keeps (1 commit โ 2ร, 3 โ 3ร, 7 โ 4ร). Combine with --sort hot to also put the hottest files first.
--hot-metric decides what "hot" means for the ranking, the ๐ฅ marks, --hot-top and --sort hot:
| Metric | Ranks by |
|---|---|
commits |
Number of commits (default) |
recency |
Commits weighted by age: a commit's weight halves every 30 days |
churn |
Lines added + deleted |
risk |
Lines changed ร file size: big files that keep changing, the usual refactoring candidates (directories rank by churn) |
- Only files the filters show are counted and ranked:
-I/-X,--paths-from, gitignore and the safety filter apply as usual, so an excluded secret file never appears however often it changed. - Lockfiles (
Cargo.lock,package-lock.json,go.sum, โฆ) and changelogs are left out: they change with every dependency bump or release. - Commits that touch more than 50 files (mass reformatting, renames, vendoring) are skipped and the count of skipped commits is shown in the header.
- History follows renames: commits made under a file's old name count toward its current name. Merge commits are not counted.
- Authors are counted by email (respecting
.mailmap); emails are never printed. - Outside a git repository
--hotprints a warning and the tree is shown without it. In a shallow clone only the fetched history is counted.
Safety Defaults
Excluded by default (at any depth):
.env,.env.*,.envrc,.ssh/**,*.pem,*.key,credentials,secrets- Tokens and passwords:
.npmrc,.pypirc,.netrc,.git-credentials,.docker/config.json,.kube/config,*.tfstate,.pgpass,.my.cnf,*.ppk,.gnupg/** - PHP / web hosting: Composer
auth.json,wp-config.php,.htpasswd node_modules/,target/,dist/,build/.git/**,.DS_Store,Thumbs.db
Use -I to selectively include, or --unsafe to disable filters.
Use Cases
Copy structure to clipboard
|
Feed codebase to AI agent
|
Fit contents within token budget
|
Find where the code is being edited
Quick project overview
Rust files only, 3 levels deep
Select directories by a condition tree2md can't express โ compute the path set with your favourite tool and pipe it in:
# only projects whose project.json says "active"
for; do
&&
done |
# tracked files only
|
# files changed on this branch, with contents, for a review prompt
| |
Build from Source
Contributing
PRs welcome! See CONTRIBUTING.md.
License
MIT License โ see LICENSE.