Skip to main content

Estimate tokens for Gemini and display tree from local/git sources.

Project description

Gemini Tree Token Counter (gtc)

🇯🇵 日本語 (Japanese)

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 git command 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?

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

gemini_tree_token_counter-0.1.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

gemini_tree_token_counter-0.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gemini_tree_token_counter-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 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

Hashes for gemini_tree_token_counter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1093ad8699be7d97f5d2572f22aaf1e692592372199c4fea25202ddd55d9b1da
MD5 da1fce472968181aae924b278571becd
BLAKE2b-256 725027d1d8e462a6807b142b6c1fa39fe6a7cc61daa302360afe55c0e6b59072

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gemini_tree_token_counter-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.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

Hashes for gemini_tree_token_counter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07a03a2c7c2755ea098108419ed637bf5d267e4c374607945ebf44efb1a5c62e
MD5 d702d5192ed82cd7151986112ea71e9e
BLAKE2b-256 0313b1955e4874d5c1491c62f210954adfe55940313d11fd0ed97ef811603093

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