Skip to main content

Local-first context hygiene tooling for AI coding sessions

Project description

Token Optimizer

Token Optimizer logo

Local-first context hygiene for AI coding sessions.

no default network no daemon dry-run first explicit inputs Apache-2.0

Token Optimizer helps you inspect context bloat, summarize explicit files, generate lightweight handoffs, and benchmark context-shaping workflows without installing invasive global hooks or collecting sensitive session data by default.

Reading Map

Start Here Then Check Deep Dive
Quick Start Benchmark Snapshot Command Reference
What It Does Safety Model Release Checks
How It Works Provider Modes More Docs
Packagetoken-optimizer
CLItoken-optimizer
Version0.1.0
LicenseApache-2.0
Default network callsnone
Default daemon/background processnone
Default raw transcript capturenone
Default raw file/tool-output persistencenone
Mutating commandsrequire explicit --yes

Why It Exists

AI coding sessions get expensive and fuzzy when every handoff starts by rereading the same files, pasting noisy command output, and rediscovering decisions that should have been compacted. Token Optimizer aims to make that hygiene visible and repeatable.

It is not a magic token counter or an always-on recorder. The MVP is deliberately small: inspect, outline, summarize, benchmark explicit fixtures, and write only project-local Token Optimizer state when asked.

[!NOTE] Token Optimizer is built for context hygiene, not hidden automation. The fastest path through the tool is still explicit: inspect first, choose inputs, then write only when you pass --yes.

What It Does

Workflow Command What You Get
Inspect setup token-optimizer doctor Project-local paths, hook state, and safety warnings
Find context bloat token-optimizer audit --project . Static signals for large files, noisy artifacts, guidance files, and plugin shape
Generate dashboard token-optimizer dashboard --project . --dry-run A plan for a static HTML audit dashboard with Expert mode for raw JSON
Outline files token-optimizer outline <file> A structure map before rereading a large Markdown or Python file
Summarize files token-optimizer summarize <files...> A compact continuation summary from explicit inputs
Benchmark fixture token-optimizer benchmark --fixture <path> Provider-neutral static_estimate comparison
Initialize state token-optimizer config init --project . --dry-run Project-local config/data plan
Clean up token-optimizer purge --project . --dry-run Token Optimizer-owned cleanup plan
Manage hooks token-optimizer hooks install --project . --dry-run Advanced experimental Stop-hook plan
Hook MCP control Token Optimizer plugin hook control Interactive MCP control with native approval-form fallback for the experimental no-op Stop-hook entry

Token Optimizer audit dashboard preview

Quick Start

From a source checkout:

PYTHONPATH=src python3 -m token_optimizer.cli doctor
PYTHONPATH=src python3 -m token_optimizer.cli audit --project .
PYTHONPATH=src python3 -m token_optimizer.cli outline README.md
PYTHONPATH=src python3 -m token_optimizer.cli summarize README.md SECURITY.md
PYTHONPATH=src python3 -m token_optimizer.cli benchmark --fixture benchmarks/fixtures/common-python-cli-session

Installed as a package:

token-optimizer doctor
token-optimizer audit --project .
token-optimizer outline README.md
token-optimizer summarize README.md SECURITY.md

How It Works

Token Optimizer workflow overview

1Start with read-only inspection.
2Require explicit project paths or explicit input files.
3Keep default workflows local-only.
4Make mutating actions dry-run inspectable.
5Store only Token Optimizer-owned project-local files when asked.
6Keep provider-specific token numbers separate from static estimates.

Benchmark Snapshot

The checked-in fixture models a small Python CLI coding session with baseline context files and optimized outline/summary outputs.

[!IMPORTANT] The chart below is a provider-neutral fixture result. It is not exact model tokens, billing usage, live Codex context-window usage, or a universal savings claim.

Common Python CLI fixture benchmark chart

Baseline estimate435
Optimized estimate202
Reduction233
Reduction percent53.56%
Preservation checksall pass
Side File Bytes Static Estimate
Baselinebaseline/cli.py32882
Baselinebaseline/continuation-note.md25564
Baselinebaseline/error-output.txt23659
Baselinebaseline/readme.md33283
Baselinebaseline/security-model.md27770
Baselinebaseline/test-output.txt30777
Optimizedoptimized/outline-output.txt13434
Optimizedoptimized/summary-output.txt672168

These numbers are provider-neutral static_estimate values using ceil(bytes / 4). They are useful for checking the fixture and methodology. They are not exact model tokens, not billing numbers, not live Codex context-window usage, and not a universal savings claim.

Use It When

Situation Why It Helps
A session keeps rereading setup filesoutline and summarize make the next read smaller and more deliberate
Command output is drowning useful factsaudit flags noisy artifacts before they become handoff clutter
You want a dashboard without a servicedashboard --dry-run and --yes produce static HTML only, with Expert mode for raw audit JSON
You need benchmark disciplinebenchmark --fixture separates static estimates from provider-specific counts
You are considering hookshooks install --dry-run, the plugin hook control app, or the native fallback form shows the exact managed block before any write

Safety Model

Area Default Posture Opt-In Behavior
NetworkNo default network callsLive provider benchmarks only when explicitly invoked
PersistenceNo raw transcripts, raw file contents, or raw tool outputProject-local config/data with --yes
HooksNo hook installed by plugin installationAdvanced experimental Stop-hook entry requires dry-run review plus --yes --experimental, hook control app approval, or explicit native-form approval; the installed command is intentionally no-op in 0.1.0
DashboardNo server or watcherStatic HTML file under .codex/token-optimizer/
CleanupNo implicit deletespurge --dry-run, then purge --yes

Writable Token Optimizer-owned paths are constrained to the selected project. Dashboard output is constrained to .codex/token-optimizer/. Hook/config/purge apply paths reject symlinked parent escapes and stale plans before writing or removing project-owned state.

Provider Modes

Mode Command Network Credential Report Label
Static estimatebenchmark --fixture <path>nononestatic_estimate
OpenAI tokenizerbenchmark openai-tiktoken --fixture <path> --model <model>nononeopenai_tokenizer_estimate
OpenAI live usagebenchmark openai-usage --fixture <path> --model <model>yesOPENAI_API_KEYopenai_provider_usage
Anthropic live countbenchmark anthropic-count --fixture <path> --model <model>yesANTHROPIC_API_KEYanthropic_count_tokens

Live provider modes send only the explicit fixture text. OpenAI live usage sends requests with store=false. Provider benchmark reports are printed to stdout and are not persisted by Token Optimizer.

Token Optimizer provider benchmark modes

Pros And Tradeoffs

Good Fit Tradeoff
Local-first teams that want inspectable context hygieneIt will not silently watch or optimize every session
Repos with repeated handoff and reread overheadYou must choose explicit files or fixtures
Users who want dry-run-first project-local changesMutating workflows are intentionally a little slower
Benchmark methodology workStatic estimates are approximate by design
Inert plugin packagingActive hook automation is intentionally deferred/gated

Command Reference

Current CLI surface
Command Read/Write Notes
doctorreadShows setup status
doctor --jsonreadStable JSON report
audit --project .readStatic context-hygiene findings
audit --project . --jsonreadStable JSON report
dashboard --project . --dry-runreadShows planned dashboard path/content
dashboard --project . --yeswriteWrites static HTML under .codex/token-optimizer/; Expert mode reveals raw audit JSON
outline <file>readMarkdown and Python structure maps
summarize <files...>readExplicit file summaries only
handoff <files...>readAlias for summarize
summarize --git-statereadAdds opt-in local git branch/status/commit context
benchmark --fixture <path>readProvider-neutral fixture estimate
benchmark --fixture <path> --jsonreadStable JSON report
config init --project . --dry-runreadProject-local config/data plan
config init --project . --yeswriteCreates .codex/token-optimizer.json and .codex/token-optimizer/
purge --project . --dry-runreadCleanup plan
purge --project . --yeswriteRemoves Token Optimizer-owned state
hooks install --project . --dry-runreadAdvanced experimental hook plan
hooks install --project . --yes --experimentalwriteInstalls an active Stop-hook entry that invokes an intentionally no-op command
Plugin hook control app/native fallbackwrite, after approvalInstalls or removes only the Token Optimizer managed no-op Stop-hook entry
hooks uninstall --project . --yeswriteRemoves managed hook state

Plugin Packages

Token Optimizer ships native package surfaces for Codex and Claude Code. The Codex package includes the local MCP hook-control surface. The Claude Code package is skill-only in 0.1.0 and guides safe CLI usage without installing hooks, starting MCP servers, or bundling the Python CLI binary.

Surface Path Includes Does Not Include
Codex.codex-plugin/, marketplace/plugins/token-optimizer/Skill, assets, local MCP hook-control serverDefault hook install, daemon, networked service
Claude Code.claude-plugin/marketplace.json, plugins/token-optimizer/Skill-only native Claude Code pluginHook install, MCP server, daemon, bundled Python CLI

GitHub install shapes after the repo is public:

codex plugin marketplace add avikahana/token-optimizer --sparse marketplace
codex plugin add token-optimizer@token-optimizer-local

claude plugin marketplace add avikahana/token-optimizer
claude plugin install token-optimizer@token-optimizer

The CLI can also be installed directly from the GitHub source with a Python installer such as pipx. The Claude Code plugin expects the CLI to be available separately.

Detailed install and support docs:

CLI Install · Codex Install · Claude Code Install · Provider And Surface Support

Release Checks

Validation commands and artifact boundaries

Run these before tagging or publishing artifacts:

PYTHONPATH=src PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -q
python3 scripts/check_release_artifacts.py
PYTHONPATH=/private/tmp/token-optimizer-validator-pyyaml python3 /path/to/validate_plugin.py .
PYTHONPATH=/private/tmp/token-optimizer-validator-pyyaml python3 /path/to/validate_plugin.py marketplace/plugins/token-optimizer
claude plugin validate .
claude plugin validate ./plugins/token-optimizer

For local marketplace install checks, use docs/local-marketplace-verification.md.

Artifact Boundary
WheelInstallable package, metadata, entry points, license
Source distributionSource, tests, benchmark fixtures, release scripts, public docs
Codex plugin package.codex-plugin/, .mcp.json, mcp/, skills/, assets/ only
Claude Code plugin package.claude-plugin/, skills/, and package README only

More Docs

Security · Privacy · Terms · Release Notes · Benchmarking · Provider Guide · Persistence Map

Public URLs

Repository: github.com/avikahana/token-optimizer
Privacy · Terms · Release Notes

License

Token Optimizer is licensed under the Apache License 2.0.

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

token_optimizer-0.1.0.tar.gz (89.8 kB view details)

Uploaded Source

Built Distribution

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

token_optimizer-0.1.0-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file token_optimizer-0.1.0.tar.gz.

File metadata

  • Download URL: token_optimizer-0.1.0.tar.gz
  • Upload date:
  • Size: 89.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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 token_optimizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bfa82562ebeb3903e9adaa5eb3a5cabeb7841957b686298341930716d91a13e4
MD5 ba0ef1c670e1ce41d322968ab7948a48
BLAKE2b-256 796b7f3ccf63dc91a912dffdefa71d93cea5b45fb52c388a4b23abe44a2e55cd

See more details on using hashes here.

File details

Details for the file token_optimizer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: token_optimizer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 48.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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 token_optimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cab96c945dc99b46afccf93598e0ec9dcad88a4d3094540d11c948bda84529bf
MD5 4f91af911328b71ecab8d4edc6bc8d05
BLAKE2b-256 09b2ed1db00ddab693e88140a638d2545cacae7f0f396403ac8ed9d88b4a8c20

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