Skip to main content

A token counting TUI tool that respects .gitignore and skips binary files

Project description

tokdu - Token Disk Usage Analyzer for LLMs

tokdu (Token Disk Usage) is a terminal-based utility that helps you analyze and visualize token usage in your codebase. Similar to the classic du (disk usage) command, tokdu shows you how many tokens your files and directories consume, which is essential when working with Large Language Models (LLMs) that have token limits.

tokdu demonstration

Features

  • 📊 Visualize token distribution across your project
  • 🚀 Fast, asynchronous scanning with caching
  • 🔍 Respects .gitignore rules
  • ⏩ Skips binary files automatically
  • 🧩 Uses OpenAI's tiktoken for accurate token counting
  • 🎛️ Support for different models' tokenizers

Installation

pip install tokdu

Or install from source:

git clone https://github.com/unitythemaker/tokdu.git
cd tokdu
pip install .

Usage

Basic usage:

tokdu

This will start tokdu in the current directory.

Specify a starting directory:

tokdu /path/to/project

Use a specific tokenizer encoding:

tokdu --encoding cl100k_base

Use tokenization based on a specific model:

tokdu --model gpt-4o

Navigation Controls

  • ↑/↓ or j/k: Navigate up/down
  • Enter: Open selected directory
  • Backspace: Go to parent directory
  • Page Up/Down: Scroll by page
  • q: Quit

Why Count Tokens?

Large Language Models like GPT-4o have context window limits measured in tokens. When embedding code in prompts or using tools and IDEs like GitHub Copilot or Zed, understanding your project's token usage helps you:

  • Stay within context window limits
  • Optimize prompts for LLMs
  • Identify areas to trim when sharing code with AI assistants

Technical Details

  • Uses OpenAI's tiktoken library for accurate token counting
  • Tokenizers can be specified with either --encoding or --model flags
  • Defaults to o200k_base encoding or gpt-4o model when not specified
  • Scans directories asynchronously for better performance
  • Caches results to avoid repeated scans

Requirements

  • Python 3
  • tiktoken
  • pathspec
  • curses (built into Python standard library)

License

MIT

Author

Halil Tezcan KARABULUT (@unitythemaker)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokdu-0.1.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokdu-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file tokdu-0.1.3.tar.gz.

File metadata

  • Download URL: tokdu-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tokdu-0.1.3.tar.gz
Algorithm Hash digest
SHA256 62738dcb62dedb221aea91987a5eaea171ffbe5f2c334ecf953d4d336b1e8d2e
MD5 2f6f4f48d44a20f62da6e4bbcedb6698
BLAKE2b-256 718265347f917a5632febdbd7b0c9248a6f7ed857fe167976898948b6543c0ca

See more details on using hashes here.

File details

Details for the file tokdu-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tokdu-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tokdu-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab51d0caff2c02ba5ae77205d39c60d03004b5bbf2cab20a801a81454eb307d3
MD5 a7aa54f35c3191ed5429e60cf3dd2779
BLAKE2b-256 761acc63b5ce6223427f11e75b6024462a7ae54ba77d7b7ba25eaa072635ae21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page