Token Optimization logo

Token Optimization

Community
cwinvestments
token-optimization

Use when the user says 'token optimization', 'save tokens', 'context window', 'reduce tokens', 'token stack', or 'TokenStack', or asks about extending context window capacity. Covers TokenStack, the built-in compression proxy that shrinks Claude Code tool output before it reaches the Anthropic API. Do NOT use for proxy troubleshooting or live status (Compress skill).

Overview

Publishercwinvestments
Repositorymemstack
Skill nametoken-optimization
Stars
425
Forks
45
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cwinvestments on GitHub. Read the source before you install it.

Installation

Install the Token Optimization AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cwinvestments/memstack/tree/master/skills/token-optimization
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cwinvestments/memstack.git /tmp/memstack
mkdir -p .claude/skills
cp -r /tmp/memstack/skills/token-optimization .claude/skills/token-optimization
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Token Optimization in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Token Optimization on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Token Optimization is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

ContextStatus
User asks about token savings or context optimizationACTIVE - full guide
User says "TokenStack", "token stack", "reduce tokens"ACTIVE - relevant section
User wants to enable or confirm the proxyACTIVE - enable steps
User asks how to read their savingsACTIVE - dashboard section
Proxy crash, health check, or live statusDORMANT - 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:

bash
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.

Free vs Pro Transforms

Free-tier transforms run on every request and are lossless (they remove only redundant formatting):

TransformWhat it removes
Strip ANSI codesterminal color and escape sequences
Strip trailing whitespaceend-of-line padding
Collapse blank linesruns of empty lines
Dedup consecutive identical linesrepeated identical lines
Strip preambles"Here is the contents of file..." lead-ins
Collapse inline whitespace (Python)redundant intra-line spacing

Pro tier (active with a valid Pro license) adds seven more transforms on top:

TransformEffect
AST truncationShortens Python function bodies while keeping signatures and type annotations. Largest single saving (around 78% on line-numbered Python). Lossy by design: Python code blocks are not preserved byte-for-byte.
JSON compressionMinifies verbose JSON output
Log deduplicationFolds repeated log lines
Path compressionShortens long repeated file paths
Markdown strippingRemoves decorative markdown
System-prompt compressionCompresses system-prompt boilerplate
Conversation-history dedupDrops duplicated earlier message blocks

Only AST truncation is lossy. Every other transform reduces tokens without changing meaning.

Confirming It Routes

The dashboard shows a proxy indicator with a live PRO or FREE tier badge plus your session and 30-day savings percentages. If the badge is present, traffic is routing through TokenStack.

A quick health check from a terminal:

bash
curl http://127.0.0.1:8787/health

Reading Your Savings

The dashboard reports savings in three places:

  • Overview header: tokens saved for the current session and lifetime.
  • Burn Report: a per-transform breakdown with estimated cost, filterable by all-time, daily, weekly, and monthly.
  • Per-Agent Token Cost: the Burn Report also splits cost across the Manager, Builder, and Reviewer agents.

What You Actually Do

  1. Enable the proxy: python -m memstack_skill_loader dashboard --with-proxy.
  2. Optionally activate a Pro license to unlock the seven Pro transforms.
  3. Read your savings on the dashboard (Overview header and Burn Report).

No installs, no MCP servers, no command prefixing.

Relationship to Other Skills

SkillScopeWhen to Use
Token Optimization (this)What TokenStack is, how to enable it, free vs Pro, reading savingsUnderstanding or turning on compression
CompressProxy health and live status troubleshootingProxy not routing, health checks
Context DBSQLite fact storeReducing repeated reads of project context

Level History

  • Lv.1 - Base: legacy 3-layer manual guide (Serena MCP, RTK CLI, Headroom API proxy). Retired. (Origin: MemStack Pro, Mar 2026)
  • Lv.2 - Rewrite: replaced the retired 3-layer manual stack with the built-in TokenStack proxy. Documents the verified enable command, free vs Pro transforms, proxy confirmation, and dashboard savings. (Jun 2026)

Frequently asked questions

What does the Token Optimization AI skill do?

Use when the user says 'token optimization', 'save tokens', 'context window', 'reduce tokens', 'token stack', or 'TokenStack', or asks about extending context window capacity. Covers TokenStack, the built-in compression proxy that shrinks Claude Code tool output before it reaches the Anthropic API. Do NOT use for proxy troubleshooting or live status (Compress skill).

Why use Token Optimization on TypingMind?

Because you install it once and use it with any model. Token Optimization is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Token Optimization in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cwinvestments/memstack/tree/master/skills/token-optimization. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Token Optimization?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Token Optimization?

As many as you like. As long as a model supports skills, you can use Token Optimization with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Token Optimization AI skill free?

Yes. It is published on GitHub by cwinvestments under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇