Token Optimizationのロゴ

Token Optimization

コミュニティ
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).

概要

公開者cwinvestments
リポジトリmemstack
スキル名token-optimization
スター
425
フォーク
45
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    cwinvestmentsがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルToken OptimizationをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/cwinvestments/memstack/tree/master/skills/token-optimization
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでToken Optimizationを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にToken Optimizationを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Token Optimizationは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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)

よくある質問

AIスキル「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).

TypingMindでToken Optimizationを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Token Optimizationはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにToken Optimizationをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/cwinvestments/memstack/tree/master/skills/token-optimizationを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Token Optimizationを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Token Optimizationは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもToken Optimizationを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Token Optimization」は無料ですか?

はい。cwinvestmentsがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇