◈ Drop-in compression for every workflow

Integrations

TokenShrink plugs into your existing workflow. No new tools to learn. No changes to how you work.

Claude Code Hook

Claude Code

HOOK

Automatically compresses every prompt you send

How it works

A UserPromptSubmit hook intercepts your message before it reaches Claude, compresses it with TokenShrink, and passes the compressed version — saving tokens on every single turn.

One-command install

curl -fsSL https://tokenshrink.com/install-claude-code.sh | bash

Requires Node.js · Works on macOS and Linux · No npm install needed

What you get

  • 💰 Token savings counter in your Claude Code status bar
  • ⚡ Every prompt automatically compressed before it reaches Claude
  • 📋 Per-session log at ~/.claude/.tokenshrink-log.jsonl
Manual install steps
01

Download the hook to ~/.claude/hooks/

terminal
curl -fsSL https://tokenshrink.com/hooks/tokenshrink-compress.js \
  -o ~/.claude/hooks/tokenshrink-compress.js
02

Register it in ~/.claude/settings.json

~/.claude/settings.json
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "node $HOME/.claude/hooks/tokenshrink-compress.js"
          }
        ]
      }
    ]
  }
}

OpenClaw

OpenClaw

SDK

Compress conversation history before routing to your agents

What is OpenClaw

OpenClaw is a Discord-to-AI gateway that routes messages to local agents. TokenShrink's compressHistory() reduces the token cost of every conversation before it hits your Ollama models.

openclaw-handler.js
import { compressHistory } from 'tokenshrink';

// Before sending conversation to your agent
const { messages, stats } = compressHistory(conversationHistory);
console.log(`Saved ${stats.totalTokensSaved} tokens this turn`);

// Pass compressed messages to Ollama or any OpenAI-compatible API
const response = await fetch('http://localhost:11434/api/chat', {
  method: 'POST',
  body: JSON.stringify({
    model: 'your-model',
    messages: messages,
  }),
});

Note

Works with any Ollama model. Compression happens locally — no data leaves your machine.

SDK

Any Claude App

SDK

Two functions. Works with every LLM.

single-prompt.js
// Single prompt
import { compress } from 'tokenshrink';

const { compressed, stats } = compress(myPrompt);
// → stats.tokensSaved
// → stats.ratio
conversation.js
// Full conversation history
import { compressHistory } from 'tokenshrink';

const { messages, stats } = compressHistory(history);
// → stats.totalTokensSaved
// → stats.messagesCompressed
npm install tokenshrink