token-optimization

token-optimization is a skill for Claude Code, Codex from cwinvestments/memstack. It costs 79 tokens per session (1,246 once invoked), scanned A, original, MIT.

A compression proxy that shortens bulky tool output before it reaches the AI service. It helps preserve room in the conversation context and reduce token use.

In plain words
What is it for?
Use it when you want to reduce token use, extend usable context, or check how much output compression saves.
Why use it?
Long tool results can fill the context window and increase usage costs. Compressing them leaves more space for useful code and discussion.

Skill for Claude CodeCodex

Part of the memstack plugin — 86 skills, 2 commands, 5 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cwinvestments/memstack/token-optimization
Any agent
npx skills add cwinvestments/memstack --skill token-optimization
Clone the repo
git clone --depth 1 https://github.com/cwinvestments/memstack

Made for: Claude Code, Codex.

Or install memstack, the plugin that ships this one along with the rest of its 86 skills, 2 commands, 5 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for token-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/cwinvestments/memstack/token-optimization.svg)](https://agentmods.dev/skills/cwinvestments/memstack/token-optimization)
Your own site
<a href="https://agentmods.dev/skills/cwinvestments/memstack/token-optimization"><img src="https://agentmods.dev/badge/skills/cwinvestments/memstack/token-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 79 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,246 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00079 $0.01246
Opus 5 $0.00039 $0.00623
Sonnet 5 $0.00016 $0.00249
Haiku 4.5 $0.00008 $0.00125

Measured yesterday against content hash 5ae4d2bcd0ea, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

token-optimization scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

curl http://127.0.0.1:8787/health
skills/token-optimization/SKILL.md · 119 lines

How it starts

The opening of the file, as written. The whole thing — 119 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Token Optimization Guide - TokenStack

One built-in compression proxy that shrinks Claude Code tool output before it reaches the Anthropic API.

Activation

When this skill activates, output:

TokenStack - enabling compression & reading your savings...

Then execute the protocol below.

Context Guard

Context Status
User asks about token savings or context optimization ACTIVE - full guide
User says "TokenStack", "token stack", "reduce tokens" ACTIVE - relevant section
User wants to enable or confirm the proxy ACTIVE - enable steps
User asks how to read their savings ACTIVE - dashboard section
Proxy crash, health check, or live status DORMANT - use Compress skill
User is actively coding (no optimization discussion) DORMANT - do not activate

What TokenStack Is

TokenStack is a single transparent proxy that sits between Claude Code and the Anthropic API. It intercepts each request, compresses the bulky tool output inside it, and forwards the smaller payload upstream. Less text per turn means more usable context and lower token cost.

It is built into the memstack-skill-loader package. There is nothing extra to install: if you have MemStack, you have TokenStack.

Earlier versions documented a 3-layer manual setup (Serena MCP, RTK CLI, and the Headroom API proxy). That stack is retired. TokenStack supersedes all three. There is no pip install, no Rust binary, no MCP server, and no command prefixing.

Enabling It

Start the dashboard with the proxy flag:

python -m memstack_skill_loader dashboard --with-proxy

This starts the TokenStack proxy on 127.0.0.1:8787 and sets ANTHROPIC_BASE_URL for you, so Claude Code traffic routes through it automatically. No manual environment configuration is needed.

Options:

  • --proxy-port N changes the proxy port (default 8787).
  • To run only the proxy without the dashboard: python -m memstack_skill_loader proxy.

Read the full file on GitHub · 119 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 119 lines · 79 tokens per session scan A 5ae4d2bcd0ea

Subscribe to this mod's changes

token-optimization is a skill published in the GitHub repository cwinvestments/memstack (419 stars, last pushed yesterday), licensed MIT. It adds 79 tokens to every session and 1,246 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

design-review

Designer's eye QA: finds visual inconsistency, spacing issues, hierarchy problems, AI slop patterns, and slow interactions — then fixes them. Iteratively fixes issues in source code, committing each fix atomically and re-verifying with before/after screenshots. For plan-mode design review (before implementation), use…

GCWing/BitFun · 125 tokens

plan-eng-review

Eng manager-mode plan review. Lock in the execution plan — architecture, data flow, diagrams, edge cases, test coverage, performance. Walks through issues interactively with opinionated recommendations. Use when asked to "review the architecture", "engineering review", or "lock in the plan". Proactively suggest when…

GCWing/BitFun · 116 tokens

pre-landing-review

Pre-landing PR review. Analyzes diff against the base branch for SQL safety, LLM trust boundary violations, conditional side effects, and other structural issues. Use when explicitly asked for the specialized pre-landing workflow. Product /review requests are handled by BitFun's unified Review mechanism instead.…

GCWing/BitFun · 74 tokens

miniapp-dev

Develops, maintains, and generates BitFun MiniApps (Zero-Dialect Runtime). Use when (1) working on miniapp framework code under src/crates/assembly/core/src/miniapp/ or src/web-ui/src/app/scenes/miniapps/; or (2) generating / creating / designing a NEW MiniApp for the user — including any request like "做一个小应用 / 生成…

GCWing/BitFun · 143 tokens

commit-push-pr

Commit selected local changes, push the branch, and create or update a GitHub pull request with BitFun attribution. Use when the user asks to 提交 PR、提代码、commit and push、开 PR、create a pull request, or wants a Claude Code-like one-command PR publishing flow from BitFun.

GCWing/BitFun · 68 tokens

investigate

Systematic debugging with root cause investigation. Four phases: investigate, analyze, hypothesize, implement. Iron Law: no fixes without root cause. Use when asked to "debug this", "fix this bug", "why is this broken", "investigate this error", or "root cause analysis". Proactively invoke this skill (do NOT debug…

GCWing/BitFun · 112 tokens