optimize-agent-usage
Use when Claude Code or Codex runs out of usage before the day or week is over, when asked to make a plan's limit or quota last longer, cut token use, or move work to cheaper models without the work getting worse. Checks which model names and settings the installed version accept
Install
npx skills add https://github.com/Heyvhuang/copybook-skills/tree/main/plugins/skills/skills/optimize-agent-usage
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install heyvhuang-copybook-skills@llmmart
git clone https://github.com/Heyvhuang/copybook-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole heyvhuang/copybook-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Make agent usage last without worse work
Most of a session is routine: reading, searching, small edits, running tests. Those turns don't need the strongest model. Move the routine to a cheaper model, keep the strong one for plans and the reviews the user names, and measure before you call it a saving.
Model names, settings and features change between versions faster than your training data. Look them up on this machine; don't write one from memory.
Settings files hold secrets
Settings files can carry API keys, tokens and hook or MCP headers anywhere, in comments too. Never print a settings or config file, or any line of one, in any step or in the report. Read them only with this skill's script, scripts/read_model_settings.py in this skill's folder, run with the repo as the working directory. It parses each file and prints only model names, effort levels, variable names and fixed messages; a value that is not a plain name prints as set, not a plain name.
Edit by replacing one field in place (a short script or sed -i on that one key) without printing the file.
1. Read the current setup
Find which agent the repo uses: .claude/ and CLAUDE.md for Claude Code, .codex/ and AGENTS.md for Codex. Change only the agent the repo uses. Note every rule about tests, builds and reviews: they all stay.
Claude Code: python3 <skill folder>/scripts/read_model_settings.py claude. It reads the managed, local, project and user settings files ($CLAUDE_CONFIG_DIR if set), each agent file's frontmatter, which model variables are set in the shell or a settings env, by name, whether an MDM policy file is present, and the flags this session was launched with, by name. The highest file that sets model wins, ANTHROPIC_MODEL beats every file, and --model or --settings at launch beat both.
Settings from the organization's server don't show in any file. /status in the user's session lists every setting source. Ask the user for that line when the script reports an MDM file, unknown launch flags, or the user is on a Team or Enterprise plan. If a managed source or a launch flag decides the model, or you can't tell which source wins, stop and tell the user what you found. Don't edit around it.
Codex: python3 <skill folder>/scripts/read_model_settings.py codex (Python 3.11 or later). It reads $CODEX_HOME/config.toml (or ~/.codex/config.toml) with its profiles and agents, /etc/codex/config.toml, and every .codex/config.toml from the repo root down to the working directory with whether that directory is trusted, plus the launch flags by name. Codex skips an untrusted project's files. MDM and cloud-managed config don't show in files; if the user's organization manages Codex, ask for the model line of /status in Codex.
Settings in the user's home folder and managed settings affect every project. Propose changes there and wait for a yes.
2. Look up what this version accepts
Claude Code:
claude --version, and the model docs for that version: https://code.claude.com/docs/en/model-config.opusplanand the advisor (https://code.claude.com/docs/en/advisor) are both there;--advisoris not listed inclaude --help.- The aliases
opus,sonnetandhaikufollow the installed version's defaults, unless anANTHROPIC_DEFAULT_*_MODELvariable remaps them. Prefer the aliases over full model IDs.
Codex:
codex debug modelslists the models Codex sees for this account and provider, with a description and the reasoning levels each one supports. Use only slugs and effort levels from that list.codex --version.
3. Claude Code: Sonnet works, Opus for plans
Write the main model into .claude/settings.local.json, the user's own file for this repo, editing model in place if it is already there and keeping every other key. Write .claude/settings.json only if the user asks to change the default for everyone on the repo.
{
"model": "sonnet"
}
If the user wants Opus to keep doing the planning, use "model": "opusplan" instead: Opus while in plan mode, Sonnet for everything else.
Then, in .claude/agents/:
- Agents that only read, search or look up docs:
model: haiku. - Agents that edit code or run tests:
model: sonnet. - An agent the user names as high-stakes (payment or security review): keep it on
opusand say why it stays. - No agent that only reads and searches yet: add one,
.claude/agents/explorer.md, withtools: Read, Grep, Glob,model: haiku, and a description that says to use it for finding files and reading code.
Change only the model line of an existing agent. Leave its description, tools and instructions as they are. Agent files in .claude/agents/ are shared with everyone on the repo, so say so in the report.
Say plainly when something from step 1 defeats the change, and don't work around it:
- Managed settings, a launch flag or
ANTHROPIC_MODELset the model: the file edit won't take effect. Tell the user where it comes from. CLAUDE_CODE_SUBAGENT_MODELwithCLAUDE_CODE_SUBAGENT_MODEL_FORCEputs every subagent on one model, the named reviewer included. Without_FORCE, an agent's ownmodelline wins.advisorModelis already set (our tip suggested it): say that each advisor call sends the whole conversation to the advisor again with no cache, so it adds usage. Remove it only with a yes.
Don't add the advisor to save usage. In Copybook's two runs (coding tasks of 3 to 7 turns, December 2026), Sonnet with an Opus advisor cost 1.4 and 1.7 times as much as Opus alone at list price. Offer it only as a quality option, and say it costs more.
Don't use these as the saving either:
- Banning subagents. Subagents are where cheap models take the reading load, so a ban moves that reading onto the main model.
- Lower effort for everything. That is how the work gets worse.
4. Codex: a lighter default, the heavy model on call
In .codex/config.toml:
- Keep
modelon the listed go-to coding model. - Set
model_reasoning_effortto a middle level from that model's list (usuallymedium) for everyday turns. - Set
plan_mode_reasoning_effortto the high level the user had, so plans keep it.
In .codex/agents/*.toml, give lookup and search agents the model whose description says fast or affordable, with its lowest listed effort above none. Keep reviewers on the stronger model.
Write no Claude Code settings into a Codex repo, or Codex settings into a Claude Code one.
5. Check the setup that wins
Claude Code:
- Run the script's
claudetask again. The file that wins formodelshows the new value, and nothing above it overrides it. python3 <skill folder>/scripts/read_model_settings.py claude-checkruns one shortclaude -pand prints only the names of the models that answered. Withopusplanit shows Sonnet, since-pdoes not plan. This is a new session: it shows what the files give, not the user's current session if that was launched with--modelor--settings.- For agents,
/tasksnames the model on each running subagent's row.
Codex: python3 <skill folder>/scripts/read_model_settings.py codex-check runs codex exec --strict-config --sandbox read-only --ephemeral "reply ok" in the repo, which fails on an unknown key in config.toml before any work starts and spends one short turn. It prints only the exit code, the unknown key's name and these fixed lines:
Untrusted project-local configuration is disabled: Codex skipped the project's.codex/files, so nothing was validated. Report the check as pending. Trusting a project lets its MCP commands run outside the sandbox, so leave that to the user; never add--trustyourself.Ignoring malformed agent role definition: an agent file has a bad key, and Codex dropped that agent.
6. Report
- Each file changed, with the old and new value of the fields you changed.
- What stayed on the strong model, and why.
- Anything that overrides the change, and what you proposed for the home folder or managed settings and did not write.
- The saving, only if you measured it. Run one task the user does often, before and after. Claude Code:
claude -p --output-format jsonreportstotal_cost_usdand tokens per model inmodelUsage. Codex:codex exec --jsonreports tokens in itsturn.completedline. Tokens on differently priced models are not a saving by themselves; compare list cost, or the plan's own meter (/usagein either tool) before and after. Otherwise call it a plan to measure, not a saving.
Based on Copybook's own tips (CC BY 4.0), written by Copybook.
Files (copybook-skills)
-
scripts
-
read_model_settings.py 9.7 KB
Loading…
-
-
CHANGES.md 6.1 KB
Loading… -
example.md 3.2 KB
Loading… -
LICENSE 18.2 KB · in bundle
-
SKILL.md 9 KB
--- name: optimize-agent-usage description: "Use when Claude Code or Codex runs out of usage before the day or week is over, when asked to make a plan's limit or quota last longer, cut token use, or move work to cheaper models without the work getting worse. Checks which model names and settings the installed version accepts and which settings win, puts routine work on a cheaper main model with the strongest one kept for plans and named high-stakes reviews, sends lookup subagents to the fastest model, keeps every test and review rule, and validates the config it writes. Not for building new specialist agents from scratch." license: CC-BY-4.0 (see LICENSE) --- # Make agent usage last without worse work Most of a session is routine: reading, searching, small edits, running tests. Those turns don't need the strongest model. Move the routine to a cheaper model, keep the strong one for plans and the reviews the user names, and measure before you call it a saving. Model names, settings and features change between versions faster than your training data. Look them up on this machine; don't write one from memory. ## Settings files hold secrets Settings files can carry API keys, tokens and hook or MCP headers anywhere, in comments too. Never print a settings or config file, or any line of one, in any step or in the report. Read them only with this skill's script, `scripts/read_model_settings.py` in this skill's folder, run with the repo as the working directory. It parses each file and prints only model names, effort levels, variable names and fixed messages; a value that is not a plain name prints as `set, not a plain name`. Edit by replacing one field in place (a short script or `sed -i` on that one key) without printing the file. ## 1. Read the current setup Find which agent the repo uses: `.claude/` and `CLAUDE.md` for Claude Code, `.codex/` and `AGENTS.md` for Codex. Change only the agent the repo uses. Note every rule about tests, builds and reviews: they all stay. Claude Code: `python3 <skill folder>/scripts/read_model_settings.py claude`. It reads the managed, local, project and user settings files (`$CLAUDE_CONFIG_DIR` if set), each agent file's frontmatter, which model variables are set in the shell or a settings `env`, by name, whether an MDM policy file is present, and the flags this session was launched with, by name. The highest file that sets `model` wins, `ANTHROPIC_MODEL` beats every file, and `--model` or `--settings` at launch beat both. Settings from the organization's server don't show in any file. `/status` in the user's session lists every setting source. Ask the user for that line when the script reports an MDM file, unknown launch flags, or the user is on a Team or Enterprise plan. If a managed source or a launch flag decides the model, or you can't tell which source wins, stop and tell the user what you found. Don't edit around it. Codex: `python3 <skill folder>/scripts/read_model_settings.py codex` (Python 3.11 or later). It reads `$CODEX_HOME/config.toml` (or `~/.codex/config.toml`) with its profiles and agents, `/etc/codex/config.toml`, and every `.codex/config.toml` from the repo root down to the working directory with whether that directory is trusted, plus the launch flags by name. Codex skips an untrusted project's files. MDM and cloud-managed config don't show in files; if the user's organization manages Codex, ask for the model line of `/status` in Codex. Settings in the user's home folder and managed settings affect every project. Propose changes there and wait for a yes. ## 2. Look up what this version accepts Claude Code: - `claude --version`, and the model docs for that version: https://code.claude.com/docs/en/model-config. `opusplan` and the advisor (https://code.claude.com/docs/en/advisor) are both there; `--advisor` is not listed in `claude --help`. - The aliases `opus`, `sonnet` and `haiku` follow the installed version's defaults, unless an `ANTHROPIC_DEFAULT_*_MODEL` variable remaps them. Prefer the aliases over full model IDs. Codex: - `codex debug models` lists the models Codex sees for this account and provider, with a description and the reasoning levels each one supports. Use only slugs and effort levels from that list. - `codex --version`. ## 3. Claude Code: Sonnet works, Opus for plans Write the main model into `.claude/settings.local.json`, the user's own file for this repo, editing `model` in place if it is already there and keeping every other key. Write `.claude/settings.json` only if the user asks to change the default for everyone on the repo. ```json { "model": "sonnet" } ``` If the user wants Opus to keep doing the planning, use `"model": "opusplan"` instead: Opus while in plan mode, Sonnet for everything else. Then, in `.claude/agents/`: - Agents that only read, search or look up docs: `model: haiku`. - Agents that edit code or run tests: `model: sonnet`. - An agent the user names as high-stakes (payment or security review): keep it on `opus` and say why it stays. - No agent that only reads and searches yet: add one, `.claude/agents/explorer.md`, with `tools: Read, Grep, Glob`, `model: haiku`, and a description that says to use it for finding files and reading code. Change only the `model` line of an existing agent. Leave its description, tools and instructions as they are. Agent files in `.claude/agents/` are shared with everyone on the repo, so say so in the report. Say plainly when something from step 1 defeats the change, and don't work around it: - Managed settings, a launch flag or `ANTHROPIC_MODEL` set the model: the file edit won't take effect. Tell the user where it comes from. - `CLAUDE_CODE_SUBAGENT_MODEL` with `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` puts every subagent on one model, the named reviewer included. Without `_FORCE`, an agent's own `model` line wins. - `advisorModel` is already set (our tip suggested it): say that each advisor call sends the whole conversation to the advisor again with no cache, so it adds usage. Remove it only with a yes. Don't add the advisor to save usage. In Copybook's two runs (coding tasks of 3 to 7 turns, December 2026), Sonnet with an Opus advisor cost 1.4 and 1.7 times as much as Opus alone at list price. Offer it only as a quality option, and say it costs more. Don't use these as the saving either: - **Banning subagents.** Subagents are where cheap models take the reading load, so a ban moves that reading onto the main model. - **Lower effort for everything.** That is how the work gets worse. ## 4. Codex: a lighter default, the heavy model on call In `.codex/config.toml`: - Keep `model` on the listed go-to coding model. - Set `model_reasoning_effort` to a middle level from that model's list (usually `medium`) for everyday turns. - Set `plan_mode_reasoning_effort` to the high level the user had, so plans keep it. In `.codex/agents/*.toml`, give lookup and search agents the model whose description says fast or affordable, with its lowest listed effort above none. Keep reviewers on the stronger model. Write no Claude Code settings into a Codex repo, or Codex settings into a Claude Code one. ## 5. Check the setup that wins Claude Code: - Run the script's `claude` task again. The file that wins for `model` shows the new value, and nothing above it overrides it. - `python3 <skill folder>/scripts/read_model_settings.py claude-check` runs one short `claude -p` and prints only the names of the models that answered. With `opusplan` it shows Sonnet, since `-p` does not plan. This is a new session: it shows what the files give, not the user's current session if that was launched with `--model` or `--settings`. - For agents, `/tasks` names the model on each running subagent's row. Codex: `python3 <skill folder>/scripts/read_model_settings.py codex-check` runs `codex exec --strict-config --sandbox read-only --ephemeral "reply ok"` in the repo, which fails on an unknown key in `config.toml` before any work starts and spends one short turn. It prints only the exit code, the unknown key's name and these fixed lines: - `Untrusted project-local configuration is disabled`: Codex skipped the project's `.codex/` files, so nothing was validated. Report the check as pending. Trusting a project lets its MCP commands run outside the sandbox, so leave that to the user; never add `--trust` yourself. - `Ignoring malformed agent role definition`: an agent file has a bad key, and Codex dropped that agent. ## 6. Report - Each file changed, with the old and new value of the fields you changed. - What stayed on the strong model, and why. - Anything that overrides the change, and what you proposed for the home folder or managed settings and did not write. - The saving, only if you measured it. Run one task the user does often, before and after. Claude Code: `claude -p --output-format json` reports `total_cost_usd` and tokens per model in `modelUsage`. Codex: `codex exec --json` reports tokens in its `turn.completed` line. Tokens on differently priced models are not a saving by themselves; compare list cost, or the plan's own meter (`/usage` in either tool) before and after. Otherwise call it a plan to measure, not a saving. Based on Copybook's own tips (CC BY 4.0), written by Copybook.
Reviews (0)
No reviews yet.
Comments
Sign in to join the conversation.
No comments yet. Start the conversation.