OpenClaw Cost Optimizer for Openclaw

A dedicated cost analysis and optimization utility for OpenClaw that identifies high token consumption and provides actionable strategies to reduce AI expenses.

dagangtj
v1.0.1
Feb 26, 2026
0
888
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install oc-cost-analyzer

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install oc-cost-analyzer using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is OpenClaw Cost Optimizer?

The OpenClaw Cost Optimizer is a technical utility designed to give developers full visibility into their AI agent's operational expenses. As a key component of the Openclaw Skills ecosystem, it parses local session logs to pinpoint exactly where tokens are being spent, whether through oversized contexts, long-running conversations, or frequent automation triggers. By analyzing usage patterns across different LLM providers, it offers a data-driven approach to maintaining high-performance agents without the burden of runaway costs.

This tool is built with a privacy-first approach, operating as a pure Node.js script with zero external dependencies. It processes all data locally on your machine, ensuring that sensitive session logs never leave your environment. It is particularly effective for power users who leverage complex workflows and need to balance model intelligence with economic sustainability.

OpenClaw Cost Optimizer Use Cases

  • Identifying expensive sessions where token usage exceeds 50k to prevent context bloat.
  • Monitoring the financial impact of frequent cron jobs and automated tasks.
  • Auditing model-specific expenditures to determine when to switch from premium models like Claude Opus to more cost-effective alternatives.
  • Evaluating the savings potential of migrating specific tasks to local LLMs via Ollama.

How OpenClaw Cost Optimizer Works

  1. The script accesses local JSONL session logs located in the OpenClaw agents directory.
  2. It scans the logs for metadata including inputTokens, outputTokens, and the specific model IDs used in each request.
  3. A cost calculation engine applies current market pricing for providers like Anthropic and DeepSeek to the extracted token counts.
  4. The analyzer identifies scenarios that cross pre-defined thresholds, such as 'Large Context' (>30k tokens) or 'Frequent Cron' (>10 executions/day).
  5. It compiles the findings into a comprehensive Markdown report, detailing total costs and specific commands to implement recommended optimizations.

OpenClaw Cost Optimizer Setup

To start using this skill within your Openclaw Skills workflow, navigate to the skill directory and use the Node.js runtime to execute the analyzer.

# Generate a full analysis report for the last 7 days
node scripts/cost_analyzer.js analyze

# Perform a quick check of today's costs
node scripts/cost_analyzer.js quick

# Analyze costs for the last 30 days
node scripts/cost_analyzer.js analyze 30

OpenClaw Cost Optimizer Data Schema & Taxonomy

The optimizer interacts with specific file paths and produces structured reports as follows:

Component Path / Format Description
Source Data ~/.openclaw/agents/main/agent/sessions/*.jsonl Local session history files containing token counts.
Output Report ~/.openclaw/workspace/memory/cost-analysis-report.md A detailed Markdown summary of costs and suggestions.
Pricing Config scripts/cost_analyzer.js Internal object mapping model IDs to input/output rates per million tokens.
Reporting Markdown Tables Used within the generated report to categorize model usage and top 5 most expensive sessions.

OpenClaw Cost Optimizer Advanced Features

  • Automated Reporting: Schedule the analyzer via OpenClaw cron to receive daily or weekly cost updates.
  • Model Tiering Strategies: Detailed recommendations for downgrading tasks from Opus to Sonnet or DeepSeek based on complexity.
  • Context Compression: Guidance on optimizing AGENTS.md and SOUL.md files to reduce the baseline token footprint of every request.
  • Integration Support: Works seamlessly with other Openclaw Skills like the token-optimizer to implement suggested context reduction strategies automatically.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*