OpenClaw Optimization Hook โœจ

Stop burning money on
your OpenClaw.

ClawGuard operates securely inside OpenClaw to actively compress massive payloads, prune history, and dynamically route simple tasks to cheap models. Save up to 80% on API costs.

npm install -g clawguard
105k ~$0.15 / req Avg Output Payload
5k ~$0.007 / req With ClawGuard

> Quick Start

macOS/Linux change ฮฒ BETA

# Installs the ClawGuard CLI and Hook globally.

$ npm install -g clawguard && clawguard init

The Ultimate Moat Against Token Waste

Generic API routers blindly charge you for massive 100k token payloads. ClawGuard actually looks inside OpenClaw and actively shrinks the payload before it leaves your machine.

๐Ÿ”ช

Artifact Truncation

OpenClaw injects your massive SOUL.md character file on every turn. If you ask "What is 2+2?", we temporarily strip the 5,000-word backstory because the AI doesn't need to know its persona to do math.

โณ

Sliding Window Memory

Instead of sending history back and forth forever, we aggressively condense old turns (like a 2,000 word email draft) into a single, dense memory block. Facts are retained, fluff is deleted.

๐Ÿ”€

Dynamic Override

Even if OpenClaw is configured to use Claude 3.5 Opus, if we intercept a simple request, we silently override the target model to Haiku locally to save you money.

๐Ÿ’“

Zero-Cost Heartbeats

OpenClaw sends background check-ins. ClawGuard recognizes these and instantly returns a mock success response locally. Cost drop from $0.15 to $0.00.

๐Ÿงน

Tool Output Pruning

When OpenClaw runs a command (like `git log`), the massive terminal output gets stuck in the history forever. Our Fast Math engine dynamically replaces old tool outputs with a 1-sentence summary, instantly deleting thousands of tokens securely.

๐Ÿšง

Budget Guardrails

Set a hard daily spending limit. ClawGuard tracks your real-time token usage locally and securely blocks API calls before you accidentally wake up to a massive AI bill.

Security First

A Trustless Architecture.

We know developers hate proxies because it means giving up API keys. That's why ClawGuard is not a proxy. It is a Native OpenClaw Hook.

  • โœ“
    Zero API Key Exposure

    ClawGuard runs in-memory *before* OpenClaw attaches your keys. We never see your API tokens.

  • โœ“
    100% Local Execution

    All heuristics and context trimming happen locally on your hardware. We don't send your data to our servers.

  • โœ“
    Zero Latency Hops

    No waiting on external router servers. We run entirely as local TypeScript inside OpenClaw's loop.

~/.openclaw/hooks/clawguard/handler.ts
// 1. Intercept before OpenClaw sends
export default async function hook(event) {
  if (event.type === 'agent:bootstrap') {
    // 2. Analyze the messages array locally
    const payload = event.context;
    
    // 3. Condense context if it exceeds 5k tokens
    if (payload.tokenCount > 5000) {
      payload.messages = compressMemory(payload.messages);
      log('Saved $0.15 this turn.');
    }
  }
}