<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: CharlonTank</title>
    <description>The latest articles on Forem by CharlonTank (@charlontank).</description>
    <link>https://forem.com/charlontank</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2236862%2F18483b51-e499-4137-bbe4-2cae4f982a0b.jpeg</url>
      <title>Forem: CharlonTank</title>
      <link>https://forem.com/charlontank</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/charlontank"/>
    <language>en</language>
    <item>
      <title>tokencount: Fast GPT token counting CLI</title>
      <dc:creator>CharlonTank</dc:creator>
      <pubDate>Tue, 16 Sep 2025 19:55:31 +0000</pubDate>
      <link>https://forem.com/charlontank/tokencount-fast-gpt-token-counting-cli-3n85</link>
      <guid>https://forem.com/charlontank/tokencount-fast-gpt-token-counting-cli-3n85</guid>
      <description>&lt;p&gt;tokencount is a new Rust CLI that helps you answer a deceptively simple question: &lt;em&gt;how many GPT tokens are hidden across this project?&lt;/em&gt; If you build AI features, write prompt-heavy docs, or just keep an eye on context windows, this tool makes the audit painless.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I built it
&lt;/h2&gt;

&lt;p&gt;Most token counters either run one file at a time or ignore the filesystem realities of big projects. I wanted something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Walks a codebase quickly (parallel rayon workers + OS-native ignore rules)&lt;/li&gt;
&lt;li&gt;Respects &lt;code&gt;.gitignore&lt;/code&gt; by default and lets me layer custom &lt;code&gt;--exclude&lt;/code&gt; globs&lt;/li&gt;
&lt;li&gt;Talks the same language as OpenAI models (&lt;code&gt;cl100k_base&lt;/code&gt;, &lt;code&gt;o200k_base&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;Gives a useful summary out of the box: per-file counts, totals, percentiles, and top-N offenders&lt;/li&gt;
&lt;li&gt;Plays nicely with automation (JSON and NDJSON streaming modes)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Features at a glance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blazing fast scan&lt;/strong&gt; – &lt;code&gt;ignore::WalkBuilder&lt;/code&gt; + Rayon for concurrent IO/tokenization&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart defaults&lt;/strong&gt; – only scans &lt;code&gt;*.elm&lt;/code&gt; unless you add &lt;code&gt;--include-ext&lt;/code&gt; flags (good for Elm-heavy repos)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible filtering&lt;/strong&gt; – combine &lt;code&gt;--include-ext&lt;/code&gt;, &lt;code&gt;--exclude&lt;/code&gt;, &lt;code&gt;--max-bytes&lt;/code&gt;, and &lt;code&gt;--follow-symlinks&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple outputs&lt;/strong&gt; – table, JSON array with summary, or NDJSON stream for pipelines&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich stats&lt;/strong&gt; – totals, average per file, and P50/P90/P99 percentiles to spot outliers fast&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quiet/verbose modes&lt;/strong&gt; – keep CI logs clean or turn on detailed warnings locally&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install &lt;/span&gt;tokencount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Quick tour
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# default: scan current directory, only *.elm files, table output&lt;/span&gt;
tokencount

&lt;span class="c"&gt;# include Elm + TypeScript&lt;/span&gt;
tokencount ./frontend &lt;span class="nt"&gt;--include-ext&lt;/span&gt; elm &lt;span class="nt"&gt;--include-ext&lt;/span&gt; ts

&lt;span class="c"&gt;# show top 10 largest files by tokens&lt;/span&gt;
tokencount &lt;span class="nt"&gt;--top&lt;/span&gt; 10

&lt;span class="c"&gt;# machine-readable summary for CI&lt;/span&gt;
tokencount &lt;span class="nt"&gt;--format&lt;/span&gt; json &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; tokens.json

&lt;span class="c"&gt;# streaming counts for further processing&lt;/span&gt;
tokencount &lt;span class="nt"&gt;--format&lt;/span&gt; ndjson

&lt;span class="c"&gt;# sort descending by token count&lt;/span&gt;
tokencount &lt;span class="nt"&gt;--sort&lt;/span&gt; tokens
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each run ends with a footer like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
total files: 42
total tokens: 128730
average/file: 3065.00
p50: 812
p90: 7194
p99: 24403
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Need only the top offenders? Combine &lt;code&gt;--top N&lt;/code&gt; with either &lt;code&gt;--sort tokens&lt;/code&gt; or the default path sort.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under the hood
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ignore handling&lt;/strong&gt; uses the &lt;code&gt;ignore&lt;/code&gt; crate with &lt;code&gt;.gitignore&lt;/code&gt;, &lt;code&gt;.git/info/exclude&lt;/code&gt;, and global git ignores respected automatically. I add common junk folders (&lt;code&gt;node_modules&lt;/code&gt;, &lt;code&gt;target&lt;/code&gt;, &lt;code&gt;.git&lt;/code&gt;) so you don’t have to.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tokenization&lt;/strong&gt; relies on &lt;a href="https://crates.io/crates/tiktoken-rs" rel="noopener noreferrer"&gt;&lt;code&gt;tiktoken-rs&lt;/code&gt;&lt;/a&gt;, so you get the same counts as OpenAI’s &lt;code&gt;cl100k_base&lt;/code&gt;/&lt;code&gt;o200k_base&lt;/code&gt; models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error handling&lt;/strong&gt; is friendly by default—non UTF-8 files or oversized blobs are skipped with warnings (or silently with &lt;code&gt;--quiet&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Percentiles&lt;/strong&gt; use a nearest-rank approach and degrade gracefully when there are zero files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Roadmap &amp;amp; feedback
&lt;/h2&gt;

&lt;p&gt;I’m exploring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More encodings (if you need a different tokenizer, open an issue)&lt;/li&gt;
&lt;li&gt;Optional HTML/Markdown report outputs&lt;/li&gt;
&lt;li&gt;Built-in file size histogram to complement token stats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Repo &amp;amp; issues live here: &lt;a href="https://github.com/CharlonTank/tokencount" rel="noopener noreferrer"&gt;github.com/CharlonTank/tokencount&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try &lt;code&gt;tokencount&lt;/code&gt;, I’d love to hear how it fits into your prompt engineering workflow or CI pipelines—reach out in the repo or drop a comment below.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>cli</category>
      <category>ai</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
