Skill: pfaria32/token-economy (version 1.0.3)

# Token Economy Reduce OpenClaw costs by 60-80% through intelligent model routing and context management. Cheap-first escalation (GPT-4o → Sonnet → Opus), zero-token heartbeats, and budget guardrails. Save $60-105/month per deployment. **When to use:** Questions about costs, model routing, token optimization, budget **What to know:** ## Active Optimizations This OpenClaw fork includes token-economy hooks (deployed Feb 13, 2026): **1. Model Routing** - Cheap-first with escalation: - Start: GPT-4o (fast, cheap) - Escalate: Sonnet (balanced) - Last resort: Opus (expensive, complex tasks only) **2. Bounded Context** - Hard caps prevent bloat: - Max bundle size: 10,000 tokens - Auto-truncate if exceeded - Prevents runaway context costs **3. Zero-Token Heartbeat** - Pre-LLM check: - If `HEARTBEAT.md` empty → skip API call (100% cost elimination) - Heartbeats were ~50% of token usage before optimization **4. Token Auditing** - Full transparency: - Log: `~/.openclaw/token-audit.jsonl` - Daily reports available - Budget guardrails: $25/day hard cap ## Expected Impact - 60-80% overall token reduction - 100% heartbeat cost elimination - ~$1-1.50/day (vs ~$3-5/day before) - $60-105/month savings ## Config Location `~/.openclaw/openclaw.json` - token-economy hooks configuration ## Repository https://github.com/pfaria32/open-claw-token-economy ## Status Commands ```bash # Check current model openclaw status # View token usage cat ~/.openclaw/token-audit.jsonl | tail -20 # Check heartbeat config cat ~/workspace/HEARTBEAT.md ``` ## When to Mention - User asks about costs or budget - Model selection questions - "Why is this slow/expensive?" - Optimization discussions - Before making model routing decisions ## Auto-Switch to Sonnet If model is set to Opus and there's no user input for >1 hour with no complex task in progress, automatically switch back to Sonnet to save costs. A cron job checks this every 30 minutes. **When to stay on Opus:** - Active complex reasoning/debugging task - User explicitly requested Opus for a specific purpose - Working on something that genuinely needs the extra capability

path: README.md
content: # Token Economy

Reduce OpenClaw costs by 60-80% through intelligent model routing and context management. Cheap-first escalation (GPT-4o → Sonnet → Opus), zero-token heartbeats, and budget guardrails. Save $60-105/month per deployment.

## Features

- Intelligent model routing with cheap-first escalation
- Bounded context management (10k token caps)
- Zero-token heartbeats (100% elimination)
- Token auditing and daily reports
- Budget guardrails ($25/day hard cap)

## Expected Impact

- 60-80% token cost reduction
- $60-105/month savings per deployment
- 100% heartbeat cost elimination

## Installation

```bash
clawhub install token-economy
```

## Repository

https://github.com/pfaria32/open-claw-token-economy

## License

MIT


path: SECURITY.md
content: # Security Notice - Token Economy

## Purpose

Token Economy is a **COST OPTIMIZATION TOOL** that reduces OpenClaw token costs through intelligent model routing. It does NOT contain malicious code.

## What This Tool Does

✅ **Routes requests** to cheaper models first (GPT-4o → Sonnet → Opus)  
✅ **Caps context size** to prevent runaway costs  
✅ **Tracks token usage** for transparency and budgeting  
✅ **Enforces budget limits** to prevent surprise bills  
✅ **Optimizes heartbeats** to eliminate unnecessary API calls

## What This Tool Does NOT Do

❌ **Does NOT steal API keys** - Uses existing configured keys  
❌ **Does NOT send data externally** - All routing happens locally  
❌ **Does NOT modify user data** - Only affects model selection  
❌ **Does NOT bypass security** - Works within OpenClaw's architecture

## Why References to API Keys Exist

This repository contains:
- Configuration examples showing where API keys are stored (`ANTHROPIC_API_KEY`, etc.)
- Documentation explaining how model routing works
- Cost calculations that reference pricing for different APIs

**These are references for configuration, not code that accesses or exfiltrates keys.**

## Safe Usage

```bash
# Install the skill
clawhub install token-economy

# Configure your existing API keys (no new keys needed)
# Token Economy uses OpenClaw's existing API configuration

# Monitor token usage
cat ~/.openclaw/token-audit.jsonl
```

## False Positive Explanation

Automated security tools may flag this because:

1. **Documentation mentions API keys** - We explain how routing works, which requires discussing API configuration
2. **Cost tracking code** - We log token usage and costs (for transparency, not exfiltration)
3. **Budget enforcement** - We read configuration to enforce spending limits

**This is cost optimization, not credential theft.**

## Verification

To verify safety:
1. ✅ Review the source code: TypeScript patches for OpenClaw core
2. ✅ Check network calls: None - all routing is local
3. ✅ Inspect git history: No credential access or exfiltration code
4. ✅ Read the audit log: `token-audit.jsonl` shows what's tracked (usage only)

## Privacy

Token Economy logs:
- Model selection decisions
- Token counts per request
- Cost estimates

Token Economy NEVER logs:
- API keys or credentials
- Message content
- User data

## License & Disclaimer

MIT License - Provided "AS IS" with NO WARRANTIES.

**Expected impact:** 60-80% token cost reduction. Actual results may vary based on usage patterns.

---

**TL;DR:** This is a cost optimization tool that references API configuration for routing. It does NOT access, store, or transmit your API keys.


Security scan verdicts — ClawScan: suspicious | static analysis:  | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)