optimize

optimize is a skill for Claude Code from ictechgy/context-guard. It costs 62 tokens per session (769 once invoked), scanned B, original, Apache-2.0.

A guide for diagnosing and reducing Claude Code's token use, meaning the amount of text processed during a coding session. It covers context size, model selection, tool connections, output cleanup, and subagent use.

In plain words
What is it for?
Use it to measure usage, find the largest sources of waste, trim project context, read only relevant parts of files, clean large outputs, and review local usage logs.
Why use it?
Unneeded history, large files, oversized tool descriptions, and repeated output can consume tokens and raise costs or usage-limit pressure.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: reads .claude/ paths; mentions CLAUDE.md; mentions subagents.

Part of the context-guard plugin — 3 skills shipped together

Good fit Use it to measure usage, find the largest sources of waste, trim project context, read only relevant parts of files, clean large outputs, and review local usage logs.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ictechgy/context-guard/optimize
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ictechgy/context-guard --skill optimize
Clone the repo
git clone --depth 1 https://github.com/ictechgy/context-guard

Made for: Claude Code.

Or install context-guard, the plugin that ships this one along with the rest of its 3 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for optimize

README.md
[![agentmods](https://agentmods.dev/badge/skills/ictechgy/context-guard/optimize/github.svg)](https://agentmods.dev/skills/ictechgy/context-guard/optimize)
Your own site
<a href="https://agentmods.dev/skills/ictechgy/context-guard/optimize"><img src="https://agentmods.dev/badge/skills/ictechgy/context-guard/optimize/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for optimize

Your own site · 80×15
<a href="https://agentmods.dev/skills/ictechgy/context-guard/optimize"><img src="https://agentmods.dev/badge/skills/ictechgy/context-guard/optimize.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 62 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 769 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00062 $0.00769
Opus 5.5 $0.00025 $0.00308
Sonnet 5.5 $0.00012 $0.00154
Haiku 4.5 $0.00006 $0.00077

Measured 1mo ago against content hash 6b60918eddd1, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade B, and why

optimize scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

If installing hook examples, prefer project-local opt-in settings first. Do not silently modify global `~/.claude/settings.json`.
plugins/context-guard/skills/optimize/SKILL.md · 50 lines

What it actually says

ContextGuard

Goal: reduce Claude Code token usage without lowering task success quality.

Use this order:

  1. Measure before changing behavior.
    • Ask the user to run /usage and /context if inside Claude Code.
    • For first-time setup, run context-guard-setup --plan and offer context-guard-setup --yes for recommended project-local settings.
    • If transcript files are available, run context-guard-audit ~/.claude/projects --top 20 --recommend.
    • For project configuration/context bloat, run context-guard-diet scan ..
    • For structural waste such as duplicate rules, stale import candidates, oversized tool schemas, or repeated reads in local logs, run context-guard-diet structural-waste . --json.
  2. Identify the largest bucket:
    • stale conversation history -> recommend /clear between unrelated tasks and focused /compact for long tasks.
    • startup context -> prune CLAUDE.md, move long workflows to skills, disable unused MCP servers.
    • large file reads -> use context-guard-read-symbol and the example Read guard before whole-file context.
    • very large logs that may need later exact slices -> store sanitized output with context-guard-artifact store and query only needed lines/patterns.
    • noisy command output -> use context-guard-trim-output wrappers or the example PreToolUse hook. context-guard-filter is deprecated; do not recommend it.
    • grep/diff output with possible secrets -> use context-guard-sanitize-output or the example Bash hook.
    • expensive reasoning -> route default work to sonnet and lower /effort; reserve Opus/opusplan for planning.
    • noisy exploration -> keep it local: use rg, context-guard-read-symbol, artifact queries, or a bounded subagent only when parallel value justifies the multiplier.
  3. Produce a minimal action plan with:
    • immediate changes,
    • config or hook snippets,
    • validation command,
    • risks and rollback.
  4. Do not recommend payment/limit bypasses, account sharing, leaked-source patches, or other unsafe/unauthorized methods.

Useful local commands provided by this plugin:

context-guard-audit ~/.claude/projects --top 20 --recommend
context-guard-setup --plan
context-guard-diet scan .
context-guard-diet structural-waste . --json
context-guard-read-symbol path/to/file.py TargetSymbol
context-guard-artifact store --command "long-command" --json < large.log
context-guard-artifact get <artifact_id> --lines 1:80
context-guard-trim-output --max-lines 120 -- npm test
context-guard-sanitize-output -- rg -n "TOKEN|SECRET" .

If installing hook examples, prefer project-local opt-in settings first. Do not silently modify global ~/.claude/settings.json.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · -2 lines 6b60918eddd1
  2. 1mo ago First seen · 52 lines · 62 tokens per session scan B 892c1ff650b7

Subscribe to this mod's changes

optimize is a skill published in the GitHub repository ictechgy/context-guard (3 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 62 tokens to every session and 769 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.