Note: This article was translated with the assistance of AI. I wrote the original in Chinese. If you can read Chinese, you are welcome to read the original Chinese version for the most authentic and unfiltered expression.

🌳 Treex - Advanced Command-line Directory Tree Visualization Tool

Today I’d like to recommend a small tool I recently developed for developers — Treex.

🤔 Why do you need this tool?

During development and learning, you may have encountered scenarios like:

  • For an unfamiliar project, looking at the complex project structure, not knowing where to start
  • Wanting to quickly show a large model your project structure so it can help you understand
  • Needing to insert a visual directory structure when writing project documentation

The traditional tree command works, but its features are too basic. While using it, I often found that it would draw out files I didn’t need (for example, node_modules in Node projects), resulting in too much unnecessary information and making things look messier.

So I used Cursor and developed Treex in Go. It’s a directory tree tool that supports multiple output formats and filtering.

Project URL: https://github.com/shiquda/treex

✨ Core Features at a Glance

🎨 Multiple Output Formats

  • 🌲 Tree format (default): classic command-line tree structure
  • 📑 Indent format: clean hierarchical indentation
  • 📝 Markdown format: paste directly into documents
  • 📊 Mermaid format: generate embeddable flowcharts

🔍 Smart Filtering

  • 🕵️ Hide hidden files like .git
  • 📁 Show only directory structure
  • 🚫 Exclude specified directories/file types

🛠️ Highly Customizable

  • 📏 Control directory depth
  • 💾 Output to file
  • 🎯 Custom display formats

🚀 Quick Start

Download

Method 1: Download precompiled binaries

Download from the Release page, then add to PATH

Method 2: Install with Go

If you have a Go environment, you can install with one command:

1
go install github.com/shiquda/treex@latest

Basic Usage

1
2
3
4
5
6
7
8
# View current directory structure
treex

# View specified directory
treex -d /path/to/project

# View help information
treex -h

Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
└── .
├── .git
│ ├── HEAD
│ ├── config
│ ├── description
│ ├── hooks
│ │ ├── applypatch-msg.sample
│ │ ├── commit-msg.sample
│ │ ├── fsmonitor-watchman.sample
│ │ ├── post-update.sample
│ │ ├── pre-applypatch.sample
│ │ ├── pre-commit.sample
│ │ ├── pre-merge-commit.sample
│ │ ├── pre-push.sample
│ │ ├── pre-rebase.sample
│ │ ├── pre-receive.sample
│ │ ├── prepare-commit-msg.sample
│ │ ├── push-to-checkout.sample
│ │ ├── sendemail-validate.sample
│ │ └── update.sample
│ ├── info
│ │ └── exclude
│ ├── objects
│ │ ├── info
│ │ └── pack
│ └── refs
│ ├── heads
│ └── tags
├── .gitignore
├── 1.go
├── 2.go
├── README.md
├── build
│ └── win
│ └── output.exe
└── test
├── 3.go
└── README_test.md

⚡ Advanced Usage Examples

1. Generate project documentation

1
2
# Exclude hidden files, output Markdown format to specified file
treex -H -f md -o PROJECT_STRUCTURE.md
  • ./
    • 1.go
    • 2.go
    • README.md
    • build/
      • win/
        • output.exe
    • test/
      • 3.go
      • README_test.md

2. Tech talk illustrations

1
2
# Keep only non-hidden directories, generate Mermaid code
treex -HD -f mermaid
1
2
3
4
5
6
7
8
graph TD
N1[./]
N2[build/]
N1 --> N2
N3[win/]
N2 --> N3
N4[test/]
N1 --> N4

mermaid-2025411 002546

3. Exclude specific files

1
2
# Exclude unimportant directories and file types
treex -e ".git/, .md"
1
2
3
4
5
6
7
8
9
└── .
├── .gitignore
├── 1.go
├── 2.go
├── build
│ └── win
│ └── output.exe
└── test
└── 3.go

🛠️ Full Parameter Reference

You can check https://github.com/shiquda/treex for details.

Parameter Description
-d Directory to scan (default: current directory)
-f Output format (tree/indent/md/mermaid)
-m Maximum directory depth (0 means unlimited)
-o Output file path
-e Exclusion rules (comma-separated)
-H Hide hidden files
-D Show directories only

💖 Looking Forward to Your Participation

Treex is still in early development. I don’t have much development experience, and limited by my personal skill level, the tool inevitably has shortcomings. If you:

  • Found a bug
  • Have feature suggestions
  • Want to contribute code

Feel free to submit an Issue or PR on GitHub! Of course, a ⭐ star of encouragement would also be great~

Project URL: https://github.com/shiquda/treex