Token Guard
Local token estimation, context deduplication, and budget circuit-breaking for agent workflows.
Free
Works with the AI Agents you already use
token-guard
Example session with this skill installed
Trim filler from my dev-prompt.md and check if it fits a 500 token budget for claude-3-5-sonnet.
- Read your context and instructions
- Compiled the token-guard
I have processed the file through the token-guard pipeline. The trimming rules removed redundant filler and duplicate paragraphs, resulting in a 17.5% reduction in context size.
Token Guard Audit Report
| Metric | Value |
|---|---|
| Original Tokens | 554 |
| Trimmed Tokens | 457 |
| Tokens Saved | 97 (17.5%) |
| Active Rules | line, block, restatement |
| Budget Limit | 500 tokens |
| Status | OK_WITHIN_BUDGET |
| Model | claude-3-5-sonnet |
| Estimated Cost | $0.001371 (Assumed) |
Analysis
- The
blockrule successfully identified a repeated instruction paragraph of 48 characters. - Code blocks were preserved in their entirety.
- The request is safe to send to the provider as it falls 43 tokens under your maximum threshold.
Next steps
- Run
estimate.py session addto record this transaction in your local receipt log. - Use
estimate.py tools trimif you plan to include MCP tools in this request. - Review the
pricing.yamlfile to ensure the $3.00/1M input token rate matches your current tier.
Connects securely to your tools. The creator never sees your data.
About this skill
Stop overpaying for agent sessions and runaway subagent loops. This local utility provides precise token estimation, context compression, and budget enforcement without calling external APIs. It addresses the high cost of long-context prompts by aggressively trimming filler, deduplicating restatements, and pruning unused tool catalogs.
What it does
- Token estimation calculates counts using the
cl100k_basetokenizer for accurate pre-flight planning. - Context trimming applies five distinct rules to remove filler, duplicate lines, and redundant sentences while protecting code blocks.
- Budget enforcement acts as a circuit-breaker to stop requests that exceed user-defined token or cost limits.
- Tool pruning filters MCP catalogs to include only the functions required for the specific task.
- Loop guarding monitors session logs to terminate infinite agent loops based on depth, tokens, or repetition.
- Cost reporting generates session receipts using verified pricing data for Anthropic, OpenAI, and Google models.
How it works
- Estimate the token count of a file or prompt string to establish a baseline.
- Trim the context using the
trimcommand to reduce token weight by up to 18% through deduplication. - Set a budget using the
--maxflag to gate execution and prevent high-cost API calls. - Log sessions to a JSONL receipt file to track cumulative spend across multiple agent turns.
Frameworks & tools
Built with Python and tiktoken. Uses a local pricing.yaml configuration for model rates and cl100k_base for BPE tokenization.
Why this beats prompting it yourself
LLMs are poor at estimating their own token usage and often fail to prune their own context effectively. This tool provides deterministic, rule-based reduction that guarantees code integrity while stripping proven filler that agents typically ignore.
Use cases
- Preventing runaway costs in autonomous multi-agent workflows.
- Shrinking massive tool catalogs before sending them to expensive long-context models.
- Auditing team-wide API spend across different providers using local logs.
- Optimizing session resumes by identifying stable prefixes for prompt caching.
Known limitations
Does not catch semantic restatements using synonyms or restatements split across hard-wrapped lines. Token counts for Claude models are estimates as they use different internal tokenizers.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.
Synonym-based restatements and hard-wrapped duplicates are not caught. Model prices are a point-in-time snapshot and require manual config updates. Batch+cache pricing is an approximation.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 6 days ago
- Free with an Agensi account
- Software
Python