Skip to content

Claude Token Optimizer

by Nadim TuhinCLI toolWrite code

Shrinks the notes Claude Code rereads at every session start, so each uses fewer tokens

View on GitHub

The problem it solves

You open Claude Code and thousands of tokens of old session notes load before you type a word, every session.

For Claude Code usersPeople with long project notesPeople who watch their Claude Code usage

Before
Your CLAUDE.md keeps growing with old notes and finished tasks, and every session rereads all of it.
After
A short CLAUDE.md loads at startup, older notes wait in side files Claude opens when needed, and you see the token count before and after.
Stars
★ 637
License
MIT
Cost
Free
Platforms
Mac · Win · Linux
Level
Intermediate

Overview

Claude Token Optimizer is a command-line tool for people who use Claude Code in a project folder. It counts how many tokens your CLAUDE.md and related files load at the start of each session, then moves old session notes and finished task lists into side files that Claude opens only when needed. It keeps a backup of the file it changes and shows the count before and after. It suits Claude Code users whose project notes have grown long.

It shows the token count first, so you can see what each session costs before changing anything.

Try these first

Start with the first one: it is a small task you can check easily.

  1. In your project folder, run: npx -y claude-token-optimizer measure. Note the startup total before changing anything.First try · read-only

  2. Back up my CLAUDE.md, then set up claude-token-optimizer from github.com/nadimtuhin/claude-token-optimizer by following its AGENTS.md. Show the token count before and after.edits files

  3. Run the prune command with a dry run first and tell me which notes it would move.dry run

  4. Run the audit and explain each problem it finds in my CLAUDE.md.

Example prompts written by Agent Flows Hub.

Features

From the creator's documentation.

FeatureWhat it doesRuns
MeasureShows how many tokens load at session start, file by fileYour computer
PruneMoves finished tasks and old session notes into side files, with a backupYour computer
CompressShrinks a markdown file with fixed rules; it cuts long lists and commentsYour computer
AuditRuns 19 structure checks on your project notesYour computer
Before and afterShows the token difference between a file and its backupYour computer
HooksOptional Claude Code hook templates, for example one that warns when startup files grow too largeYour computer

Good to know

Your Claude Code project has a long CLAUDE.md full of old session notes and finished tasks. The tool measures what loads at session start and moves the old material into files Claude reads only on demand.

Limits

  • prune and compress rewrite CLAUDE.md and keep only one backup, which the next run replaces; copy the file yourself first. compress is lossy.
  • In a project with no CLAUDE.md, init writes new files and can replace an existing .claudeignore or .claude/*.md; commit or back them up first.
  • Token counts come from an older Claude tokenizer, so treat them as estimates rather than exact usage.

Notes by (original project name: claude-token-optimizer (cto)), written from the creator's documentation, not from running it ourselves. Claude Token Optimizer: README and commands

Stuck setting it up?

Tell us what happened. We take a look first; if it needs paid work, you get an estimate before anything starts.

Get help

Other cli tools

  • CodeBurn Shows what your AI coding tools cost, split by project, model and task
  • Dev Browser Lets your coding agent drive a real Chrome browser to open pages, click and check results
  • Fabric Runs ready-made AI prompts on any text, such as summarising an article into key points
  • Horizon Turns the news sources you follow into a ranked daily briefing in English or Chinese
  • LLM Lets you ask many AI models questions from the terminal and keeps a log of every answer
  • MarkItDown Converts PDFs, Word, Excel, PowerPoint and more into Markdown text an AI can read

See all 18 cli tools

GitHub