TokenGuard for Openclaw

TokenGuard is a dedicated API cost guardian that tracks AI agent spending, enforces configurable budget limits, and prevents expensive runaway loops.

g0head
v1.0.0
Feb 2, 2026
3
1.9k
2

Install & Download

1. ClawHub CLI

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

npx clawhub@latest install tokenguard

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 tokenguard 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 TokenGuard?

TokenGuard serves as a critical safety layer for AI agents making paid API calls. By implementing session-based tracking and hard limits, it ensures that your development or production agents never exceed their allocated budget. This tool is essential for developers using Openclaw Skills who want to maintain financial control over their autonomous agents.

The skill provides a robust framework for monitoring costs across various models like GPT-4o and Claude 3.5 Sonnet. It allows for pre-flight budget verification before executing expensive operations, ensuring that your Openclaw Skills remain cost-effective and secure from unexpected billing spikes.

TokenGuard Use Cases

  • Prevent runaway loops from exhausting API credits during autonomous agent execution.
  • Enforce daily or session-based spending limits for development environments.
  • Monitor real-time API usage and cost metrics across multiple AI models.
  • Implement pre-flight budget checks before performing high-token operations.
  • Audit historical spending patterns to optimize AI agent performance and cost efficiency.

How TokenGuard Works

  1. Initialize the budget by setting a session limit using the set command.
  2. Perform a pre-flight check before any expensive API call to verify if the estimated cost fits the remaining budget.
  3. Execute the API operation and capture the actual token usage or monetary cost.
  4. Log the actual cost to the session history, which updates the internal tracking data.
  5. Use the status command or exit codes to monitor budget health and trigger alerts or overrides if limits are reached.

TokenGuard Setup

Install the skill via the CLI:

clawhub install tokenguard

Alternatively, set up manually within your workspace:

mkdir -p ~/.openclaw/workspace/skills/tokenguard
# Copy scripts/tokenguard.py to the directory
chmod +x scripts/tokenguard.py

Configure your environment defaults (optional):

export TOKENGUARD_DEFAULT_LIMIT=20.0
export TOKENGUARD_WARNING_PCT=0.8

TokenGuard Data Schema & Taxonomy

TokenGuard organizes its tracking data within the ~/.tokenguard/ directory using the following JSON structure:

File Description
limit.json Stores the current spending limit and configuration settings.
session.json Contains daily spending totals and a detailed log of all API cost entries.
override.flag A temporary file used to signal a one-time bypass of budget restrictions.

All data is exportable in a standard JSON format for integration with external monitoring dashboards.

TokenGuard Advanced Features

  • Multi-model cost reference table for Claude and GPT series.
  • Automated daily session resets to manage recurring budgets.
  • One-time budget overrides for critical high-cost operations.
  • Exit code integration for seamless use in bash scripts and automated workflows.
  • JSON export capability for full audit trails and data analysis.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*