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.2.tar.gz (7.0 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.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tokdu-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 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.2.tar.gz
Algorithm Hash digest
SHA256 ac4988bfddc03ca0a6d3634bc5c4ed0647983590be91a4d7ebdbefc5593eec54
MD5 52fbadabb02a56b16b4b7d4b6aad500a
BLAKE2b-256 1b14c40d2fb40617e93af5c5602ed4270aac031f8e1cb747871f737a7aa9d29b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tokdu-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6309b41c2021016932732bb386810338872f768ae573def6c3444ee36aded1a0
MD5 7223fa5bd6c0840c41faa27ea3113faa
BLAKE2b-256 2be2cc3c8bd0028635d69a27a31755ee01f86c92d121908cb852e7d26205b304

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