tree2md 0.9.1

Like the tree command, but outputs in Markdown. Optimized for AI agents.
tree2md-0.9.1 is not a library.

tree2md

Crates.io License: MIT

Visualize your codebase structure for humans and AI agents.

tree2md                        # Pretty tree in terminal
tree2md | pbcopy               # Pipe-friendly tree for clipboard
tree2md -c -I "*.rs" -L 2     # Tree + file contents for AI context

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

[package]
name = "example"

---

## Installation

```bash
cargo install tree2md

Or from source:

git clone https://github.com/zawakin/tree2md
cd tree2md
cargo install --path .

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

Contents

Flag Description
-c, --contents Append file contents as code blocks

Statistics

Flag Description
--stats {off|min|full} Statistics display (default: full)
--loc {off|fast|accurate} Line counting mode (default: fast)

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

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

tree2md . -L 3 | pbcopy

Feed codebase to AI agent

tree2md . -c -I "*.rs" -I "*.toml" | pbcopy

Quick project overview

tree2md . -L 2 --stats min

Rust files only, 3 levels deep

tree2md src/ -L 3 -I "*.rs"

Build from Source

git clone https://github.com/zawakin/tree2md
cd tree2md
cargo build --release
cargo test

Contributing

PRs welcome! See CONTRIBUTING.md.

mise run verify   # fmt + clippy + tests
mise run fix      # auto-format + clippy fix

License

MIT License โ€” see LICENSE.