Skip to content
Back to skills

Opt Loop

ASecurity

Enforces cost discipline and cache-aware pacing for autonomous agent loops and recurring cron tasks. Prevents runaway token consumption through prompt-cache alignment, short-circuit checks, and hard exit stops.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
ai-agentsgoshellrailsgit

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add airshell/ai-optimizer --skill opt-loop --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Opt Loop?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Opt Loop
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-opt-loop/badge)](https://www.skillsdirectory.com/skills/airshell-opt-loop)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: opt-loop
description: >-
  Enforces cost discipline and cache-aware pacing for autonomous agent loops
  and recurring cron tasks. Prevents runaway token consumption through
  prompt-cache alignment, short-circuit checks, and hard exit stops.
license: MIT
metadata:
  origin: AI Optimizer
  maintainer: Airshell (https://github.com/airshell)
---

# Autonomous Loop & Cron Budget Control (`opt-loop`)

In recurring agent tasks and autonomous execution loops, token costs compound multiplicatively (`cost = per_turn × iterations`). This skill enforces strict budget guardrails to prevent token waste and runaway background spending.

## When to Use

- When configuring scheduled cron tasks or recurring loop instructions
- When running long-lived background monitoring agents
- To prevent prompt-cache misses during automated tasks

## The 5 Cost Guardrails

### 1. Pace to the Prompt Cache (Banish the Dead Zone)
Modern LLM prompt caches typically have a 5-minute (300-second) TTL.
- **Active polling**: Run `< 270s` to ensure the prompt cache stays warm (saving up to 80% on input tokens).
- **Idle intervals**: Step up to `≥ 1200s` so the cost of a cache miss is amortized over a long idle period.
- **Never schedule near ~300s**: The 290s–330s window is the worst possible choice — it incurs the full cost of a cache miss without amortizing the wait.

### 2. Short-Circuit When Nothing Changed
Re-generating responses on empty runs is the single largest source of recurring loop waste:
- Check a lightweight timestamp, file mtime, git hash (`git rev-parse HEAD`), or status flag first.
- If there is no new work, emit a single status line (`tick N: no changes`) and reschedule without re-analyzing the workspace.

### 3. Event-Driven Triggers Over Active Polling
- Leverage asynchronous notifications and process exit events whenever available rather than polling in tight loops.
- Fall back to slow heartbeats (`1200s+`) for monitoring external services.

### 4. Carry a Compact State Handle
- Store progress in a lightweight JSON state file (`.optimizer/state.json`).
- Read only the state file each tick — never re-discover the entire project history from scratch.

### 5. Define a Clear Exit Condition
- Every loop must have an explicit stop condition: goal reached, maximum iterations hit, or a deadline.
- Unbounded loops are strictly prohibited.

## Output Discipline
During recurring ticks where no human intervention is needed, emit minimal one-line status updates. Save full reports exclusively for when meaningful changes or errors occur.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.