Skip to content
Back to skills

Optimize Context

ASecurity

Reduces AI agent context bloat across three dimensions: duplicate skill deduplication, canonical AGENTS.md optimization, and session token efficiency. USE ONLY when trimming instruction files, diagnosing duplicate skill loading, or reducing agent token overhead.

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentspythonbash

Works with

  • terminal

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned October 3, 2026

npx -y skills add richfrem/agent-plugins-skills --skill optimize-context --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Optimize Context?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Optimize Context
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/richfrem-optimize-context/badge)](https://www.skillsdirectory.com/skills/richfrem-optimize-context)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: optimize-context
plugin: dev-utils
description: >
  Reduces AI agent context bloat across three dimensions: duplicate skill deduplication, canonical AGENTS.md optimization, and session token efficiency.
  USE ONLY when trimming instruction files, diagnosing duplicate skill loading, or reducing agent token overhead.
allowed_tools:
  - run_command
  - view_file
  - write_to_file
  - replace_file_content
  - multi_replace_file_content
  - grep_search
  - list_dir
---

# Optimize Context (optimize-context)

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

## Contents
- [Critical Constraints](#critical-constraints)
- [Quick start](#quick-start)
- [Workflow](#workflow)
- [Verification](#verification)
- [References](#references)

## 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

```bash
# 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

```bash
# 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
- [deduplication-topology.md](references/deduplication-topology.md) - Loading hierarchy and deduplication mechanics.
- [instruction-optimization.md](references/instruction-optimization.md) - Pruning guidelines and mirror sync rules.
- [session-efficiency.md](references/session-efficiency.md) - Delegation rules and subagent context boundaries.
- [acceptance-criteria.md](references/acceptance-criteria.md) - Verification contracts and test criteria.
- [fallback-tree.md](references/fallback-tree.md) - Failure recovery and fallback procedures.

Files in this skill

  • SKILL.md11.4 KB
  • evals/evals.json2.2 KB
  • references/acceptance-criteria.md42 B
  • scripts/optimize_context.py36 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.