You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize Agent Instructions and Skills for Token Efficiency
Summary
Audit and refactor AGENTS.md and .agents/skills/ to reduce recurring and on-demand token consumption without weakening behavioral constraints, accuracy, verification requirements, safety rules, or skill routing.
The current instruction architecture is fundamentally sound:
GOVERNANCE.md / CODESTYLE.md / WORKFLOW.md
|
v
AGENTS.md
|
v
Skill routing
|
v
SKILL.md
|
v
references/
The main opportunity is not to remove rules. It is to ensure that each layer contains only the information needed at that layer.
The desired model is:
AGENTS.md
Always-on bootstrap, universal constraints, and routing.
SKILL.md description
Decide whether the skill should be loaded.
SKILL.md body
Tell the agent what to do when the skill is active.
references/
Detailed mechanics, examples, edge cases, and infrequently needed material.
GOVERNANCE.md / CODESTYLE.md / WORKFLOW.md
Complete authoritative policy, rationale, and durable documentation.
The optimization principle is:
Minimize tokens × load frequency, not merely file size.
A 500-token instruction loaded for every task can cost more over time than a 5,000-token reference loaded only for a rare operation.
Goals
Reduce the token cost of the always-loaded instruction set.
Reduce skill discovery/description token cost.
Improve progressive disclosure within skills.
Preserve all behaviorally important rules.
Preserve explicit verification and safety gates.
Preserve skill-routing accuracy.
Preserve provider-independent fleet behavior.
Make important instructions easier for an agent to identify rather than burying them in explanatory prose.
Maintain one authoritative source for complete policy and rationale.
Avoid optimizing token count at the expense of correctness.
Non-Goals
This is not an exercise in making instructions terse at all costs.
Do not:
Remove a rule merely because a capable model would "probably know" it when the rule expresses a fleet-specific decision.
Remove surprising or non-standard conventions.
Weaken explicit safety, verification, authorization, or merge gates.
Replace deterministic instructions with model judgment where the fleet deliberately specifies behavior.
Eliminate intentional repetition where a rule must be surfaced at a specific decision point.
Combine distinct conditions merely to reduce line count.
Make skill descriptions so generic that skill routing becomes less reliable.
Move frequently required instructions into references merely to make SKILL.md smaller.
Token reduction is successful only when behavior remains equivalent or improves.
Current Findings
1. AGENTS.md is the highest-priority optimization target
The root AGENTS.md is approximately 17.5 KB.
Its intended responsibility is already correctly described as:
Bootstrap.
Always-on context/delegation discipline.
Map to canonical rules.
That is the right architecture.
However, the file currently contains substantial explanatory material around those responsibilities, including:
Rationale for where different classes of rules live.
Detailed explanation of relationships among AGENTS.md, GOVERNANCE.md, CODESTYLE.md, WORKFLOW.md, project-specific instructions, and Copilot instructions.
A Fleet Bootstrap diagram followed by prose describing substantially the same states.
Explanations of why context-management rules save tokens.
Explanations of why particular delegation rules exist.
Detailed discussion of why some governance sections have skills and others do not.
Descriptions of the purpose and provenance of numerous skills.
Much of this information is useful durable documentation but does not need to occupy the always-on context.
Desired AGENTS.md shape
Target roughly a 40–60% reduction, subject to behavioral validation.
Prefer a structure similar to:
# Instructions for AI Coding Agents
## Authority
Short declaration of canonical sources and precedence.
## Fleet Bootstrap
State -> required procedure.
No duplicated diagram plus prose explanation.
## Always-On Rules
Only rules that truly apply to every task.
### Context
### Reading
### Commands
### Delegation
### Safety / authorization if required here
## Rule Router
Task/topic -> canonical section and/or skill.
## Skill/Installation Notes
Only information necessary to discover or maintain the skill system.
Move architectural rationale and historical explanation to the canonical documentation rather than keeping it in the bootstrap.
For example, instead of a long explanation of document responsibilities, prefer something structurally equivalent to:
## Rule Sources-`GOVERNANCE.md`: canonical cross-cutting rules.
-`CODESTYLE.md`: general and language-specific code style.
-`WORKFLOW.md`: CI/CD contract.
- Project `AGENTS.md`: project-specific conventions and behavioral contracts.
-`.github/copilot-instructions.md`: Copilot-specific mechanics.
Do not duplicate canonical rules between these files.
The exact wording should be derived from the existing policy so that no authority or precedence semantics are lost.
2. Skill descriptions are precise but substantially overlong
The current skill descriptions generally have excellent trigger specificity.
Examples include:
agent-conduct
pr-review-conduct
dotnet-codestyle
python-codestyle
comment-and-doc-style
repo-worktree
Their descriptions frequently contain all of the following:
What the skill owns.
When it activates.
Examples of apparently trivial tasks that still activate it.
Why those tasks are dangerous.
Historical or architectural rationale.
Relationship to GOVERNANCE.md.
Relationship to AGENTS.md.
Sibling-skill precedence.
Provider-specific implementation notes.
Only a subset is required for discovery.
Desired description structure
A skill description should primarily answer:
WHAT does this skill own?
WHEN should it activate?
WHAT adjacent skill or task should not activate it?
Keep important negative-routing boundaries where they prevent ambiguity.
Move rationale, history, implementation details, and full policy explanation into the body or canonical documentation.
For example, agent-conduct could be structurally similar to:
description: >- Apply fleet conduct rules when about to claim work is complete or verified, when an ambiguity requires user confirmation, or when a failure or review exposes a durable lesson. Do not use for commits, PR-review mechanics, or prose when the corresponding specialist skill applies.
The final wording should be tested against the existing description for routing equivalence.
Similarly, pr-review-conduct could be structurally similar to:
description: >- Drive PR review through completion: request/recheck review after pushes, triage and resolve all findings including suppressed findings, verify review coverage of the current head SHA, and enforce the merge gate. Use for PR review loops, judging whether a PR is clean or mergeable, and before merge or auto-merge.
Details explaining whymergeStateStatus: CLEAN is insufficient belong in the skill body, not necessarily its discovery metadata.
Target approximately 50–75% reduction in description size, but validate routing before accepting the reduction.
3. Why This Exists sections frequently consume runtime context without changing execution
Several skills begin with substantial rationale or incident history.
Examples include:
agent-conduct: why decision-moment surfacing was needed.
repo-worktree: history of concurrent agents contaminating each other's commits.
comment-and-doc-style: why mechanical prose rules exist and which tools enforce them.
Language skills: explanation of why the language-specific guide is packaged as a skill.
These explanations are useful for maintainers and for understanding policy design.
They are less valuable every time the skill executes.
Desired approach
Retain a short rationale only where it helps the agent correctly interpret a surprising rule.
For example:
The worktree must exist before the first write because isolation at commit
time is too late to prevent another task's files from entering the tree.
This is useful.
A full historical incident narrative should live in durable documentation rather than be repeatedly loaded as runtime instruction.
General rule:
Preserve rationale that changes interpretation. Move rationale that merely explains history.
4. Use references/ more aggressively for progressive disclosure
The repository already uses skill references, which is the correct mechanism.
Some SKILL.md files still contain material that is better suited to references.
repo-worktree
The mandatory runtime behavior is relatively small:
Every task gets an isolated worktree.
Isolation occurs before the first write.
Use the correct base branch.
Continuation still requires isolation.
Do not commandeer another task's tree.
Commands for creation/continuation/cleanup.
The skill also contains extensive explanation of:
Flat repository naming.
Fork naming.
Upstream checkout naming.
Adopted repository semantics.
Collision behavior.
Hyphen ambiguity.
Relationship between namespace and repository ownership.
This is useful but is not required for the normal "create a worktree for this task" path.
The main skill can establish the critical profile decision concisely:
build:
PEP 621 project/package, uv.lock, uv run, pytest
lint-only:
stdlib utility scripts, no [project], no lockfile, uvx, unittest
Determine the profile from repository state before applying profile-specific rules.
The detailed contract can then be loaded when the task actually changes project infrastructure.
Some rules need to exist in canonical policy and be surfaced at the exact point where an agent is likely to violate them.
Examples include:
Explicit maintainer permission before merge.
Verification before claiming success.
Worktree isolation before the first write.
Review of the current head SHA before declaring a PR mergeable.
These are valuable repetitions.
Use this rule when deduplicating:
Duplicate the imperative when timing requires it. Do not duplicate the complete rationale and policy exposition.
A skill can therefore say:
Do not merge without explicit maintainer permission.
even when GOVERNANCE.md already contains the complete authorization policy.
It does not need to reproduce the entire policy explanation.
6. Preserve the current precision of decision gates
One of the strongest properties of the current instructions is that important rules generally resolve cleanly.
For example, pr-review-conduct provides an explicit merge gate and distinct dispositions for review findings.
repo-worktree defines the isolation boundary as before the first file edit, rather than using vague wording such as "use worktrees when appropriate."
Do not trade this precision for brevity.
Prefer:
WHEN <condition>
DO <action>
UNLESS <explicit exception>
Avoid compressions that turn deterministic policy into suggestions such as:
Consider...
Usually...
When appropriate...
Prefer...
unless the existing policy genuinely intends discretion.
7. comment-and-doc-style has a broad activation surface
comment-and-doc-style currently covers:
Code comments.
Workflow comments.
Markdown.
Character-set rules.
Line endings.
Tool casing.
Carried instruction files.
PR titles.
Commit messages.
This means relatively small text changes can activate a comparatively large skill.
Do not immediately split the skill solely for token reduction, because additional skills increase routing metadata and can introduce overlap.
First:
Shorten its description.
Reduce its main body.
Move uncommon Markdown, line-ending, and carried-document mechanics into references.
Measure the resulting runtime size.
Only consider splitting into narrower skills if empirical evaluation shows that the remaining skill is still too expensive or routing improves with separation.
Token-Cost Model
Optimization should account for load frequency.
Conceptually:
effective cost ≈ tokens loaded × number of times loaded
Therefore prioritize:
Tier 1: Always-loaded instructions
Examples:
AGENTS.md
Every unnecessary token here is expensive.
Optimize aggressively while retaining all universal constraints and routing information.
Tier 2: Skill metadata/descriptions
Descriptions may participate in skill discovery even when the full skill does not load.
These should be compact, discriminative classifier prompts.
Optimize aggressively while measuring routing quality.
Optimize primarily for accuracy, clarity, and maintainability rather than minimum size.
This is where detailed examples, uncommon edge cases, historical explanation, tables, and complete mechanics should generally live.
Tier 5: Canonical policy documentation
GOVERNANCE.md, CODESTYLE.md, WORKFLOW.md, and related authoritative documents should optimize primarily for correctness, completeness, and maintainability.
Do not damage the canonical specification merely to reduce its byte count if agents can selectively read the relevant section.
Proposed Evaluation Method
Do not accept a refactor based solely on token reduction.
Create a representative evaluation set covering actual fleet behavior.
repo-worktree activates before first edit
comment-and-doc-style activates
For pr-review-conduct:
"Checks are green. Merge the PR."
Expected:
pr-review-conduct activates
agent does not infer mergeability from green checks
current-head review state is verified
explicit merge authorization semantics are preserved
For dotnet-codestyle:
"Silence CAxxxx in this project."
Expected:
dotnet-codestyle activates
suppression hierarchy is followed
blanket suppression is not introduced merely to make the build pass
Include negative cases where neighboring skills should not activate.
Before/After Validation
Run the same evaluation set against:
A: current instructions
B: optimized instructions
Optionally:
C: no custom instructions
Measure:
Task success.
Skill-routing accuracy.
False-positive skill activation.
False-negative skill activation.
Instruction violations.
Safety/authorization violations.
Verification quality.
Unnecessary user questions.
Unnecessary tool calls.
Input/context tokens.
Output tokens.
Runtime.
An optimization should not merge merely because it saves tokens.
A meaningful regression in behavioral correctness should block the change.
Suggested Refactoring Order
Perform the work incrementally so regressions can be attributed.
Phase 1: Establish baseline
Inventory AGENTS.md and all skills.
Measure bytes and estimated/model-token counts.
Record skill description sizes separately from skill bodies.
Create representative routing and behavior tests.
Record baseline results.
Phase 2: Optimize AGENTS.md
Remove duplicated rationale.
Remove duplicated diagram/prose representations.
Reduce skill-system explanation.
Keep bootstrap, universal rules, authority, and routing.
Target approximately 40–60% reduction.
Run behavioral evaluation.
Phase 3: Optimize skill descriptions
For every description:
Retain ownership.
Retain positive activation triggers.
Retain meaningful negative boundaries.
Move rationale and mechanics into the body.
Target approximately 50–75% description reduction where possible.
Run routing evaluation after this phase.
Phase 4: Optimize skill bodies
Remove unnecessary Why This Exists material.
Preserve short rationale where it affects interpretation.
Eliminate policy exposition already available canonically.
Keep decision-point imperatives.
Move uncommon mechanics and examples to references/.
Run behavioral evaluation.
Phase 5: Review skill boundaries
After compression, identify skills that remain unusually large or activate too broadly.
Only then consider splitting or combining skills.
Avoid increasing skill count without evidence that routing or token cost improves.
Suggested Metrics Report
Produce a report similar to:
Artifact
Current tokens
Target tokens
Reduction
Load class
Notes
AGENTS.md
...
...
...%
Always
Highest priority
agent-conduct description
...
...
...%
Discovery
Preserve 3 trigger moments
agent-conduct/SKILL.md
...
...
...%
Conditional
Move rationale
repo-worktree description
...
...
...%
Discovery
Preserve first-write trigger
repo-worktree/SKILL.md
...
...
...%
Conditional
Extract layout theory
dotnet-codestyle/SKILL.md
...
...
...%
Conditional
Extract uncommon examples
python-codestyle/SKILL.md
...
...
...%
Conditional
Extract detailed profiles
comment-and-doc-style/SKILL.md
...
...
...%
Conditional/high frequency
Reduce before considering split
Also report:
Total always-loaded tokens:
Total skill-discovery tokens:
Median SKILL.md tokens:
Largest SKILL.md:
Total reference tokens:
The most important metrics are always-loaded tokens and skill-discovery tokens, not total repository documentation size.
Acceptance Criteria
AGENTS.md contains only bootstrap, genuinely always-on rules, authority/precedence information, and routing needed by every session.
Explanatory or historical material not needed at runtime is moved to appropriate canonical documentation.
Skill descriptions primarily express ownership, activation conditions, and necessary exclusions.
Skill descriptions do not contain detailed implementation mechanics better suited to the skill body.
Common-path rules remain directly in SKILL.md.
Uncommon mechanics, extensive examples, and edge cases use references/ where appropriate.
Intentional decision-point duplication of critical rules remains intact.
Safety, authorization, verification, and merge gates are not weakened.
Fleet-specific conventions remain explicit rather than being delegated to generic model knowledge.
A representative routing/behavior evaluation exists.
Optimized instructions pass the behavioral evaluation without material regression.
Before/after token measurements are recorded.
The final change demonstrates reduced effective token cost, not merely fewer bytes.
Guiding Principle
The desired end state is not "short instructions."
It is high-information-density instructions with progressive disclosure:
AGENTS.md:
What must I always know, and where do I go?
Skill description:
Should I load this skill?
SKILL.md:
What do I do now?
references/:
What details do I need for this particular case?
Canonical docs:
What is the complete policy, rationale, and source of truth?
Every token should have one clear job.
Optimize recurring context first, discovery context second, conditional execution context third, and rarely loaded reference material last.
The quality bar is unchanged:
Lower token cost with equivalent or better routing, correctness, verification, safety, and accuracy.
Optimize Agent Instructions and Skills for Token Efficiency
Summary
Audit and refactor
AGENTS.mdand.agents/skills/to reduce recurring and on-demand token consumption without weakening behavioral constraints, accuracy, verification requirements, safety rules, or skill routing.The current instruction architecture is fundamentally sound:
The main opportunity is not to remove rules. It is to ensure that each layer contains only the information needed at that layer.
The desired model is:
The optimization principle is:
A 500-token instruction loaded for every task can cost more over time than a 5,000-token reference loaded only for a rare operation.
Goals
Non-Goals
This is not an exercise in making instructions terse at all costs.
Do not:
SKILL.mdsmaller.Token reduction is successful only when behavior remains equivalent or improves.
Current Findings
1.
AGENTS.mdis the highest-priority optimization targetThe root
AGENTS.mdis approximately 17.5 KB.Its intended responsibility is already correctly described as:
That is the right architecture.
However, the file currently contains substantial explanatory material around those responsibilities, including:
AGENTS.md,GOVERNANCE.md,CODESTYLE.md,WORKFLOW.md, project-specific instructions, and Copilot instructions.Much of this information is useful durable documentation but does not need to occupy the always-on context.
Desired
AGENTS.mdshapeTarget roughly a 40–60% reduction, subject to behavioral validation.
Prefer a structure similar to:
Move architectural rationale and historical explanation to the canonical documentation rather than keeping it in the bootstrap.
For example, instead of a long explanation of document responsibilities, prefer something structurally equivalent to:
The exact wording should be derived from the existing policy so that no authority or precedence semantics are lost.
2. Skill descriptions are precise but substantially overlong
The current skill descriptions generally have excellent trigger specificity.
Examples include:
agent-conductpr-review-conductdotnet-codestylepython-codestylecomment-and-doc-stylerepo-worktreeTheir descriptions frequently contain all of the following:
GOVERNANCE.md.AGENTS.md.Only a subset is required for discovery.
Desired description structure
A skill description should primarily answer:
Keep important negative-routing boundaries where they prevent ambiguity.
Move rationale, history, implementation details, and full policy explanation into the body or canonical documentation.
For example,
agent-conductcould be structurally similar to:The final wording should be tested against the existing description for routing equivalence.
Similarly,
pr-review-conductcould be structurally similar to:Details explaining why
mergeStateStatus: CLEANis insufficient belong in the skill body, not necessarily its discovery metadata.Target approximately 50–75% reduction in description size, but validate routing before accepting the reduction.
3.
Why This Existssections frequently consume runtime context without changing executionSeveral skills begin with substantial rationale or incident history.
Examples include:
agent-conduct: why decision-moment surfacing was needed.repo-worktree: history of concurrent agents contaminating each other's commits.comment-and-doc-style: why mechanical prose rules exist and which tools enforce them.These explanations are useful for maintainers and for understanding policy design.
They are less valuable every time the skill executes.
Desired approach
Retain a short rationale only where it helps the agent correctly interpret a surprising rule.
For example:
This is useful.
A full historical incident narrative should live in durable documentation rather than be repeatedly loaded as runtime instruction.
General rule:
4. Use
references/more aggressively for progressive disclosureThe repository already uses skill references, which is the correct mechanism.
Some
SKILL.mdfiles still contain material that is better suited to references.repo-worktreeThe mandatory runtime behavior is relatively small:
The skill also contains extensive explanation of:
This is useful but is not required for the normal "create a worktree for this task" path.
Consider:
Keep the common layout in
SKILL.md:Load
repository-layout.mdonly when cloning, naming, adopting, forking, or resolving collisions.Language code-style skills
dotnet-codestyleandpython-codestyleare large, but their conditional nature makes that less problematic thanAGENTS.md.Still, consider separating common execution rules from reference material.
For example:
The main skill should retain rules commonly needed while editing .NET code:
Detailed XML documentation examples, uncommon analyzer cases, and extended mechanics can be references.
Similarly:
The main skill can establish the critical profile decision concisely:
The detailed contract can then be loaded when the task actually changes project infrastructure.
5. Preserve intentional decision-point duplication
Not all duplication is waste.
Some rules need to exist in canonical policy and be surfaced at the exact point where an agent is likely to violate them.
Examples include:
These are valuable repetitions.
Use this rule when deduplicating:
A skill can therefore say:
even when
GOVERNANCE.mdalready contains the complete authorization policy.It does not need to reproduce the entire policy explanation.
6. Preserve the current precision of decision gates
One of the strongest properties of the current instructions is that important rules generally resolve cleanly.
For example,
pr-review-conductprovides an explicit merge gate and distinct dispositions for review findings.repo-worktreedefines the isolation boundary as before the first file edit, rather than using vague wording such as "use worktrees when appropriate."Do not trade this precision for brevity.
Prefer:
Avoid compressions that turn deterministic policy into suggestions such as:
unless the existing policy genuinely intends discretion.
7.
comment-and-doc-stylehas a broad activation surfacecomment-and-doc-stylecurrently covers:This means relatively small text changes can activate a comparatively large skill.
Do not immediately split the skill solely for token reduction, because additional skills increase routing metadata and can introduce overlap.
First:
Only consider splitting into narrower skills if empirical evaluation shows that the remaining skill is still too expensive or routing improves with separation.
Token-Cost Model
Optimization should account for load frequency.
Conceptually:
Therefore prioritize:
Tier 1: Always-loaded instructions
Examples:
Every unnecessary token here is expensive.
Optimize aggressively while retaining all universal constraints and routing information.
Tier 2: Skill metadata/descriptions
Descriptions may participate in skill discovery even when the full skill does not load.
These should be compact, discriminative classifier prompts.
Optimize aggressively while measuring routing quality.
Tier 3:
SKILL.mdLoaded when a relevant skill activates.
Optimize moderately.
Keep common-path execution rules immediately available.
Tier 4:
references/Loaded only for particular subcases.
Optimize primarily for accuracy, clarity, and maintainability rather than minimum size.
This is where detailed examples, uncommon edge cases, historical explanation, tables, and complete mechanics should generally live.
Tier 5: Canonical policy documentation
GOVERNANCE.md,CODESTYLE.md,WORKFLOW.md, and related authoritative documents should optimize primarily for correctness, completeness, and maintainability.Do not damage the canonical specification merely to reduce its byte count if agents can selectively read the relevant section.
Proposed Evaluation Method
Do not accept a refactor based solely on token reduction.
Create a representative evaluation set covering actual fleet behavior.
For each test case define:
Include positive and negative routing cases.
Example skill-routing tests
For
repo-worktree:Expected:
For
pr-review-conduct:Expected:
For
dotnet-codestyle:Expected:
Include negative cases where neighboring skills should not activate.
Before/After Validation
Run the same evaluation set against:
Optionally:
Measure:
An optimization should not merge merely because it saves tokens.
A meaningful regression in behavioral correctness should block the change.
Suggested Refactoring Order
Perform the work incrementally so regressions can be attributed.
Phase 1: Establish baseline
AGENTS.mdand all skills.Phase 2: Optimize
AGENTS.mdPhase 3: Optimize skill descriptions
For every description:
Target approximately 50–75% description reduction where possible.
Run routing evaluation after this phase.
Phase 4: Optimize skill bodies
Why This Existsmaterial.references/.Run behavioral evaluation.
Phase 5: Review skill boundaries
After compression, identify skills that remain unusually large or activate too broadly.
Only then consider splitting or combining skills.
Avoid increasing skill count without evidence that routing or token cost improves.
Suggested Metrics Report
Produce a report similar to:
AGENTS.mdagent-conductdescriptionagent-conduct/SKILL.mdrepo-worktreedescriptionrepo-worktree/SKILL.mddotnet-codestyle/SKILL.mdpython-codestyle/SKILL.mdcomment-and-doc-style/SKILL.mdAlso report:
The most important metrics are always-loaded tokens and skill-discovery tokens, not total repository documentation size.
Acceptance Criteria
AGENTS.mdcontains only bootstrap, genuinely always-on rules, authority/precedence information, and routing needed by every session.SKILL.md.references/where appropriate.Guiding Principle
The desired end state is not "short instructions."
It is high-information-density instructions with progressive disclosure:
Every token should have one clear job.
Optimize recurring context first, discovery context second, conditional execution context third, and rarely loaded reference material last.
The quality bar is unchanged: