Agent Context Engineering: A Cleanup Guide for Skills and AGENTS.md Files
This article explains why newer, more capable models make context cleanup essential rather than optional. It covers how to decide what to keep, merge, delete, or load on demand; how to restructure repository-level convention files like AGENTS.md; how to slim down Skills from fixed scripts into capability descriptions; and how to validate the results with a lightweight evaluation loop. You will also find common pitfalls and a practical rollout checklist.
1. Why a new generation of models makes a “context cleanup” mandatory
After switching to a new generation of AI coding tools, many developers notice something counterintuitive: the model’s reasoning ability is stronger, but the “legacy assets” in the project have become a drag. These assets fall into two categories. The first is skill documentation scattered across the repository. The second is the agent convention file at the repository root (for example, AGENTS.md), which describes how to build, test, and follow code style.
Once the model’s capabilities jump forward, the verbose prompts, repeated constraints, and hardcoded workflows designed for “weaker models” start to consume the precious context window. They dilute the weight of critical instructions, lengthen the execution path, increase tool calls, and make results less stable.
So a “cleanup” is not simply about deleting content. It is a refactor aimed at context engineering: reallocating the truly scarce resources—attention and context budget—to high-value information. The core goals can be summarized in three points: reduce noise, improve the signal-to-noise ratio, and make sure the model sees the right information at the right time.
2. Set judgment criteria first: what to keep, merge, or delete
Before making changes, establish a reusable set of rules so you do not edit by gut feeling:
- Keep: implicit knowledge that is tightly bound to the repository and cannot be inferred automatically from the code—for example, a specific build order, internal dependency constraints, directories that must not be touched, and caveats about the production environment.
- Merge: when multiple files describe the same rule, converge them into a single authoritative source and leave only references elsewhere.
- Delete: information that standard tooling can discover automatically (such as routine compile commands), outdated workarounds, and “hand-holding” step-by-step instructions written for older model capabilities.
- Push down: long documents, tables, and background material that are only needed for specific tasks should be moved out of the resident context and loaded on demand.
A practical self-check question is: “If a new teammate read only this file, would they perform an incorrect operation?” If the answer is no, the information is insufficient. If the answer is “they would be distracted by a large amount of irrelevant information,” it needs to be trimmed.
3. A refactoring pattern for AGENTS.md-style convention files
The value of a repository-level convention file lies in being “stable and predictable.” It should read like a concise engineering contract, not an encyclopedia. A layered structure is recommended:
# Project conventions (resident context, keep under 100 lines)## 1. Build and verification- Dependency install: <the single recommended way>- Local verification: <the shortest executable check command>## 2. Directories and boundaries- Modifiable: <directory>- Do not modify: <directory and reason>## 3. Must-do before committing- Formatting / static checks / unit test scope## 4. Look up on demand- Performance tuning guide: docs/perf.md- Release process: docs/release.md
Key practices include: split long content into on-demand documents and leave only pointers in the main file; replace “prohibition lists” with “positive instructions,” because clearly telling the model what to do is more effective than piling up bans; and annotate each rule with its scope of applicability so global rules do not accidentally harm local tasks.
4. Slimming down and reorganizing Skills: from process scripts to capability descriptions
Skill assets are the most prone to bloat. Many skills were originally written as fixed-step “operation manuals” to compensate for the model’s shortcomings. With a new generation of models, they should be abstracted into “capability + constraints + input/output contract,” handing specific decisions back to the model.
Take performance analysis as a typical scenario. The old approach was often a long, fixed command sequence. A more reasonable organization is:
skills/perf-analysis/SKILL.md # when to use, input requirements, output format, caveatsreferences/checklist.md # common bottleneck categories and criteriareport.tpl # conclusion template: symptom-evidence-hypothesis-validation-benefit
The skill description should make three things explicit: the trigger condition (which task requires loading it), the input contract (which logs or metric files are needed), and the output contract (in what structure the conclusion is presented). At the same time, leave “information that can be obtained automatically” to the toolchain—for example, retrieving runtime data through monitoring alerts, log services, or the metrics API of a container platform—instead of hardcoding collection steps in the prompt.
5. General practices for cold start and performance optimization
In inference service optimization, cold start and first-token latency are common pain points. Regardless of which AI coding tool you use, a reusable methodology holds:
- Evidence first: collect stage-by-stage timing (loading, compilation or graph capture, weight loading, cache warmup) to form a comparable baseline.
- Hypothesis-driven: have the agent propose several verifiable hypotheses based on the evidence, annotated with expected benefit and risk.
- Small-step validation: change only one variable at a time and keep a rollback path, avoiding “changing multiple points at once,” which makes attribution fail.
- Capture conclusions: write validated conclusions back into the “look up on demand” layer of the skill or convention file, forming an organizational asset.
An illustrative conclusion record format:
finding:symptom: first-request latency is significantly higher than steady stateevidence: weight loading accounts for the largest share of stage timinghypothesis: the loading path has repeated deserializationchange: reuse already-parsed metadataresult: cold start time decreased (based on local measurement)rollback: a switch is kept to revert
It must be emphasized that any performance number must come from your own measured environment and should not be copied from others’ conclusions.
6. Evaluation loop: verify the benefit of the “cleanup” in a quantifiable way
After refactoring the context, you must answer “did it actually get better?” It is recommended to build a lightweight evaluation set of 10–30 real task samples covering everyday code changes, troubleshooting, writing tests, and performance localization, and to record three types of metrics: task success rate, average number of interaction rounds, and context consumption (input length can approximate this). After each adjustment to the convention file or a skill, run a regression and watch for structural anomalies such as “success rate rises but rounds also rise.”
In addition, you can introduce a “minimal context” control experiment: run the same task with the streamlined version and the full version of the convention file and compare the results. If the streamlined version performs no worse—or even better—it means the previous redundancy was indeed interfering with the model’s judgment.
7. Common pitfalls and a rollout checklist
- Pitfall 1: stuffing all knowledge into the resident file. Instead, use layered loading.
- Pitfall 2: constraining behavior with a large number of bans. Instead, use clear positive workflows and acceptance criteria.
- Pitfall 3: writing skills as fixed scripts. Instead, keep the goal and constraints and let the model plan the path itself.
- Pitfall 4: doing a one-time big change and never maintaining it. Instead, bring the convention file into code review and update it as the architecture evolves.
The recommended rollout order is: first inventory the assets and annotate their source and last-updated time; then merge duplicates and delete outdated items; then restructure the directory into “resident + on-demand”; then fill in the three types of contracts for skills; and finally build an evaluation set and a regular regression mechanism. If the team already uses common cloud capabilities such as a container platform, log service, and monitoring alerts, you can write the way runtime data is obtained into the skill’s input contract, reducing environment-specific descriptions in the prompt so that the same set of skills can be reused across different projects.
After this round of cleanup, you will find that the benefit is not reflected in any single prompt trick, but in a change to the overall way of collaborating: the context is cleaner, the instructions are clearer, the agent’s behavior is more predictable, and the team’s experience can be continuously accumulated in a structured way.
