# tree2md
[](https://crates.io/crates/tree2md)
[](https://opensource.org/licenses/MIT)
**Visualize your codebase structure for humans and AI agents.**
```bash
tree2md # Pretty tree in terminal
```
---
## Output Modes
Output format is auto-detected based on TTY:
| **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
```toml
[package]
name = "example"
```
```
---
## Installation
```bash
cargo install tree2md
```
Or from source:
```bash
git clone https://github.com/zawakin/tree2md
cd tree2md
cargo install --path .
```
---
## CLI Options
### Filtering
| `-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` |
### Contents
| `-c, --contents` | Append file contents as code blocks |
### Statistics
| `--stats {off\|min\|full}` | Statistics display (default: `full`) |
| `--loc {off\|fast\|accurate}` | Line counting mode (default: `fast`) |
### Fun & Style
| `--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
| `--safe` | Apply safety filters (default) |
| `--unsafe` | Disable all safety filters |
---
## Safety Defaults
Excluded by default:
- `.env`, `.ssh/**`, `*.pem`, `*.key`
- `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**
```bash
**Feed codebase to AI agent**
```bash
**Quick project overview**
```bash
tree2md . -L 2 --stats min
```
**Rust files only, 3 levels deep**
```bash
tree2md src/ -L 3 -I "*.rs"
```
---
## Build from Source
```bash
git clone https://github.com/zawakin/tree2md
cd tree2md
cargo build --release
cargo test
```
---
## Contributing
PRs welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).
```bash
mise run verify # fmt + clippy + tests
mise run fix # auto-format + clippy fix
```
---
## License
MIT License โ see [LICENSE](LICENSE).