Logo di Token Optimization

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

Panoramica

Autorecwinvestments
Repositorymemstack
Nome della skilltoken-optimization
Stelle
425
Fork
45
File inclusi
Solo istruzioni
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da cwinvestments su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Token Optimization in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/cwinvestments/memstack/tree/master/skills/token-optimization
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Nuova skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella nella cartella delle skill di quell'agente.

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
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Token Optimization in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Token Optimization non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Token Optimization non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

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)

Domande frequenti

Cosa fa la skill IA 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).

Perché usare Token Optimization su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Token Optimization è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Token Optimization in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/cwinvestments/memstack/tree/master/skills/token-optimization. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Token Optimization?

Qualsiasi modello che colleghi in TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Token Optimization?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Token Optimization: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Token Optimization è gratuita?

Sì. È pubblicata su GitHub da cwinvestments con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, modelli o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇