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.
Features
- 📊 Visualize token distribution across your project
- 🚀 Fast, asynchronous scanning with caching
- 🔍 Respects
.gitignorerules - ⏩ Skips binary files automatically
- 🧩 Uses OpenAI's
tiktokenfor 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
tiktokenlibrary for accurate token counting - Tokenizers can be specified with either
--encodingor--modelflags - Defaults to
o200k_baseencoding orgpt-4omodel 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac4988bfddc03ca0a6d3634bc5c4ed0647983590be91a4d7ebdbefc5593eec54
|
|
| MD5 |
52fbadabb02a56b16b4b7d4b6aad500a
|
|
| BLAKE2b-256 |
1b14c40d2fb40617e93af5c5602ed4270aac031f8e1cb747871f737a7aa9d29b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6309b41c2021016932732bb386810338872f768ae573def6c3444ee36aded1a0
|
|
| MD5 |
7223fa5bd6c0840c41faa27ea3113faa
|
|
| BLAKE2b-256 |
2be2cc3c8bd0028635d69a27a31755ee01f86c92d121908cb852e7d26205b304
|