optimize-context

optimize-context is a skill for Claude Code from richfrem/agent-plugins-skills. It costs 50 tokens per session (638 once invoked), scanned A, original, MIT.

A cleanup tool for an AI coding project's instructions and installed skills. It removes duplicate skill copies and shortens instruction files while keeping their rules.

In plain words
What is it for?
Auditing skill folders and optimizing CLAUDE.md, GEMINI.md, or GitHub Copilot instruction files, with options to preview changes or focus on one area.
Why use it?
AI tools can load the same skill twice or spend context on stale and overly long instructions. This reduces repeated or unnecessary text so the agent has more room for the actual task.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: mentions subagents; mentions AGENTS.md.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is python3 plugins/agent-scaffolders/scripts/audit_skill.py plugins/dev-utils/skills/optimize-context --mode source.

Part of the dev-utils plugin — 19 skills shipped together

Good fit Auditing skill folders and optimizing CLAUDE.md, GEMINI.md, or GitHub Copilot instruction files, with options to preview changes or focus on one area.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/richfrem/agent-plugins-skills
agentmods
npx agentmods add skills/richfrem/agent-plugins-skills/optimize-context

Made for: Claude Code.

Or install dev-utils, the plugin that ships this one along with the rest of its 19 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-context

README.md
[![agentmods](https://agentmods.dev/badge/skills/richfrem/agent-plugins-skills/optimize-context/github.svg)](https://agentmods.dev/skills/richfrem/agent-plugins-skills/optimize-context)
Your own site
<a href="https://agentmods.dev/skills/richfrem/agent-plugins-skills/optimize-context"><img src="https://agentmods.dev/badge/skills/richfrem/agent-plugins-skills/optimize-context/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-context

Your own site · 80×15
<a href="https://agentmods.dev/skills/richfrem/agent-plugins-skills/optimize-context"><img src="https://agentmods.dev/badge/skills/richfrem/agent-plugins-skills/optimize-context.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 50 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 638 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.00050 $0.00638
Opus 5.5 $0.00020 $0.00255
Sonnet 5.5 $0.00010 $0.00128
Haiku 4.5 $0.00005 $0.00064

Measured 17d ago against content hash d580db7390d4, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

optimize-context scanned grade A with 0 findings 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 17d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/optimize_context.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/dev-utils/skills/optimize-context/SKILL.md · 64 lines

How it starts

The opening of the file, as written. The whole thing — 64 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Optimize Context (optimize-context)

Reduces AI agent context bloat through duplicate skill deduplication, canonical AGENTS.md optimization, and session token hygiene.

Contents

Critical Constraints

  • Scope Boundary: USE ONLY for diagnosing token bloat, deduplicating installed skill mirrors, trimming instruction files, or auditing session efficiency.
  • Destructive Action Gate: Never delete duplicate skills or platform instruction files autonomously; deletions require explicit user confirmation.
  • Canonical Instruction Anchor: Treat AGENTS.md as the sole canonical instruction authority; avoid blind synchronizations to legacy mirrors.
  • Artifact Passing: Pass bounded structured artifacts rather than raw terminal traces between subagent boundaries.

Quick start

# Scan for duplicate skills and context bloat (dry-run)
python3 plugins/dev-utils/skills/optimize-context/scripts/optimize_context.py --dry-run

Workflow

  1. Phase 1: Skill Deduplication Scan: Run optimize_context.py --dry-run to detect duplicate skill declarations across .claude/ and workspace plugin roots.
  2. Phase 2: Instruction File Audit: Review AGENTS.md against the target line budget and identify duplicate mirror surfaces.
  3. Phase 3: Session Token Efficiency: Verify lean delegation patterns and enforce artifact passing over raw transcript dumps.
  4. Phase 4: Hygiene Verification: Re-run diagnostic checks to confirm duplicate elimination and verify zero broken references.

Verification

# Run context hygiene verification
python3 plugins/dev-utils/skills/optimize-context/scripts/optimize_context.py --dry-run

# Audit skill compliance
python3 plugins/agent-scaffolders/scripts/audit_skill.py plugins/dev-utils/skills/optimize-context --mode source

References

Read the full file on GitHub · 64 lines

Files

What ships with it

7 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 17d ago Changed · +8 lines d580db7390d4
  2. 1mo ago Changed · +3 lines · -12 tokens per session scan C → A 43554d12b300
  3. 1mo ago Changed · -231 lines · -102 tokens per session scan D → C 48187120b903
  4. 1mo ago First seen · 284 lines · 164 tokens per session scan D 07b5d73d5865

Subscribe to this mod's changes

optimize-context is a skill published in the GitHub repository richfrem/agent-plugins-skills (7 stars, last pushed yesterday), licensed MIT. It adds 50 tokens to every session and 638 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.