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.1.tar.gz (6.4 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.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tokdu-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 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.1.tar.gz
Algorithm Hash digest
SHA256 fa4b4374df498d423357be4787fc3b4c0fbc49d8ead3effd815f7a0535293b6c
MD5 f0e7e5ed67701774b0bb5e2610fd9a83
BLAKE2b-256 8525136259d63424ad25753c88371e0a755a8324f9022d569dd368d7880c435b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokdu-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df2dc8514b4e01e450e556a4cb7d53e09130665e51fcdf9fdc03ffb75dc50489
MD5 dd1f0b1012ecf5c6500816b3858c5b04
BLAKE2b-256 a13378a53893c56dab437a25b2899924839440e3639473bff703d587ed0a40bd

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