npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

treeviz-cli

v1.8.1

Published

Generate ASCII directory trees from the terminal

Readme

treeviz-cli

Generate clean, readable directory trees from the terminal — designed to give AI models instant understanding of your project structure.

npm version license

Why treeviz?

AI coding assistants like Claude, ChatGPT, and Copilot are powerful. But they're blind to your project's file structure. Without knowing which files exist and how they're organized, AI models waste tokens asking questions, hallucinate paths, or give advice that doesn't fit your codebase.

treeviz solves this. One command generates a structured snapshot of your project that you can paste into any AI prompt, save to a context file (like CLAUDE.md or AGENTS.md), or pipe into your workflow. The result: AI models understand your project from the first message.

The problem

You: "Add a login page"
AI:  "Sure! Create src/pages/Login.tsx..."
You: "We don't have a pages folder. We use app/ with Next.js App Router."
AI:  "Oh, I see. Let me try again..."

The fix

You: "Here's my project structure:
     [paste treeviz output]
     Add a login page."
AI:  "I can see you're using Next.js App Router. I'll create app/login/page.tsx..."

Installation

# npm
npm install -g treeviz-cli

# yarn
yarn global add treeviz-cli

# pnpm
pnpm add -g treeviz-cli

# bun
bun add -g treeviz-cli

Or run it directly without installing:

npx treeviz-cli
bunx treeviz-cli

Quick Start

# Current directory
treeviz

# Specific path
treeviz ./src

# Limit depth to 2 levels
treeviz --depth 2

# Save to a file
treeviz --output tree.txt

# Copy to clipboard (paste straight into AI chat)
treeviz --copy

Output Formats

ASCII (default)

treeviz
my-app/
├── src/
│   ├── components/
│   │   ├── Button.tsx
│   │   └── Header.tsx
│   ├── app/
│   │   ├── layout.tsx
│   │   └── page.tsx
│   └── utils/
│       └── helpers.ts
├── package.json
├── tsconfig.json
└── README.md

JSON

treeviz --format json
{
  "name": "my-app",
  "type": "directory",
  "children": [
    {
      "name": "src",
      "type": "directory",
      "children": [
        { "name": "components", "type": "directory", "children": [...] },
        { "name": "app", "type": "directory", "children": [...] }
      ]
    },
    { "name": "package.json", "type": "file" }
  ]
}

Markdown

treeviz --format markdown
- my-app/
  - src/
    - components/
      - Button.tsx
      - Header.tsx
    - app/
      - layout.tsx
      - page.tsx
  - package.json
  - README.md

Using treeviz with AI Models

Paste into AI chat

The fastest way — copy the output and paste it at the top of your prompt:

treeviz --copy

Then in your AI chat:

Here's my project structure:

my-app/
├── src/
│   ├── components/
│   ...

[Your question here]

Save to a context file

Many AI tools support project-level context files. Generate a tree and include it:

# For Claude Code
treeviz --output tree.txt
# Then paste into CLAUDE.md under "## Project Structure"

# For Cursor, Windsurf, or any AI editor
treeviz --output tree.txt
# Reference in your .cursorrules, .windsurfrules, or similar

Automate with a pre-commit hook

Keep your context file always up to date:

# In your pre-commit hook or CI step
treeviz --output tree.txt

Pipe into other tools

# Feed into clipboard for quick paste
treeviz | pbcopy

# Append to an existing context file
treeviz >> CLAUDE.md

# Save JSON for programmatic use
treeviz --format json --output structure.json

Commands

| Command | Description | | -------- | ---------------------------------------- | | update | Update treeviz-cli to the latest version |

treeviz update

Options

| Option | Alias | Description | | ---------------------- | ----- | ---------------------------------------------------- | | [path] | | Directory to visualize (default: .) | | --format <type> | -f | Output format: ascii (default), json, markdown | | --depth <n> | -d | Limit directory traversal depth | | --ignore <folders> | -i | Comma-separated folders to add to the ignore list | | --no-default-ignores | | Disable the default ignore list | | --follow-symlinks | | Follow symbolic links (skipped by default) | | --output <file> | -o | Write output to a file | | --copy | -c | Copy output to clipboard | | --help | -h | Show help | | --version | -v | Show version |

Default Ignores

treeviz automatically skips common noise directories so your tree stays clean and relevant:

node_modules, .claude, .git, .next, .husky, .turbo, dist, build, .DS_Store

You can add more with --ignore or disable defaults entirely with --no-default-ignores.

Security

treeviz is designed to be safe by default:

  • Symlinks are skipped — prevents traversal outside the project directory. Opt in with --follow-symlinks.
  • Cycle detection — when following symlinks, circular references are detected and skipped to prevent infinite loops.
  • Path traversal protection — resolved paths that escape the working directory are rejected.
  • Entry limit — trees are capped at 10,000 entries to prevent resource exhaustion on massive directories.

Platform Support

  • macOS — clipboard via pbcopy
  • Linux — clipboard via xclip (install with sudo apt install xclip)
  • Windows — works for tree generation; clipboard support coming soon

Contributing

Contributions are welcome! The project uses:

  • Bun as the runtime and test runner
  • TypeScript with strict mode
  • ESLint + Prettier for code quality
  • Husky + lint-staged for pre-commit hooks
# Clone the repo
git clone https://github.com/bireycikan/treeviz-cli.git
cd treeviz-cli

# Install dependencies
bun install

# Run locally
bun run dev

# Run tests
bun test

# Build
bun run build

License

MIT