Rate limit management

From grandamenium/cortextos · View interactive version

Rate limit management is an AI agent skill from the GitHub repository grandamenium/cortextos. Framework protocol for responding to Claude Max API usage thresholds. Three-tier wind-down and recovery. Agent-specific behavior belongs in deployment config, not here.

How to use this skill

Skill file

Rate Limit Management Protocol

Framework-level protocol. Defines tiers and check mechanism only.

Agent-specific behavior at each tier belongs in your deployment's CLAUDE.md or config.json.


Usage Check Command

cortextos bus check-usage-api [--warn-7day N] [--warn-5h N] [--chat-id ID] [--force]

Reads Claude Max utilization from the Anthropic OAuth usage API. Outputs JSON with five_hour and seven_day utilization fields.

Options:

| Flag | Default | Description |

|------|---------|-------------|

| --warn-7day N | 80 | Send Telegram alert if 7-day utilization >= N% |

| --warn-5h N | 90 | Send Telegram alert if 5-hour utilization >= N% |

| --chat-id ID | $CTX_TELEGRAM_CHAT_ID | Telegram chat ID for alerts |

| --force | false | Bypass 3-minute result cache |

Cache: Results are cached for 3 minutes at $CTX_ROOT/state/usage/api-cache.json to avoid hitting the API hard limit (~5 requests per token before 429).

Requirements: macOS Keychain with Claude Code credentials. The script reads the OAuth access token from the Claude Code-credentials Keychain entry.


Three-Tier Protocol

Tier 1 — Wind-Down (>= 85% utilization)

Signal: Usage is high but work can still complete safely.

Agent behavior:

Cron behavior: Suspend scheduled/proactive cron work. Keep inbox-check and heartbeat crons running.


Tier 2 — Minimal (85-95% utilization)

Signal: Usage is critically high. New work risks hitting the hard limit mid-task.

Agent behavior:

Cron behavior: Suspend all crons except heartbeat.


Tier 3 — Dark (>= 95% utilization)

Signal: Approaching or at hard limit. Further work risks broken mid-task state.

Agent behavior:

```

Rate limit at [N]%. Going dark until reset. Will notify when back online. Resets at [time].

```


Recovery

Reset condition: Utilization drops below 20% (confirmed via usage check).

On recovery:

```

Rate limit reset. Back online. Resuming normal operations.

```


Recommended Cron: Usage Check

Check usage every 15 minutes and apply tier logic:

{
  "name": "usage-check",
  "interval": "15m",
  "prompt": "Run cortextos bus check-usage-api and apply the rate limit protocol from .claude/skills/rate-limit-management/SKILL.md based on current utilization."
}

Configurable thresholds: The --warn-7day and --warn-5h flags on check-usage-api are independent early-warning alerts sent to Telegram. They fire below the tier thresholds defined above and serve as a heads-up before tier behavior kicks in.

Recommended warn thresholds:


What Belongs Here vs. Deployment Config

This skill defines:

Your deployment config should define:


Quick Reference

| Utilization | Tier | Behavior |

|-------------|------|---------|

| < 85% | Normal | Full operations |

| 85-94% | Wind-Down | Finish current task; no new autonomous work |

| 85-95% | Minimal | Direct messages only; no scheduled work |

| >= 95% | Dark | Go silent; notify user; wait for reset |

| < 20% (after reset) | Recovery | Resume all operations; notify user |


Framework protocol — no AscendOps-specific content. Agent behavior at each tier is deployment-defined.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.