Context Governance for LLMs: A Cleanup Guide for Skills and AGENTS.md
As context windows grow, relevance becomes the real bottleneck. This article explains why domain-based skill triggers and monolithic rule files waste context budget, and how to fix it: rewrite triggers as task boundaries with counter-examples, layer rules across global, project, directory, and task levels, compress and deduplicate content, and sustain the cleanup with an evaluation set and periodic reviews. The approach is tool-agnostic and applies to any agent configuration that relies on a context window.
Introduction: From Scarce Context to Context Governance
Over the past year, the context windows of AI coding tools have kept expanding. Developers have naturally developed an expectation: since we can fit more content, why not hand the model the project conventions, troubleshooting procedures, and reference material all at once? As a result, two types of files have ballooned. The first is skill descriptions that define “which workflow to load and when.” The second is project rule files placed in the repository root for agents to read, such as the convention established by AGENTS.md.
But once available space is no longer the bottleneck, the new bottleneck becomes relevance. At every step, the model must make trade-offs within limited attention resources, and anything that enters the context competes for them. This article is not about the capabilities of a specific tool. It addresses a general engineering problem: how to systematically clean up skill trigger conditions and project rule files so that the context budget is spent only on information truly relevant to the current task.
1. Root Cause: Triggers Written as “Domains” Instead of “Tasks”
A common pattern is to describe the applicable scenario with domain nouns, for example, “use when working with databases, queries, models, or persistence.” This kind of description has an enormous scope: changing an ORM field, fixing a query statement, or adjusting a serialization configuration all literally fall within the “database/model” range, so the skill is judged to be relevant.
Once triggered, the cost is a chain reaction. The skill body’s procedure descriptions, checklists, reference links, and sample code all enter the context, often amounting to thousands of tokens. They are unrelated to the current task, yet they will:
- Consume budget, causing truly relevant code and logs to be truncated;
- Introduce wrong objectives, as the model starts executing migration checks, rollback plans, and other task-irrelevant steps;
- Cause “rule conflicts,” where multiple skills match at the same time, instructions contradict each other, and the output becomes conservative or repeatedly asks for confirmation.
To judge whether a skill is being over-triggered, you can use several observable signals: a small change triggers a long workflow; the questions the model asks are unrelated to the task; the output contains many unrequested check items; the same task behaves noticeably differently across sessions.
2. First Cut: Rewrite Trigger Descriptions from “Domains” to “Task Boundaries”
The core method is to replace “topic words” with “action + artifact + counter-example.” It can be written in the following structure:
---name: schema-migration-safetyuse_when:- Need to add or remove table fields and generate the corresponding versioned migration scripts- Need to write data backfill scripts that involve existing production datado_not_use_when:- Only modifying ORM field mappings or serialization configuration- Only adjusting query conditions, index hints, or pagination parameters- Only reading model definitions to understand business semantics---
Three key points: first, use decidable actions (“generate migration scripts,” “write backfill scripts”) instead of abstract nouns; second, explicitly write counter-examples so the model has a basis for exclusion; third, control granularity so that one skill corresponds to one independently verifiable workflow, not an entire domain.
3. Second Cut: Layer Rule Files to Avoid a “Single Giant File”
Concentrating rules in a single file at the root directory forces the entire content to be loaded for every task. A more reasonable approach is to layer them:
- Global layer: only cross-project general conventions, such as commit message format and logging standards, kept within a hundred lines;
- Project layer: build methods, directory structure, and test command entry points;
- Directory layer: local rules placed in subdirectories, effective only when that directory is modified;
- Task layer: move lengthy troubleshooting procedures, templates, and reference material into skills or standalone documents, loaded on demand.
The criterion for layering is simple: does this rule only hold for a specific directory or a certain type of task? If so, it should not appear in the global file.
4. Third Cut: Compress Size and Deduplicate
During cleanup, ask three questions about each item: Can the model infer this rule from the code itself? Is it duplicated with another rule? Is it already outdated? Delete what can be inferred from the code, merge duplicates, and archive what is outdated.
An illustrative before-and-after comparison:
Before: 420-line rule file, 11 skills, average trigger description of 3 lines, all domain wordsAfter: 90-line rule file (40 global + 50 project), 6 skills,trigger descriptions all in "action + artifact + counter-example" form, averaging 6 lines but decidable
While the size drops, decidability rises. This is the sign of a successful cleanup.
5. Making Cleanup Sustainable: Evaluation Sets and Regular Checkups
A one-time cleanup will regress, so it needs to be mechanized:
- Build a small evaluation set, labeling 20–50 real historical tasks as “should trigger / should not trigger,” and run regression after every change;
- Record trigger accuracy and context usage as quantifiable metrics;
- Add checks in continuous integration to limit the line count and size of rule files, with alerts when thresholds are exceeded;
- Do a “cleanup” once a quarter, deleting skills that have not been hit for a long time and merging semantically overlapping rules.
6. The Right Way to Integrate Profiling Skills
Take startup performance troubleshooting as an example. This type of skill is highly valuable but large in size, and is most likely to be loaded unconditionally. The recommended approach: keep only the decision process and interpretation key points in the skill body, and place sampling scripts, metric thresholds, and historical baseline data at a fixed path in the repository for the model to read on demand; limit the trigger condition to “need to locate the source of cold-start or long-tail latency and sampling data is already available,” rather than “involves performance.”
Conclusion
The essence of context governance is relevance engineering: not stuffing in more, but ensuring that every piece of content entering the context has a clear responsibility. Write trigger conditions as task boundaries, place rules in layers, compress the size to a maintainable range, and then use evaluation and regular cleanup to hold the gains. AI coding tools will become noticeably more stable and predictable in real projects. This method is independent of any specific tool and applies to any agent configuration that relies on a context window.
