agentleFS
telegraphic-devtelegraphic-dev/am-i-cooked/skills/quota-gate/SKILL.md

quota-gate

Skill4 starsChanged 5 months agoMITView on GitHub

Use before expensive, long-running, automated, or quota-sensitive AI coding agent work to check subscription quota and fail closed when quota is low or unknown.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. ryanmaclean/skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 6 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Default provider is claude, because this skill is currently installed into Claude Code.

    line 19
  2. Distinctive:

    Before doing the expensive work, run:

    line 25
  3. Distinctive:

    Never estimate provider quota from conversation context.

    line 81
  4. Distinctive:

    Never continue if the quota check fails.

    line 82
  5. Very specific:

    Never ask for manual token input unless quota-gate explicitly reports a missing credential/API-key reason for the selected provider.

    line 83
  6. Distinctive:

    Treat any non-zero exit as a hard stop for the expensive routine.

    line 84
  7. Distinctive:

    Do not use MCP for this skill.

    line 85
  8. Distinctive:

    Do not print or request access tokens or refresh tokens.

    line 86
  9. Very specific:

    If exit 0, continue. If exit 2, return only:

    line 102
  10. Very specific:

    If exit 1, return only:

    line 108

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Quota Gate

Overview

Use this skill before expensive, long-running, automated, or quota-sensitive AI coding agent routines. It runs a bundled Node.js gate that checks subscription quota and returns a machine-readable allow/skip decision. It supports direct Claude Code and Codex usage checks using local CLI credentials; no resident OpenUsage app is required.

Default provider is claude, because this skill is currently installed into Claude Code. For Codex quota checks, pass --provider=codex explicitly.

The gate fails closed. If quota is low, unknown, credentials are missing, the endpoint errors, or the response shape is invalid, do not continue with the requested work.

Required Check

Before doing the expensive work, run:

scripts/quota-gate --weekly-min=<N> --five-hour-min=<M>

For automatic Claude Code enforcement, install/enable the bundled plugin. Claude Code reads hooks/hooks.json from the plugin and runs the UserPromptSubmit hook automatically. The hook command is:

${CLAUDE_PLUGIN_ROOT}/skills/quota-gate/scripts/claude-quota-hook

The hook runs this gate only when the prompt looks quota-sensitive, and blocks the prompt if quota is below its hard floor or unknown. It conforms to Claude Code's expected format: exit 0, no stdout to allow, and stdout containing only {"decision":"block","reason":"..."} to block.

The plugin hook uses conservative default hard floors (10% weekly and 10% five-hour remaining) so it only stops expensive prompts near exhaustion. The standalone quota-gate command keeps a stricter weekly default for explicit/manual checks.

Optional environment controls:

  • QUOTA_GATE_WEEKLY_MIN=<0..100> to override the hook's weekly hard floor. Default: 10.
  • QUOTA_GATE_FIVE_HOUR_MIN=<0..100> to override the hook's five-hour hard floor. Default: 10.
  • QUOTA_GATE_CACHE_TTL_SECONDS=<n> to set the usage cache freshness window.
  • QUOTA_GATE_NO_CACHE=1 to bypass the usage cache.
  • QUOTA_GATE_DEBUG=1 to print token-redacted diagnostics to stderr.
  • QUOTA_GATE_HOOK_PATTERN=<javascript-regex> to override the trigger heuristic.
  • QUOTA_GATE_HOOK_ALWAYS=1 to check every prompt.

For Codex quota checks, select the Codex provider explicitly:

scripts/quota-gate --provider=codex --weekly-min=<N> --session-min=<M>

Thresholds are minimum remaining percentages.

Default thresholds:

  • --weekly-min=50
  • --five-hour-min=0

Exit Code Contract

  • Exit 0: quota is sufficient; continue with the requested work.
  • Exit 2: quota is below threshold; stop and return only:
{"status":"skipped","reason":"low_ai_quota"}
  • Exit 1: quota is unknown because of missing credentials, auth failure, endpoint error, invalid response, or internal error; stop and return only:
{"status":"skipped","reason":"unknown_ai_quota"}

Rules

  1. Never estimate provider quota from conversation context.
  2. Never continue if the quota check fails.
  3. Never ask for manual token input unless quota-gate explicitly reports a missing credential/API-key reason for the selected provider.
  4. Treat any non-zero exit as a hard stop for the expensive routine.
  5. Do not use MCP for this skill.
  6. Do not print or request access tokens or refresh tokens.

Examples

Example 1

User prompt:

Use quota-gate. Execute this only if weekly quota remaining is above 50%; otherwise do nothing.

Expected action:

scripts/quota-gate --weekly-min=50

If exit 0, continue. If exit 2, return only:

{"status":"skipped","reason":"low_ai_quota"}

If exit 1, return only:

{"status":"skipped","reason":"unknown_ai_quota"}

Example 2

User prompt:

Run this refactor only if I have at least 30% of five-hour quota and 60% weekly quota left.

Expected action:

scripts/quota-gate --weekly-min=60 --five-hour-min=30

Example 3

User prompt:

Use Codex only if weekly quota remaining is at least 50%.

Expected action:

scripts/quota-gate --provider=codex --weekly-min=50

Output Shape

The script always prints JSON. resets_at is preserved when the endpoint provides it. When reset time is known, each usage window can include advisory pacing metadata showing whether usage is faster than a linear budget for that window.

Allowed:

{
  "allowed": true,
  "reason": "ok",
  "thresholds": {
    "weekly_min_remaining_pct": 50,
    "five_hour_min_remaining_pct": 20
  },
  "usage": {
    "five_hour": {
      "used_pct": 10,
      "remaining_pct": 90,
      "resets_at": "..."
    },
    "weekly": {
      "used_pct": 40,
      "remaining_pct": 60,
      "resets_at": "..."
    }
  }
}

Skipped due to low quota:

{
  "allowed": false,
  "reason": "below_threshold",
  "thresholds": {
    "weekly_min_remaining_pct": 50,
    "five_hour_min_remaining_pct": 20
  },
  "usage": {
    "five_hour": {
      "used_pct": 85,
      "remaining_pct": 15,
      "resets_at": "..."
    },
    "weekly": {
      "used_pct": 55,
      "remaining_pct": 45,
      "resets_at": "..."
    }
  }
}

Unknown quota:

{"allowed":false,"reason":"missing_claude_code_credentials"}

or:

{"allowed":false,"reason":"usage_endpoint_429"}

Verification Checklist

  • Ran scripts/quota-gate before expensive work, or verified the Claude Code hook ran it.
  • Continued only on exit 0.
  • Returned the exact low-quota JSON on exit 2.
  • Returned the exact unknown-quota JSON on exit 1.
  • If using the hook, it blocks quota-sensitive prompts on low/unknown quota and stays silent when quota is sufficient.
  • Did not ask for or print OAuth tokens, API keys, or credential files.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.