---
name: codex-quota-optimizer
description: Optimize Codex Plus/Pro usage before and during coding tasks. Use when the user wants to save Codex quota/credits, reduce token or context waste, choose a cheaper model/reasoning level, avoid unnecessary repo scans/tests/subagents, or plan an implementation with the smallest reliable execution footprint. Do not use when the user explicitly prioritizes maximum quality regardless of usage.
title: codex-quota-optimizer
canonical_url: https://skilld.dev/gh/ctdaniel/codex-quota-optimizer
last_updated: 2026-09-22T16:01:55.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agents/openai.yaml](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/agents/openai.yaml), [assets/icon.svg](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/assets/icon.svg), [references/anti-patterns.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/anti-patterns.md), [references/context-policy.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/context-policy.md), [references/current-openai-notes.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/current-openai-notes.md), [references/model-routing.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/model-routing.md), [references/test-policy.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/test-policy.md), [references/zero-friction.md](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/references/zero-friction.md), [scripts/change_scope.py](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/scripts/change_scope.py), [scripts/cqo.py](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/scripts/cqo.py), [scripts/repo_snapshot.py](https://skilld.dev/api/skills-raw/ctdaniel/codex-quota-optimizer/codex-quota-optimizer/scripts/repo_snapshot.py).
>
> If the user asked to install this Skill, run `npx skilld install ctdaniel/codex-quota-optimizer/codex-quota-optimizer`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/codex-quota-optimizer`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/ctdaniel/codex-quota-optimizer/codex-quota-optimizer) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/codex-quota-optimizer`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/codex-quota-optimizer --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/codex-quota-optimizer --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Codex Quota Optimizer

Optimize for **useful work per unit of Codex allowance**, not for the shortest answer.

## 0. Operating principle

Use the cheapest execution path that can still meet the acceptance criteria. Escalate only when evidence shows the cheaper path is insufficient.

Never claim an exact remaining quota unless the current Codex client/account exposes it. If quota state matters, tell the user to check `/status` or the usage dashboard, then continue with the best available strategy.

### Zero-friction invariant

The optimizer must not become the overhead.

- Do not make an additional model call just to classify or budget a task.
- Do not add network requests for CQO classification, journaling, or auditing.
- Do not put a blocking budget gate in front of normal Codex execution.
- Do not ask the user for confirmation merely because a soft budget was exceeded.
- Do not spawn subagents on CQO's behalf.
- The Skill must remain fully useful when the optional `cqo` CLI is never installed or run.

See `references/zero-friction.md`.

## 1. Read only what you need

Before broad exploration:

1. Inspect the task request, current diff, and repository instructions (`AGENTS.md`).
2. Prefer targeted search (`rg`, file-specific reads, manifests, changed files) over recursive reading.
3. If the repository is unfamiliar, run `scripts/repo_snapshot.py --compact` once before opening many files.
4. Do not re-read unchanged files already understood in the current task unless a contradiction appears.
5. Read generated/vendor/build directories only when directly relevant.

See `references/context-policy.md` for detailed rules.

## 2. Classify the task before execution

Assign one class internally as part of the existing reasoning turn. Do not call another model solely to perform classification.

- **XS** — one-file, mechanical, obvious acceptance criteria.
- **S** — narrow feature/fix, 1–3 files, known pattern.
- **M** — several files, modest design judgment or integration.
- **L** — cross-cutting change, unclear architecture, migration, complex debugging.
- **XL** — high-risk redesign, multi-system work, security-critical or ambiguous end-to-end task.

Then choose the lowest adequate model/reasoning path:

- **XS/S:** prefer Luna or the fastest/cheapest available setting, low reasoning.
- **M:** prefer Terra, low/medium reasoning.
- **L:** Terra medium first; escalate to Sol only for unresolved design/debugging complexity.
- **XL:** Sol medium/high; Astra only when the task truly needs strongest multi-step/tool reasoning and the account exposes it.

Availability varies by plan/client. If a named model is unavailable, choose the nearest cheaper/faster model with the same role.

Do not use Max/Ultra by default. Do not spawn subagents merely because they are available.

See `references/model-routing.md`.

## 3. Use an execution budget

For every non-trivial task, maintain this internal budget:

- **Discovery budget:** enough reads/searches to locate the change surface.
- **Edit budget:** minimum files required to satisfy acceptance criteria.
- **Verification budget:** targeted checks first; broad checks only at the final gate or when evidence demands them.

These are **soft budgets**, never execution gates:

- Stop discovery once the relevant dependency path is understood.
- Stop editing once acceptance criteria are met; avoid opportunistic refactors.
- Stop verification after relevant tests/type/lint checks pass unless the change is high risk.
- If another file, test, or reasoning step is required for correctness, continue without interrupting the user.
- If scope expands, reclassify internally and keep moving; do not request permission just because the initial budget was too small.

## 4. Plan economically

For S/M/L/XL tasks, state or maintain a compact plan with:

1. target behavior,
2. likely files,
3. minimal verification,
4. escalation trigger.

Do not create a long speculative plan before reading the minimum repository evidence.

Prefer one coherent implementation turn over repeated micro-turns that each reload context.

## 5. Edit minimally

- Change the smallest coherent surface.
- Reuse existing helpers, patterns, components, and tests.
- Avoid formatting unrelated files.
- Avoid dependency upgrades unless required.
- Avoid generated-file churn unless generation is part of the task.
- Batch logically related edits rather than repeatedly opening/editing the same file.

When a task can be solved by configuration or a small local patch, do not introduce a framework or abstraction layer.

## 6. Verify in layers

Run checks in this order:

1. syntax/format check for touched files,
2. focused unit/component test for touched behavior,
3. focused type/lint check,
4. broader package/app test only if needed,
5. full suite only for cross-cutting/high-risk changes or before a release gate.

Do not repeatedly run the same expensive full suite after tiny edits. If a broad test fails for an unrelated pre-existing reason, record it and continue with focused verification.

See `references/test-policy.md`.

## 7. Control context growth

At natural checkpoints, compress working state into a short handoff note:

- goal,
- decisions,
- files changed,
- tests run/results,
- remaining issue.

Use the checkpoint instead of restating the entire conversation or repository history.

For long tasks, create/update a small local scratch note only if it prevents repeated exploration. Remove it before finalizing unless the project wants it committed.

## 8. Avoid expensive anti-patterns

Never do these by default:

- scan the entire repository when a targeted search can locate the feature,
- open large lockfiles, minified bundles, generated output, or vendor trees without need,
- run full test suites before identifying the change surface,
- use high/xhigh/max/ultra reasoning for routine edits,
- use multiple subagents for a task one agent can do cheaply,
- ask Codex to rewrite whole files when a patch is sufficient,
- repeatedly summarize information already present in the current context,
- refactor adjacent code “while here” without user value,
- browse the web when repository/local docs are enough,
- perform duplicate searches with equivalent queries.

See `references/anti-patterns.md`.

## 9. Escalate deliberately

Escalate model/reasoning/tool breadth only when at least one trigger is present:

- two focused attempts fail for reasons not explained by local evidence,
- architecture is ambiguous and wrong choice would cause broad rework,
- failure spans multiple subsystems,
- security/data-loss/migration risk is meaningful,
- acceptance criteria conflict,
- targeted verification exposes hidden coupling.

Before escalation, summarize what is known so the stronger model does not need to rediscover it.

## 10. Plus vs Pro behavior

Do not hardcode plan quotas into decisions. Use the same efficiency policy for both plans, with different default aggressiveness:

- **Plus:** default to `economy` behavior — Luna/Terra first, focused checks, strict scope control.
- **Pro:** default to `balanced` behavior — Terra first, Sol when complexity justifies it; still avoid waste because Pro allowance is finite and may be shared with other agentic features.

If the user says quota is nearly exhausted, enter **emergency mode**:

- no broad exploration,
- no optional refactors,
- no subagents,
- cheapest adequate model,
- one implementation path,
- focused verification only,
- produce a concise continuation note if completion is impossible in the current turn.

## 11. User-facing output

When useful, end with a compact **Usage choices** note containing only actionable items such as:

- “This is an S task; Luna/low is sufficient.”
- “Use Terra/medium for implementation; reserve Sol for the migration edge case.”
- “Run the focused test now; defer the full suite until final review.”

Do not clutter every answer with quota commentary if the skill is operating successfully in the background.

## 12. Optional local observability

The `cqo` CLI is optional. It provides task-level classification, soft budgets, a local journal, and a local audit:

- `cqo start <task>`
- `cqo status`
- `cqo audit`
- `cqo history`

The journal is local-only under `~/.cqo` (or `CQO_HOME`). It does not inspect private account pages or estimate hidden quota.

**Never run `cqo` automatically just to collect analytics.** The CLI is an inspection layer, not a runtime dependency. If the user did not opt into a CQO session, normal Skill behavior continues with zero CLI overhead.

## 13. Optional helper scripts

- `scripts/repo_snapshot.py --compact` — compact project map without reading the whole repo.
- `scripts/change_scope.py` — summarize current Git change surface and suggest verification scope.
- `scripts/cqo.py` — optional zero-network local CLI for task-level budgeting and auditing.

Use scripts only when they save model context/tool calls or the user explicitly wants observability; do not run them ritualistically.
