Repository navigation
Review gates step aside when the Codex quota is nearly spent - #38
Open
razbenaharon wants to merge 1 commit into
Open
razbenaharon wants to merge 1 commit into
razbenaharon wants to merge 1 commit into
Conversation
The consultation gate (PreToolUse) and the review gate (Stop) asked for a Codex call even while the user's Codex 5-hour window was at 99%, against the user's own rule of no new Codex jobs at 80% (5-hour) or 90% (weekly). The hook now reads a quota snapshot the user's own tooling writes (codex-quota.json in the state root, or preferences.json codex_quota_file), with limits quota_hold_five_hour (default 80) and quota_hold_weekly (default 90). At or above a limit, neither gate stops anything and no reminder asks for Codex; where a gate would have stopped, the user is told once, with the reset time, and the ledger records quota_skipped_review or quota_skipped_consult. A missing, unreadable or already-reset snapshot is unknown and keeps today's behaviour. The quota does not come from Codex's logs: those are Codex rollout files, which the hook must never open (invariant 6), and the status tool has no quota and cannot be called from a hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On 2026-12-01 the Codex 5-hour window was at 99%, yet the PreToolUse consultation gate denied a Write and the Stop review gate demanded a
review_gatecall. The user's own rule is no new Codex jobs at 80% (5-hour) or 90% (weekly), so the gates and the rule contradicted each other.Where the quota comes from
Not from Codex's logs and not from the
statustool:~/.codex/sessions/*.jsonlare Codex rollout files (full conversation text). Invariant 6 says the hook never opens a conversation file, and the "no quota reading" stance was deliberate.statusreports no quota, and a hook cannot call an MCP tool.Instead the hook reads a small snapshot the user's own tooling writes:
<state root>/codex-quota.json, or the path inpreferences.jsonundercodex_quota_file. Its shape is{"captured_at": ..., "rate_limits": <Codex's own rate_limits object>}, at most 64 KiB.Behaviour
Limits in
preferences.json:quota_hold_five_hour(default 80) andquota_hold_weekly(default 90). A value must be above 0 and at most 100; anything else falls back to the default.At or above a limit:
Where a gate would have stopped, the user gets one line (
systemMessage) with the window, the % used, the limit and the reset time. The ledger recordsquota_skipped_consultorquota_skipped_review, andmodelquad review reportshows the counts.Below the limits, or unknown (no file, malformed, or the window's
resets_atalready passed): exactly today's behaviour.The quota is read only when a gate or reminder is about to act.
Tests
tests/test_quota_hold.py(30 tests) covers:Full suite:
python scripts/check.py fastandpython scripts/check.py pythonboth pass.Not in this PR
Nothing writes the snapshot yet. Until the user's own quota script writes it, the gates behave as before.
🤖 Generated with Claude Code