<?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: korjwl1</title>
    <description>The latest articles on Forem by korjwl1 (@korjwl1).</description>
    <link>https://forem.com/korjwl1</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%2F3920253%2Fda8b0b10-6f20-45f1-ac2e-5299ac4ce4e3.png</url>
      <title>Forem: korjwl1</title>
      <link>https://forem.com/korjwl1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/korjwl1"/>
    <language>en</language>
    <item>
      <title>TOKI - Fast and Lightweight Token Inspector ecosystem for Vibe Coders</title>
      <dc:creator>korjwl1</dc:creator>
      <pubDate>Fri, 08 May 2026 14:47:06 +0000</pubDate>
      <link>https://forem.com/korjwl1/i-built-a-rust-replacement-for-ccusage-1742x-faster-near-zero-overhead-3c06</link>
      <guid>https://forem.com/korjwl1/i-built-a-rust-replacement-for-ccusage-1742x-faster-near-zero-overhead-3c06</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: I built &lt;a href="https://github.com/korjwl1/toki" rel="noopener noreferrer"&gt;Toki&lt;/a&gt; — a Rust daemon that replaces &lt;code&gt;ccusage&lt;/code&gt; for Claude Code / Codex token tracking. ~1,742× faster on warm queries, near-zero overhead. Two optional layers sit on top: &lt;a href="https://github.com/korjwl1/toki-monitor" rel="noopener noreferrer"&gt;toki-monitor&lt;/a&gt; (macOS menu bar app) and &lt;a href="https://github.com/korjwl1/toki-sync" rel="noopener noreferrer"&gt;toki-sync&lt;/a&gt; (self-hostable sync server). FSL-1.1-Apache-2.0, solo project.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The problem: ccusage was making my laptop crawl
&lt;/h2&gt;

&lt;p&gt;I'm a Korean dev who burns a lot of tokens in Claude Code and Codex. At my workplace we'd been keeping a half-joking &lt;code&gt;ccusage&lt;/code&gt; leaderboard of who was burning the most that week. It was fun — until we wired it into a hook to auto-run on every session, and our laptops started visibly slowing down.&lt;/p&gt;

&lt;p&gt;Looking at ccusage's design, the cause was clear. Every invocation re-walks &lt;code&gt;~/.claude&lt;/code&gt; and &lt;code&gt;~/.codex&lt;/code&gt; and re-parses every JSONL session file from scratch, single-threaded. The Zig multi-threaded fork that tries to fix this still re-reads every byte and scales memory linearly with input.&lt;/p&gt;

&lt;p&gt;OpenTelemetry would be cleaner architecturally, but it needs a central collector, can't see anything from before you set it up, and is overkill for "I just want to see my own tokens."&lt;/p&gt;

&lt;h2&gt;
  
  
  Toki — the daemon that replaces ccusage
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftoitbg9da5fjc1t1hg4h.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftoitbg9da5fjc1t1hg4h.gif" alt="Toki CLI demo showing daemon start and report commands in a&amp;lt;br&amp;gt;
  terminal" width="560" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The name "Toki" is short for &lt;strong&gt;To&lt;/strong&gt;ken &lt;strong&gt;I&lt;/strong&gt;nspector, and it's also the Korean word for rabbit (토끼) — hence the project mascot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Toki is a direct, drop-in replacement for ccusage.&lt;/strong&gt; It's a Rust daemon that indexes your sessions incrementally and serves reports from an embedded LSM store (&lt;a href="https://github.com/fjall-rs/fjall" rel="noopener noreferrer"&gt;fjall&lt;/a&gt;, used as a TSDB). Docker-style architecture: one daemon ingests, multiple clients read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;toki daemon start    &lt;span class="c"&gt;# ingests via FSEvents/inotify&lt;/span&gt;
toki report          &lt;span class="c"&gt;# instant TSDB query&lt;/span&gt;
toki trace           &lt;span class="c"&gt;# live event stream (stdout / UDS / HTTP)&lt;/span&gt;
toki query &lt;span class="s1"&gt;'sum by (model)(toki_tokens_total[1d])'&lt;/span&gt;   &lt;span class="c"&gt;# PromQL-ish&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Toki is the only piece that &lt;em&gt;replaces&lt;/em&gt; ccusage. The two other repos in this post (toki-monitor, toki-sync) are &lt;strong&gt;optional layers built on top of Toki&lt;/strong&gt;, not separate competitors to anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmarks
&lt;/h2&gt;

&lt;p&gt;On a 2GB session dataset (M1 MacBook Air, &lt;code&gt;sudo purge&lt;/code&gt; between runs):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk0y8dn5ax936bxobjht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk0y8dn5ax936bxobjht.png" alt="Cold-start benchmark" width="800" height="375"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqur7unm9agtvq90w0h9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqur7unm9agtvq90w0h9u.png" alt="Report query benchmark" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Toki&lt;/th&gt;
&lt;th&gt;ccusage&lt;/th&gt;
&lt;th&gt;zzusage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cold-start&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.54 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;21.5 s&lt;/td&gt;
&lt;td&gt;1.41 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Report query (warm)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~12 ms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;21.5 s&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Idle RAM&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;5 MB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(no idle state)&lt;/td&gt;
&lt;td&gt;(no idle state)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Idle CPU&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DB on disk&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;~3%&lt;/strong&gt; of source&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Translation&lt;/strong&gt;: the daemon stays out of the way. Your laptop fan won't spin from this; you only feel it when you actually run a query, and queries come back fast enough that you barely notice the round trip.&lt;/p&gt;

&lt;p&gt;The report query is constant-time regardless of dataset size — it hits the TSDB index, not the source files. So 1,742× on 2 GB of sessions, and the speedup keeps growing as your history grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The JSONL pipeline is where most of the engineering went.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Cold-start: parallel mmap'd parsing
&lt;/h3&gt;

&lt;p&gt;Cold-start uses &lt;code&gt;mmap&lt;/code&gt; + &lt;a href="https://github.com/rayon-rs/rayon" rel="noopener noreferrer"&gt;Rayon&lt;/a&gt; to walk session files in parallel. Lines without token-usage fields get skipped before serde ever touches them — most JSONL lines (thinking blocks, plain text content) don't carry usage, so this single filter is a meaningful win.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Selective serde on token-bearing lines
&lt;/h3&gt;

&lt;p&gt;For the lines that &lt;em&gt;do&lt;/em&gt; contain usage, the serde decoder is configured to skip every string field except the token counts. Prompts, responses, and thinking blocks are &lt;strong&gt;never even allocated&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Privacy comes from the parser, not from policy — and it's a real speed win on big files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. xxHash3 fingerprint + reverse-from-EOF resume
&lt;/h3&gt;

&lt;p&gt;For incremental resume, the daemon stores an xxHash3 fingerprint of the last line it read. On the next run it scans backward from EOF and matches by hash, so even if a session file got compacted from the front, the right resume point is found in O(1) hash compares. No re-scanning everything just to figure out where we left off.&lt;/p&gt;

&lt;p&gt;Architecture details — writer thread topology, trace fan-out, query parser — are documented in &lt;a href="https://github.com/korjwl1/toki/blob/main/docs/DESIGN.md" rel="noopener noreferrer"&gt;DESIGN.md&lt;/a&gt;. The short version: one writer thread per provider, separate UDS read path, so reports never block ingestion.&lt;/p&gt;




&lt;h2&gt;
  
  
  On top of Toki: toki-monitor (macOS menu bar GUI)
&lt;/h2&gt;

&lt;p&gt;The CLI isn't for everyone, so I built &lt;a href="https://github.com/korjwl1/toki-monitor" rel="noopener noreferrer"&gt;toki-monitor&lt;/a&gt; — a macOS menu bar app that runs on top of the Toki daemon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2km5mylb46rkm913pep8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2km5mylb46rkm913pep8.png" alt="toki-monitor menu bar modes" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The starting idea was something like RunCat but for token usage: a pixel rabbit in your menu bar that runs faster the more tokens you burn. As I built it, I kept finding things that make sense for AI tools but wouldn't for RunCat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rabbit sleeps when you stop using AI for a while&lt;/strong&gt; (zZ animation), because "0 tokens" is a meaningful state for an AI tool while "0 CPU" never really is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xhvkwjfy3sutvznaqrd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xhvkwjfy3sutvznaqrd.gif" alt="Rabbit sleeping when idle" width="254" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An HP bar above the character&lt;/strong&gt; shows how much of your Claude or Codex window is left, and depletes green → red as your weekly window burns down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional warning system&lt;/strong&gt;: a hit animation when your $/min crosses a threshold you set, and a poison effect when usage spikes anomalously vs your 24h baseline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr275scmdhpftrdtw314y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr275scmdhpftrdtw314y.gif" alt="Hit effect when threshold crossed" width="254" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can render Claude and Codex as two separate characters in different colors, or merge them into one. Numeric and sparkline modes per provider if the mascot isn't your thing.&lt;/p&gt;

&lt;p&gt;There's also a dashboard panel system (still beta) with PromQL-style queries, time-series charts, project breakdowns, and Liquid Glass styling for macOS Tahoe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpx0a6tp4f9teyz952m4x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpx0a6tp4f9teyz952m4x.png" alt="toki-monitor dashboard" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dashboard is functional but rough at the edges, and the menu bar animations aren't as polished as I'd like — solo dev, sprite art is genuinely not my strength. &lt;strong&gt;Contributions on the visual side would be amazing&lt;/strong&gt; — new menu bar characters, animation refinements, dashboard polish, anything visual. The theme system is modular, so adding a new character is mostly drag-and-drop PNGs plus a small &lt;code&gt;theme.json&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  On top of Toki: toki-sync (self-hostable sync server, beta)
&lt;/h2&gt;

&lt;p&gt;There's also &lt;a href="https://github.com/korjwl1/toki-sync" rel="noopener noreferrer"&gt;toki-sync&lt;/a&gt; for multi-device users, team analytics, or running a "who's burning the most tokens this week" leaderboard with friends.&lt;/p&gt;

&lt;p&gt;Custom binary TCP protocol (bincode + zstd + ACK flow control + delta-sync on reconnect), runs on AWS free-tier EC2 with fjall, ClickHouse backend for bigger deployments. Built-in auth + RBAC + REST API on top, so you can build your own dashboard. Still beta and the README is rough.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew tap korjwl1/tap
brew &lt;span class="nb"&gt;install &lt;/span&gt;toki                  &lt;span class="c"&gt;# CLI daemon (the ccusage replacement)&lt;/span&gt;
brew &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--cask&lt;/span&gt; toki-monitor   &lt;span class="c"&gt;# optional macOS GUI on top&lt;/span&gt;
toki daemon start &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; toki report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Linux + macOS for the daemon (toki-monitor is macOS-only). Claude Code + Codex CLI supported today, Gemini CLI is next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Status &amp;amp; contributions
&lt;/h2&gt;

&lt;p&gt;Solo project, &lt;strong&gt;FSL-1.1-Apache-2.0&lt;/strong&gt; — full source, free for personal and commercial use, converts to Apache 2.0 after two years.&lt;/p&gt;

&lt;p&gt;Contributions of any kind very welcome:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code&lt;/strong&gt; — issues / PRs across all three repos&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sprite art&lt;/strong&gt; — new menu bar characters for toki-monitor (theme system is documented and modular)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Animation&lt;/strong&gt; — refinements and polish&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Translations&lt;/strong&gt; — currently EN / KO, more languages welcome&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you try it and run into anything weird, please file an issue. Happy to answer questions in the comments 🐇&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Repos:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/korjwl1/toki" rel="noopener noreferrer"&gt;korjwl1/toki&lt;/a&gt; — the daemon (Toki proper, replaces ccusage)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/korjwl1/toki-monitor" rel="noopener noreferrer"&gt;korjwl1/toki-monitor&lt;/a&gt; — macOS menu bar GUI, on top of Toki&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/korjwl1/toki-sync" rel="noopener noreferrer"&gt;korjwl1/toki-sync&lt;/a&gt; — sync server, on top of Toki (beta)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>showdev</category>
      <category>vibecoding</category>
      <category>claude</category>
    </item>
  </channel>
</rss>
