# Token-Guard — Caching & Autonomy Optimizer

> Lower your AI costs and prevent expensive infinite loops by cleaning up chat memory and setting task limits.

Token-Guard — Caching & Autonomy Optimizer is a paid AI agent skill pack (several skills in one listing) on Agensi by Rachid Houmayni, in Agents & Orchestration. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $39 (one-time purchase)
- Creator: [Rachid Houmayni](https://www.agensi.io/creators/rachid-houmayni)
- Category: [Agents & Orchestration](https://www.agensi.io/skills/agents-orchestration)
- Version: 1.0
- Last updated: 2026-12-03
- Security: scan passed (2026-08-31); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/token-guard-caching-autonomy-optimizer
- Tags: ai-agents, token-optimization, claude-code, cursor, llm-ops

## What it does

- Moves large documents to local folders to keep the chat fast and cheap
- Sets hard limits on how many times the AI can repeat a task before stopping
- Creates a simple list of where every large file is stored for easy retrieval
- Protects the first few messages of your chat to keep the AI focused and accurate

## About this skill

When you work with an AI agent for a long time, the chat gets crowded. It starts costing more money, runs slower, and can even get stuck repeating the same mistake forever. This skill gives your AI agent a set of tools to keep things tidy and cheap. It works by shrinking down the middle of your conversation while keeping the start and the most recent parts crystal clear.

If you have huge files or long reports, this skill tells your AI to move them to a side folder instead of keeping them in the chat memory. It leaves a small note so it can find the file later if needed. Most importantly, it sets a hard limit on how many times the AI can try something. If the AI hits that limit, it stops and asks you what to do instead of wasting your budget.

**How it works**
1. Ask your AI agent to start the skill at the beginning of a long task.
2. Review the plan your AI suggests for shrinking the chat or moving large files.
3. Check the progress reports to see how many tokens and steps you have used.
4. Give your approval before the AI cleans up old parts of the chat history.

**What you get:** A system that lowers your AI costs by up to 80% and stops runaway loops.

## Known limitations

Requires local file system write access for offloading. The loop-guard helper script requires manual execution to enforce hard process termination.

## Technical details

Built using SKILL.md for context management. Uses a Python helper script (token_guard.py) for deterministic budget enforcement. Implements byte-stable prefixing for prompt caching and JSONL-based artifact offloading to local storage. Compatible with agents that support local file system access and system prompt extensions.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Token-Guard — Caching & Autonomy Optimizer skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does Token Guard help reduce my API bills?

Token Guard uses cache-aware compaction to keep context prefixes stable, significantly increasing the likelihood of provider-side cache hits and reducing input token costs by up to 80%.

### Which AI agents and IDEs are compatible with this skill?

It is designed for any agent that supports SKILL.md integration, with optimized workflows for Claude Code, Cursor, and Gemini CLI environments.

### What exactly is included in the purchase?

You receive the core SKILL.md instruction protocol, a set of Python helper scripts for budget enforcement, and documentation for setting up the local JSONL artifact storage.

### How does the artifact offloading feature prevent context overflow?

Token Guard moves verbose tool outputs and data to local JSONL files, replacing them with one-line pointers so the agent remembers *where* information is without it clogging the context window.

### Can I set specific limits on how many tokens an agent can spend per task?

Yes, the included budget enforcement scripts allow you to set deterministic hard caps on iterations and token spend, preventing agents from entering expensive infinite loops.

### Is there a complex setup process for the local file system access?

Installation is straightforward: you simply add the SKILL.md file to your agent's project directory and ensure the agent has permissions to write to a local artifacts folder.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
