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

@daisukeueta/ttree

v0.1.1

Published

Tree-format directory structure display with token counting

Readme

ttree

A command-line tool that displays directory structures in tree format with token counting and AI cost estimation for each file and directory. Perfect for analyzing codebases, understanding token usage, and estimating AI API costs before sending code to language models.

Features

  • 🌳 Tree Structure Display: Visualize directory hierarchy in a clean tree format
  • 🔢 Token Counting: Calculate and display token counts for individual files and directories
  • 💰 AI Cost Estimation: Always-on cost estimates for popular AI models (Claude, GPT, Gemini)
  • 🎨 Color-coded Output: Different colors for files, directories, and token counts based on size
  • 🚫 Smart Filtering: Automatic .gitignore support plus custom ignore patterns
  • 📊 Multiple Output Formats: Human-readable tree view or JSON output
  • Performance Optimized: Efficient traversal with configurable depth limits
  • 🔧 Flexible Options: Sort by name, size, or tokens with threshold filtering

Installation

From Source

npx ttree

Or install globally:

npm install -g ttree

Usage

Basic Usage

# Analyze current directory
ttree

# Analyze specific directory
ttree src/

Examples

Basic Examples

# Show current directory with default settings and cost estimates
ttree

# Analyze src directory with depth limit
ttree src/ -d 2

# Show only directories (no individual files)
ttree --no-files

# Sort by token count (descending)
ttree -s tokens

# Use GPT-3.5/GPT-4 tokenizer instead of default GPT-4o
ttree -e cl100k_base

Sample Output

Tree Format (Default)

src/
├── cli.ts (501 tokens)
├── constants.ts (404 tokens)
├── cost-calculator.ts (528 tokens)
├── cost-formatter.ts (918 tokens)
├── file-traverser.ts (587 tokens)
├── formatters.ts (477 tokens)
├── gitignore-parser.ts (726 tokens)
├── index.ts (494 tokens)
├── pricing-data.ts (582 tokens)
├── token-counter.ts (683 tokens)
├── tree-builder.ts (1.0k tokens)
├── tree-renderer.ts (800 tokens)
├── types.ts (369 tokens)
└── utils.ts (634 tokens)

Total: 8,743 tokens
Files: 14, Directories: 1

💰 Cost Estimates (Input + Output @ 0.5x ratio):
┌─────────────────┬─────────┬─────────┬───────────┐
│ Model           │ Input   │ Output  │ Total     │
├─────────────────┼─────────┼─────────┼───────────┤
│ Claude Sonnet 4 │  $0.026 │  $0.065 │    $0.092 │
│ Claude Opus 4.1 │  $0.131 │  $0.327 │    $0.458 │
└─────────────────┴─────────┴─────────┴───────────┘

Configuration

.gitignore Support

ttree automatically respects .gitignore files in the target directory. Common patterns like node_modules/, dist/, and *.log are automatically excluded.

Default Ignore Patterns

The following patterns are ignored by default:

  • node_modules/**
  • .git/**
  • dist/**
  • build/**
  • .next/**
  • .vscode/**
  • .idea/**
  • *.log
  • .DS_Store
  • Thumbs.db

File Type Detection

  • Text files: Analyzed for token counting
  • Binary files: Counted as 0 tokens
  • Large files: Files over 50MB are skipped for performance

Color Coding

  • 🔵 Blue: Directory names
  • 🟢 Green: Low token count (< 100)
  • 🟡 Yellow: Medium token count (100-999)
  • 🔴 Red: High token count (≥ 1000)
  • 🔘 Gray: Zero tokens or tree structure

License

MIT License - see LICENSE file for details

Acknowledgments

  • Built with tiktoken for accurate token counting
  • Inspired by the classic tree command with modern AI workflow needs
  • Uses commander.js for CLI interface