/project-toolkit:context-optimizerfrom project-toolkit
Analyzes content to determine optimal placement (Skill vs Passive Context vs Hybrid), compresses markdown to reduce context overhead, and validates compliance with the decision framework.
Ships in project-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Tooling suite for optimizing Claude Code context placement. Passive context performed better than skills in the Vercel knowledge-injection eval by eliminating retrieval decisions.
analyze skill placement - classify and validate content as Skill vs Passive Contextcompress markdown - reduce context overheadoptimize context - lower API costs and improve agent performance; distill a large log or diff once with distill_artifact.py, then read the digestextract and index - split markdown into detail files with compact indexaudit always-on rules - eval-gated procedure for whether a rule earns its slot, and the doctrine behind it, in rule-audit-procedure.md and model-context-doctrine.md. Also the entry point when a new model ships. Requires a full rjmurillo/ai-agents checkout: the procedure runs this repo's eval harness and rule generator, neither of which ships in a plugin install. The doctrine and the instrument write-ups are readable anywhere; only the commands need the checkoutanalyze_skill_placement.py to classify contentcompress_markdown_content.py to reduce context overheadtest_skill_passive_compliance.py to check compliance| Script | Purpose | Exit Codes |
|---|---|---|
analyze_skill_placement.py | Classify content as Skill/PassiveContext/Hybrid | 0=success, 1=error |
compress_markdown_content.py | Compress markdown and report the result | 0=success, 1=error, 2=config, 3=external |
test_skill_passive_compliance.py | Validate compliance with decision framework | 0=pass, 1=violations |
extract_and_index.py | Extract sections into detail files with pipe-delimited index | 0=success, 1=error, 2=config, 3=external |
distill_artifact.py | Distill a log, diff, or long text once into a cached digest with line citations; no model call | 0=success, 2=config, 3=external |
path_validation.py | Shared CWE-22 repo-root-anchored path validation | N/A (library module) |
Python 3.12+ with tiktoken for local token counting:
uv pip install -e ".[dev]" # includes tiktoken
pip install tiktoken # or install directly
tiktoken is an offline tokenizer (cl100k_base encoding) that approximates Claude tokenization. No API key is required for these scripts.
The first question is not "skill or passive context." It is: does the model already know this?
| Configuration | Outcome |
|---|---|
| Baseline (no docs) | Weaker than passive context |
| Skill (default) | Weaker than passive context |
| Skill + explicit instructions | Better than the default skill |
| AGENTS.md passive context | Strongest result in the eval |
Skills create decision points where agents must choose whether to retrieve documentation. These introduce 4 failure modes: late retrieval, partial retrieval, integration failure, and instruction fragility. Passive context eliminates all four by being always-available.
The Vercel result is real and narrow. Its suite targeted Next.js 16 APIs chosen because they were absent from model training data. That is a knowledge-injection problem: an agent cannot retrieve what it does not know it is missing, so putting the docs in front of it wins.
It is not evidence that pre-trained knowledge belongs in passive context. Anthropic's Claude 5 context-engineering guidance points the other way for behavioral instruction, naming overconstraint as the failure mode after reducing a system prompt without measurable coding-eval loss. Both results hold, because they answer different questions:
| Content | Model already knows it | Where it goes |
|---|---|---|
| A post-cutoff framework API | No | Passive context |
| This repo's dash ban, its gates | No | Passive context |
| SOLID, Clean Code, refactoring | Yes | Progressive disclosure, or nowhere |
| Deep book material | Partly | Progressive disclosure |
Passive context is paid on every request, whether or not the task needs it. Use progressive disclosure for guidance that does not apply to every file. Read the doctrine and the audit procedure before adding always-on text. Prefer deleting a duplicate over compressing one.
.project-toolkit/analysis/vercel-passive-context-vs-skills-research.mdpassive-context-vs-skills-vercel-researchScript: scripts/analyze_skill_placement.py
Analyzes skill content and recommends Skill, Passive Context, or Hybrid placement.
The script reports shape, not admission. It cannot tell whether the model already knows the content, and that is the question the Decision Framework above turns on. Use it for placement and duplication; the Decision Framework decides what earns an always-on slot.
Classification Logic:
Usage:
# Analyze a skill directory (from repo root)
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/context-optimizer/scripts/analyze_skill_placement.py -p .claude/skills/github; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# Analyze a specific SKILL.md
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/context-optimizer/scripts/analyze_skill_placement.py -p .claude/skills/github/SKILL.md; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# Get detailed metrics
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/context-optimizer/scripts/analyze_skill_placement.py -p .claude/skills/github -d; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Output:
{
"classification": "Hybrid",
"confidence": 85,
"reasoning": "High tool execution (12 calls); High reference content ratio (0.75)",
"recommendations": {
"Passive": ["Routing Rules", "Classification Framework"],
"Skill": ["Get-UnaddressedComments.ps1", "Post-PRCommentReply.ps1"]
}
}
Classification Thresholds:
| Classification | Criteria | Confidence |
|---|---|---|
| Skill | skillScore > passiveScore + 3 | 70-90% |
| PassiveContext | passiveScore > skillScore + 3 | 70-90% |
| Hybrid | abs(skillScore - passiveScore) <= 3 | 50-70% |
Script: scripts/compress_markdown_content.py
Compress markdown to pipe-delimited format while preserving the information needed for retrieval.
Compression Techniques:
|key: value|key2: value2|[Section] |item1 |item2Usage:
# Basic compression (JSON output to stdout)
python3 scripts/compress_markdown_content.py -i README.md -l medium
# Save to file with aggressive compression
python3 scripts/compress_markdown_content.py -i CRITICAL-CONTEXT.md -l aggressive -o compressed.txt
# With verbose metrics
python3 scripts/compress_markdown_content.py -i input.md -l medium -v
Compression Levels:
| Level | Techniques |
|---|---|
| Light | Headers, tables, whitespace |
| Medium | Redundant words, tighter whitespace |
| Aggressive | H3 compression, lists, abbreviations |
Example:
Before:
## Session Protocol
The session protocol has multiple phases:
1. Serena Activation - You must activate Serena
After:
[Session Protocol]
session protocol has multiple phases:
1. Serena Activation - activate Serena
Script: scripts/extract_and_index.py
Implements the Vercel extract-and-index pattern. Splits markdown by headings into detail files and generates a compact pipe-delimited index.
Usage:
# Extract sections and output JSON to stdout
python3 scripts/extract_and_index.py -i AGENTS.md -d .agents-details
# Write index to a file
python3 scripts/extract_and_index.py -i AGENTS.md -d .agents-details -o AGENTS-INDEX.md
# Custom reference path in index
python3 scripts/extract_and_index.py -i AGENTS.md -d .agents-details -r .agents-docs -o AGENTS-INDEX.md
Output Index Format (Vercel pattern):
[Architecture]
|Layered design with separation of concerns (see: .agents-details/architecture.md)
[Testing]
|Coverage required for business logic (see: .agents-details/testing.md)
Works with CLAUDE.md @import mechanism. Reference via @AGENTS-INDEX.md.
Script: distill_artifact.py
Boils one log, diff, or long text down to a markdown digest with line citations. No model call. The digest is cached by content and source, so a repeat call reuses it.
Use it for an artifact you will read on more than one turn, or one too large
to read whole. The digest keeps signal lines (error, fail, warning, and
similar), the first and last 15 lines, and per-file counts for a diff. Middle
lines without a signal are omitted, so a clean git log digests thin: use
git log --oneline for chronology instead.
Usage:
# Save the output and its exit code first, so the raw stays searchable
some_command > build.log 2>&1; echo "exit=$?"
# Distill the saved file; prints the digest path
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/context-optimizer/scripts/distill_artifact.py build.log; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# JSON adds cached, kind, raw and digest bytes, ratio
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/context-optimizer/scripts/distill_artifact.py build.log --format json; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
- reads stdin, but then no raw copy remains to search, and a pipe reports
the distiller's exit code, not the command's. Save to a file first.
Use the digest to locate evidence (L{n} cites the raw line). It omits middle
lines without a signal, so search the raw source for any detail it lacks and
read the matching lines with their context.
Script: scripts/test_skill_passive_compliance.py
Validates content placement against the skill vs passive context decision framework.
Evaluated Checks:
name and description)The report examines the selected CLAUDE.md file separately from imported
content, hierarchical CLAUDE.md and AGENTS.md files, generated instruction
layers, and plugin context. That result is diagnostic, not a compliance
verdict.
Claude Code loads CLAUDE.md files in full. Auto-memory uses MEMORY.md and
follows separate vendor behavior. This repository applies its own skill
validation policy in skill_size.py.
Source: https://docs.anthropic.com/en/docs/claude-code/memory
Skill size is also separate. In a full rjmurillo/ai-agents checkout, run the
repository's skill_size.py validator against both the canonical and generated
skill trees.
The report states what it does not evaluate. Content value still needs evidence-based review. Classify each passive rule as one of:
Lexical matches do not prove those categories. Cite the incident, source, or test that supports each keep or remove decision.
Usage:
# Scan .claude directory (JSON output)
python3 scripts/test_skill_passive_compliance.py
# Scan specific directory with table output
python3 scripts/test_skill_passive_compliance.py --path .claude/skills/github --format table
Exit Codes: 0 = all passed, 1 = violations detected
Common Violations:
| Violation | Fix |
|---|---|
| Missing @import file | Create file or remove @import directive |
| Skill missing frontmatter | Add --- block with name: and description: |
| Skill has no actions | Add scripts or move to passive context |
| Passive has actions | Extract executable content to a skill |
| Duplicate content | Remove redundant content from skill or passive |
| Unaudited size exception | Add invariant, behavior tests, and review trigger |
Input: GitHub skill with gh pr create, gh issue close commands
{"classification": "Skill", "confidence": 85, "reasoning": "High tool execution (8 calls); Many action verbs (12)"}
Input: Memory hierarchy reference, tables and lists, no commands
{"classification": "PassiveContext", "confidence": 80, "reasoning": "High reference content ratio (0.85)"}
Input: PR comment responder with routing rules + script execution
{
"classification": "Hybrid",
"confidence": 65,
"reasoning": "High reference content ratio (0.72); Some tool execution (4 calls)",
"recommendations": {
"Passive": ["Routing Rules", "Classification Framework"],
"Skill": ["Get-UnaddressedComments.ps1", "Post-PRCommentReply.ps1"]
}
}
python3 -m pytest tests/ # all tests
python3 -m pytest tests/test_skill_passive_compliance_test.py -v # specific
python3 -m pytest tests/ --cov=scripts --cov-report=term-missing # coverage
Coverage Summary:
| Component | Key Areas |
|---|---|
| Compliance Validator | Placement, @imports, frontmatter, duplicates, exit codes |
| Analyzer | Tool calls, action verbs, classification logic, confidence scoring |
| Extract-and-Index | Slug generation, parsing, index format |
| Compressor | Compression levels, code block preservation |
references/claude-code-productivity-patterns.md (opens in a new tab)references/model-context-doctrine.md (opens in a new tab)references/rule-audit-evidence.md (opens in a new tab)references/rule-audit-instrument.md (opens in a new tab)references/rule-audit-measurement-discipline.md (opens in a new tab)references/rule-audit-parser-forensics.md (opens in a new tab)references/rule-audit-procedure.md (opens in a new tab)references/vibe-engineering.md (opens in a new tab)scripts/analyze_skill_placement.py (opens in a new tab)scripts/compress_markdown_content.py (opens in a new tab)scripts/context_output_checker.py (opens in a new tab)scripts/context_output_cli.py (opens in a new tab)scripts/context_output_index.py (opens in a new tab)scripts/context_output_manifest.py (opens in a new tab)scripts/context_output_parsing.py (opens in a new tab)scripts/context_output_report.py (opens in a new tab)scripts/context_output_storage.py (opens in a new tab)scripts/distill_artifact.py (opens in a new tab)scripts/extract_and_index.py (opens in a new tab)scripts/path_validation.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
105 skills in this plugin
/adr-generatorCreate comprehensive Architectural Decision Records (ADRs). Researches the destination directory to detect existing template conventions, gathers context, determines next ADR number, generates the ADR, validates completeness, and saves. Supports multiple ADR formats (MADR, Nygard, Alexandrian, project canonical). Use when documenting technical decisions, creating new ADR files, or capturing rationale so future readers can revisit a choice. Use when you say "write an ADR", "document this decision", "document these design choices", "record why we chose this", "capture the rationale", or "for future maintainers", or when creating an ADR-like markdown file under docs/decisions/, docs/adr/, docs/architecture/, architecture/decisions/, or .project-toolkit/architecture/. Do NOT use to debate or review an existing ADR (use adr-review)./adr-reviewMulti-agent debate orchestration for Architecture Decision Records. Automatically triggers on ADR create/edit/delete. Coordinates architect, critic, independent-thinker, security, analyst, and high-level-advisor agents in structured debate rounds until consensus. Use when you say "review this ADR", when an ADR is created/edited/deleted, or when reviewing, accepting, or updating a decision file under .project-toolkit/architecture/, docs/architecture/, docs/decisions/, docs/adr/, or architecture/decisions/, including intent like "review this decision record" or "check this rationale for future maintainers". Do NOT use to author a new ADR (use adr-generator)./agent-harness-referenceField reference for Claude Code and GitHub Copilot CLI hook contracts. Covers hook locations, events, matchers, payloads, decisions, exit codes, timeouts, plugin roots, and cloud limits with official URLs and versioned probes. Use for `harness contract`, `copilot cli hook behavior`, `hook payload format`, `stale plugin root`, `Errno 2 _dispatch.py`, or before changing cross-harness hooks. Do NOT use to run the porting campaign (in the ai-agents repository, use `ai-agents-portability-campaign`)./ai-agents-external-claimsVerify external, vendor, and third-party claims (numbers, attributions, structure) against authoritative primary sources before they land in a repo artifact or external deliverable. Covers stake-holding sources, round-number tells, citation-chain drift, and the walk-the-gate-or-file-conservative discipline. Use when you say `verify an external claim`, `check a vendor number`, `is this stat real`, `validate a third-party citation`. Do NOT use for running an experiment (use `ai-agents-research-methodology` in the ai-agents repository) or command-injection scanning (use `security-scan`)./analysis-provenanceIdentify code ownership before modifying validators or linters. Checks file headers for provenance indicators, reviews documentation, and determines provenance as UPSTREAM, LOCAL, VENDOR, or UNKNOWN. Prevents accidental modification of upstream tools./analyzeSystematic multi-step codebase analysis producing prioritized findings with file-line evidence. Covers architecture reviews, security assessments, and code quality evaluations through guided exploration, investigation planning, and synthesis. Use when you say "analyze this codebase", "run security assessment", "architecture review of this system", "find code smells", or "review code quality" across multiple files. Do NOT use for single-file maintainability scoring (use code-qualities-assessment) or CWE-78 injection pattern scanning (use security-scan).npx claudepluginhub rjmurillo/ai-agents --plugin project-toolkit2 plugins in one repository ship this exact skill · first indexed Nov 13, 2026
Other plugins' skills for the same job