Estimate tokens for Gemini and display tree from local/git sources.
Project description
Gemini Tree Token Counter (gtc)
A CLI tool to estimate tokens for Gemini models across local directories and GitHub repositories. It visualizes the file tree with token counts and supports "Time Travel" (analyzing specific Git commits/dates).
Note: The token counting logic is based on regex approximations (ported from
smartprocure/gemini-token-estimator) and is designed for speed. It is accurate within ~10% for most cases.
Features
- 🚀 Fast Estimation: Uses regex-based logic (no API calls required).
- 🌳 Tree Visualization: Displays directory structure with token counts per node.
- 🐙 GitHub Support: Analyze remote repositories directly.
- ⏳ Time Travel: Check token counts for a specific branch, commit hash, or date (e.g., "how many tokens was this repo in 2023?").
- 📄 Content Inspection: Optionally output file contents for context generation.
Installation
Prerequisites
- Python 3.7+
- Git (The
gitcommand must be available in your system path)
Install via pip
pip install gemini-tree-token-counter
Usage
Basic usage scans the current directory:
gtc
Options
target: Local path or GitHub URL (default: current directory).-d,--dir: Target specific subdirectories (can be used multiple times).-c,--content: Display file contents (useful for piping to LLMs).-b,--branch: Checkout a specific Git branch.--commit: Checkout a specific Git commit hash.--date: Checkout the latest commit before a specific date (format: YYYY-MM-DD).--first: Checkout the first (initial) commit of the repo.
Examples
# 1. Local Directory
gtc # Scan current directory
gtc . -d src -d lib # Scan specific dirs
gtc . -c > context.txt # Dump all code and tokens to a file
# 2. GitHub Repository
gtc https://github.com/user/repo
gtc https://github.com/user/repo -b develop
# 3. Time Travel (Git History)
gtc . --date 2023-01-01 # How big was this project last year?
gtc . --first # How small was the first commit?
Output Example (ver 0.1.2)
$ gtc
Source : .
Working Path : /Users/sakasegawa/src/github.com/nyosegawa/gemini-tree-token-counter
------------------------------------------------------------
├── src/ (4679 tokens)
│ └── gemini_tree_token_counter/ (4679 tokens)
│ ├── __init__.py (11 tokens)
│ └── main.py (4668 tokens)
├── tests/ (2596 tokens)
│ ├── __init__.py (0 tokens)
│ └── test_tokenizer.py (2596 tokens)
├── .gitignore (682 tokens)
├── LICENSE (0 tokens)
├── pyproject.toml (249 tokens)
├── README.md (1130 tokens)
└── README_ja.md (594 tokens)
------------------------------------------------------------
Grand Total Tokens: 9930
------------------------------------------------------------
License & Acknowledgments
This project is licensed under the MIT License.
However, the tokenizer regex logic is a port of gemini-token-estimator by GovSpend, which is licensed under the ISC License.
Tokenizer Logic Copyright
Copyright (c) GovSpend
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
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 gemini_tree_token_counter-0.1.3.tar.gz.
File metadata
- Download URL: gemini_tree_token_counter-0.1.3.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
727c6fa3308f5ed7dff224f189deedf0f6374af23518944c2753c50ae0d077a3
|
|
| MD5 |
bb45d8fb6b63bd8de692de6c20a0447e
|
|
| BLAKE2b-256 |
6975eb68322767231b8f043519e394d9bba72d8f12a8505c601e0929a8ed16dd
|
File details
Details for the file gemini_tree_token_counter-0.1.3-py3-none-any.whl.
File metadata
- Download URL: gemini_tree_token_counter-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56d54902027196879a53075abfc9bf7224a46b1e31b70e8b31765b254fa75a35
|
|
| MD5 |
4260706234a9dcb7c7218a702f9fc5ef
|
|
| BLAKE2b-256 |
3658de906bc15f8f3c0017483bb5aaa14236297039c1da39fbab9cebaea76c83
|