agentleFS
jonathan-vellajonathan-vella/apex/.github/skills/apex-context-management/SKILL.md

apex-context-management

Skill216 starsChanged 2 months agoMITView on GitHub

**UTILITY SKILL** — Two-mode context-window management. RUNTIME: artifact compression (full/summarized/minimal) used by orchestrator and codegen agents. AUDIT: post-mortem analysis of Copilot debug logs (token profiling, redundancy + hand-off gap detection) used by 11-Context Optimizer. WHEN: "context optimization", "token budget", "runtime compression", "log parsing". DO NOT USE FOR: infra, IaC code, deployments.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before loading a predecessor artifact file (01 through 07)

    line 31
  2. Distinctive:

    When conversation length suggests >60% of model context is used

    line 32
  3. Distinctive:

    When an agent needs to load multiple large artifacts

    line 33
  4. Distinctive:

    If loading multiple artifacts, compress the older / less-critical ones first

    line 61

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Context Management Skill

Unified context-window management with two distinct lifecycles:

  • Runtime Compression — what an agent does before loading a large artifact to stay under the model context limit (during workflow execution).
  • Diagnostic Audit — what the 11-Context Optimizer agent does after the fact to find waste in agent definitions, instructions, and skill loads.

The two modes do not depend on each other — pick the section that matches your need.


Mode A: Runtime Compression

Replaces the legacy context-shredding skill.

When to Use Runtime Compression

  • Before loading a predecessor artifact file (01 through 07)
  • When conversation length suggests >60% of model context is used
  • When an agent needs to load multiple large artifacts

Compression Tiers

TierContext UsageStrategy
full< 60%Load entire artifact — no compression
summarized60-80%Load key H2 sections only
minimal> 80%Load compact decisions; retain required safety evidence losslessly

Hard Token Checkpoints

Percentages are advisory; absolute input-token counts override them. GPT-6 Sol/Luna and GPT-5.6 Terra hard-checkpoint at ≥300K input; Claude Opus 5.5, Claude Sonnet 5.5 and MAI-Code at ≥160K. When hit, emit a compaction message and prefer the minimal artifact tier. Required missing guidance and safety evidence must still be recovered. These are repository trip-wires, not verified model API limits; use the active harness limit when known and do not infer it from a model name. Full per-model table, checkpoint procedure, and background context (nordic-foods saturation event) in references/hard-checkpoints.md.

Rules

  1. Estimate context usage — count approximate conversation tokens
  2. Select tier based on the thresholds above
  3. Apply compression template from references/compression-templates.md
  4. If loading multiple artifacts, compress the older / less-critical ones first

Steps

1. Estimate current context usage (rough: 1 token ≈ 4 chars)
2. Check the active harness model limit; if unavailable, report it as unknown
3. Calculate usage percentage and check hard-checkpoint table
4. Select tier:
   < 60%  → full (no compression needed)
   60-80% → summarized (key sections only)
   > 80%  → minimal (decision summaries only)
5. Load the artifact tier; skills remain single-tier and safety inputs remain complete

Skill Loading

Skills are single-tier — one file per skill, no digest / minimal variants. Reuse each SKILL.md while unchanged and available in context; reload missing required guidance after compaction, edits, or a new chat. Defer references/*.md until the SKILL.md body explicitly points to one. Full protocol in references/skill-loading.md.


Mode B: Diagnostic Audit

Replaces the legacy context-optimizer skill.

Structured methodology for auditing how GitHub Copilot agents consume their context window. Identifies waste, recommends hand-off points, and produces prioritised optimisation reports.

When to Use Diagnostic Audit

  • Auditing context-window efficiency across a multi-agent system
  • Identifying where to introduce subagent hand-offs
  • Reducing redundant file reads and skill loads
  • Optimising instruction file applyTo glob patterns
  • Profiling per-turn token cost from debug logs
  • Porting agent optimisations to a new project

Audit Capabilities & Prerequisites

Capabilities cover log parsing, turn-cost profiling, redundancy detection, hand-off gap analysis, instruction audit, and structured report generation. Prerequisites: Python 3.14, VS Code Copilot Chat debug logs, and .github/agents/*.agent.md (or equivalent). Full capability matrix, portability checklist, and debug-log discovery in references/audit-setup.md.

Analysis Methodology

For the complete methodology — log format reference (ccreq line parsing, request types, latency heuristics), Steps 1-5 (log parsing → optimisation recommendations), common optimisation patterns, and baseline comparison workflow (Phase 0 + Phase 6) — read references/analysis-methodology.md.

Report Template

See templates/optimization-report.md for the full output template.


Reference Index

Operational procedures (load only the requested one):

  • Debug-log export, with manual Host entrypoint apex-host-debug-log-export.
  • Context audit.

For definition scorecards, static authoring-asset assessments, and their design history, use apex-agent-authoring. This skill owns log capture, context audit, and runtime compression, not authoring assessment procedures.

Load on demand:

ReferenceModeWhen to Load
references/compression-templates.mdRuntimePer-artifact H2 sections per tier
references/hard-checkpoints.mdRuntimeHitting a model token threshold or wiring agent checkpoint logic
references/skill-loading.mdRuntimeMulti-skill loads / clarifying single-tier load protocol
references/token-estimation.mdAuditEstimating token counts for context optimisation
references/analysis-methodology.mdAuditLog format, 5-step methodology, optimisation patterns, baseline comparison
references/audit-setup.mdAuditPrerequisites, enabling debug logs, audit capabilities, portability
scripts/parse-chat-logs.pyAuditLog parser producing structured JSON
templates/optimization-report.mdAuditReport output template

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.