Optimize skills for Claude Code context efficiency#3
Optimize skills for Claude Code context efficiency#3alexei-led wants to merge 1 commit intovladikk:mainfrom
Conversation
balanced-coupling/SKILL.md (329→194 lines, ~41% token reduction): - Collapse Sections 1.1-1.3 (Cynefin, modularity definition) to activation hints — Opus already knows these concepts, brief reminders suffice - Convert integration strength levels from #### headers to numbered list — preserves Vlad's explanatory language in more token-efficient format - Add 4 worked classification examples after strength levels — research shows few-shot examples give 50-70% accuracy gains in taxonomy tasks - Collapse Section 3 (Fractal Geometry) to single paragraph — principle already introduced in Section 2.2 (distance is relative) - Delete Section 6 ASCII diagram — LLMs don't parse ASCII art meaningfully; every element is already stated in Sections 2-4 - Delete Core Principles list — each item restates the body verbatim; "prior models incorporated" framing moved to Section 2.1 - Remove Implicit-Explicit Spectrum subsection — already embedded in each level definition (intrusive="implicit", contract="explicit") - Move "Communicating with the User" to review/design skills where user interaction actually happens - Rewrite description as reference-oriented to fix trigger overlap with review and design skill descriptions balanced-coupling/details.md (new, 45 lines): - Lazy-loaded reference for content split from SKILL.md - Implicit-explicit spectrum elaboration - Connascence degrees (static/dynamic) with ordering - DDD tactical design connections (aggregates, business logic patterns) - DDD strategic integration pattern mapping review/SKILL.md: - Add context: fork — codebase file contents accumulate during analysis; fork keeps them in subagent context, not main conversation - Sharpen description to emphasize "existing codebase" as input - Add DDD plain-language communication constraint (moved from balanced-coupling) - Make HTML output conditional in Step 4 design/SKILL.md: - Add context: fork — same reasoning as review - Sharpen description to emphasize "functional requirements document" - Replace AskUserQuestion markdown tables with compact inline format — saves ~200 tokens; LLMs don't need tabular format for tool call params - Add file verification step after Step 5 - Add DDD plain-language communication constraint document/SKILL.md: - Make HTML generation optional — Markdown always generated, HTML only when explicitly requested. Useful when working in Claude Code where HTML rendering isn't needed.
There was a problem hiding this comment.
Pull request overview
Reduces Claude Code skill context usage by condensing and restructuring the Balanced Coupling reference and tightening review/design/document skill instructions, while introducing a lazy-loaded extended reference.
Changes:
- Condensed
balanced-coupling/SKILL.mdand added worked classification examples; moved deep-dive content into a newdetails.md. - Added
context: forkand clarified routing/constraints inreviewanddesignskills. - Made HTML generation optional in the
documentskill (Markdown always generated).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| skills/review/SKILL.md | Adds context: fork, clarifies “existing codebase” scope, and aligns output to optional-HTML document behavior. |
| skills/design/SKILL.md | Adds context: fork, clarifies “requirements doc” scope, compacts AskUserQuestion instructions, and adds output verification step + DDD-term explanation constraint. |
| skills/document/SKILL.md | Updates contract to always write Markdown and only generate HTML when explicitly requested; adjusts output instructions accordingly. |
| skills/balanced-coupling/SKILL.md | Condenses foundations, restructures integration strength into an ordered list, adds examples, and references a lazy-loaded extended file. |
| skills/balanced-coupling/details.md | New on-demand extended reference for implicit/explicit spectrum, connascence degrees, and additional DDD mappings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Then validate using `AskUserQuestion` — Header: "Subdomains", Options: "Approved — All correct", "Some are wrong — I'll tell you which to change", "Missing subdomains — There are areas not listed". If the user says some are wrong, ask which ones and what the correct classification should be. | ||
|
|
||
| | Header | Question | Options | | ||
| | ---------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| | Subdomains | Do these subdomain classifications look right? | 1. **Approved** - All correct 2. **Some are wrong** - I'll tell you which to change 3. **Missing subdomains** - There are areas not listed | | ||
|
|
||
| If the user says some are wrong, ask which ones and what the correct classification should be. | ||
|
|
||
| Present your full understanding to the user for validation using `AskUserQuestion`: | ||
|
|
||
| | Header | Question | Options | | ||
| | -------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Approval | Does this understanding of the requirements look correct? | 1. **Approved** - Proceed to architecture design 2. **Needs changes** - I'll explain what's wrong 3. **Missing context** - There's more I should tell you | | ||
| Present your full understanding to the user for validation using `AskUserQuestion` — Header: "Approval", Options: "Approved — Proceed to architecture design", "Needs changes — I'll explain what's wrong", "Missing context — There's more I should tell you". |
There was a problem hiding this comment.
The AskUserQuestion instructions here omit the Question: field (only Header: and Options: are provided). Elsewhere in this same skill you explicitly include Question: (e.g., in the Input section), and the tool call typically requires it; without it, implementations may reject the call or produce a low-quality prompt. Add a clear Question: string for this prompt (and the other condensed prompts below).
| | Header | Question | Options | | ||
| | -------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Approval | Does this modular architecture look correct? | 1. **Approved** - Proceed to design documents 2. **Needs changes** - I'll explain what to adjust 3. **Rethink** - Let's reconsider the module boundaries | | ||
| Validate using `AskUserQuestion` — Header: "Approval", Options: "Approved — Proceed to design documents", "Needs changes — I'll explain what to adjust", "Rethink — Let's reconsider the module boundaries". |
There was a problem hiding this comment.
This AskUserQuestion instruction is missing an explicit Question: field. To keep tool calls consistent and avoid schema/tooling failures, include a concrete question string (as done elsewhere in this file).
| Validate using `AskUserQuestion` — Header: "Approval", Options: "Approved — Proceed to design documents", "Needs changes — I'll explain what to adjust", "Rethink — Let's reconsider the module boundaries". | |
| Validate using `AskUserQuestion` — Header: "Approval", Question: "Do you approve this modular architecture so we can proceed to writing the design documents?", Options: "Approved — Proceed to design documents", "Needs changes — I'll explain what to adjust", "Rethink — Let's reconsider the module boundaries". |
| | Header | Question | Options | | ||
| | ------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Modules | All module design documents have been written. How do they look? | 1. **Approved** - Proceed to test specifications 2. **Needs changes** - I'll explain which modules need work 3. **Revisit architecture** - The documents reveal a boundary problem | | ||
| After writing all module documents, present the complete set using `AskUserQuestion` — Header: "Modules", Options: "Approved — Proceed to test specifications", "Needs changes — I'll explain which modules need work", "Revisit architecture — The documents reveal a boundary problem". |
There was a problem hiding this comment.
This condensed AskUserQuestion instruction omits the Question: field. Add an explicit question so the tool call is well-formed and consistently specifies what the user is approving.
| After writing all module documents, present the complete set using `AskUserQuestion` — Header: "Modules", Options: "Approved — Proceed to test specifications", "Needs changes — I'll explain which modules need work", "Revisit architecture — The documents reveal a boundary problem". | |
| After writing all module documents, present the complete set using `AskUserQuestion` — Header: "Modules", Question: "Do you approve this complete set of module design documents?", Options: "Approved — Proceed to test specifications", "Needs changes — I'll explain which modules need work", "Revisit architecture — The documents reveal a boundary problem". |
| | **Low Strength** | **Low Cohesion** (Complexity) — Unrelated components located close together. Increases cognitive load. Drifts toward big ball of mud. | **Loose Coupling** (Modularity) — Low strength minimizes cascading changes. High distance is balanced. | | ||
| | **High Strength** | **High Cohesion** (Modularity) — Components must co-evolve, but low distance makes cascading changes cheap. | **Tight Coupling** (Complexity) — Frequent cascading changes (high strength) that are expensive to implement (high distance). A step toward a distributed monolith. | | ||
|
|
||
| ### 4.2The Balance Rule |
There was a problem hiding this comment.
The heading is missing a space after the section number (### 4.2The ...). This reads oddly and can interfere with consistent formatting/TOC generation. Insert a space after 4.2.
| ### 4.2The Balance Rule | |
| ### 4.2 The Balance Rule |
| Write to `docs/modularity-review/!`date +%Y-%m-%d`/`: | ||
|
|
||
| 1. `docs/modularity-review/!`date +%Y-%m-%d`/modularity-review.md` — the Markdown version | ||
| 2. `docs/modularity-review/!`date +%Y-%m-%d`/modularity-review.html` — the HTML version | ||
| 1. `docs/modularity-review/!`date +%Y-%m-%d`/modularity-review.md` — **always generated** | ||
| 2. `docs/modularity-review/!`date +%Y-%m-%d`/modularity-review.html` — **only when HTML is requested** |
There was a problem hiding this comment.
The output path is written using nested backticks (`docs/modularity-review/!`date +%Y-%m-%d`/`), which breaks Markdown inline-code formatting and renders ambiguously. Use an escaping approach that preserves the literal text (e.g., a fenced code block or wrapping the whole path in double backticks) so the intended shell substitution syntax is readable.
What this PR does
Optimizes all four plugin skills for Claude Code context/token efficiency while preserving your content and framework intact. No concepts are removed — content is either reformatted for better LLM consumption, condensed to activation hints where Opus already has strong prior knowledge, or split to a lazy-loaded reference file.
Why
When
reviewordesignis invoked,balanced-couplingSKILL.md loads automatically into context (~4,400 tokens). This analysis found that ~40% of those tokens are spent on content that either duplicates other sections, uses LLM-incompatible formats (ASCII art), or teaches concepts that Opus 4.6 already knows well. The changes reduce the automatic context cost to ~2,600 tokens per invocation while likely improving classification accuracy through added worked examples.The analysis was informed by:
Changes by file
balanced-coupling/SKILL.md(329 → 194 lines, ~41% reduction)Condensed (content preserved as brief activation hints):
Sections 1.1–1.3 (Cynefin framework explanation, modularity definition, coupling philosophy) — Opus reliably knows these concepts from training. The specific framing is kept ("coupling is a design tool", "complexity is subjective", the working memory limit) but the multi-paragraph explanations are collapsed to a focused paragraph. Section 1.4 ("The Shared Cause") is kept verbatim — it establishes the conceptual bridge that coupling drives both modularity and complexity.
Section 3 (Fractal Geometry) — The fractal principle is already introduced in Section 2.2 ("Distance Is Relative to the Observed Level of Abstraction") with the same examples. Section 3 is collapsed to a single paragraph retaining the key instruction: always establish which abstraction level you're analyzing.
Reformatted (same content, more LLM-efficient structure):
Integration strength levels — Converted from
####header sections with multi-paragraph prose to a numbered ordered list. Your explanatory language is preserved in each item (intrusive = "fragile and implicit", the duplicated knowledge example for functional coupling, etc.). Research shows ordered lists convey ordinal relationships more efficiently to LLMs than prose sections with headers. The classic coupling model correspondences are kept as parenthetical anchors:(cf. content/pathological coupling).Description — Rewritten from action-oriented ("Use when: designing modular architectures, evaluating coupling...") to reference-oriented ("Domain knowledge reference... Loaded as a dependency by the review and design skills"). The original phrasing overlapped with
reviewanddesigndescriptions, creating potential routing ambiguity in Claude Code's skill selection.Removed (duplicated content):
Section 6 ASCII diagram (40 lines) — LLMs process ASCII art as raw text tokens without reconstructing the visual layout. Every element in the diagram (the three dimensions, their sub-items, the balance rule, the key insight) is already stated as prose in Sections 2–4. This is the single largest token savings in the PR.
Core Principles list (10 lines) — Each of the 8 items restates a point from the body. End-of-document summaries help humans who skim a document; they add zero information for an LLM that has already processed the full context window. The one item with unique framing — "Prior models are incorporated, not replaced" — was moved to Section 2.1 where the classic coupling model references appear.
Implicit-Explicit Spectrum subsection — Each strength level's definition already describes its implicit/explicit nature (intrusive = "implicit and fragile", contract = "explicit and stable"). The separate subsection restated this as a 4-item summary list. The content is preserved in the new
details.mdreference file.Moved (to action skills where it's actually used):
reviewanddesignskills that actually generate responses to users, not in the knowledge reference document. Added as a constraint in both skills: "Explain DDD terms on first use."Added:
4 worked classification examples after the strength level definitions — Research on LLM taxonomy classification shows that few-shot examples produce 50–70% accuracy gains, particularly at boundary cases (e.g., is shared event schema intrusive or functional coupling?). The examples cover one scenario per strength level with explicit reasoning. This is likely the highest-ROI single change in the PR.
"Prior models incorporated, not replaced" framing in Section 2.1 — Moved from the deleted Core Principles list. Provides important context that this framework builds on module coupling and connascence rather than replacing them.
balanced-coupling/details.md(new, 45 lines)Lazy-loaded reference file for content that was split from SKILL.md. This file is not loaded automatically — Claude only reads it during deep analysis when it needs connascence-level granularity or detailed DDD pattern mapping. Zero cost on standard invocations.
Contains:
review/SKILL.md(88 → 91 lines)context: fork— The review skill reads extensive codebase contents during analysis. Without fork, all file contents accumulate in the main conversation's context window, compounding the already-heavy skill payload. With fork, the skill runs in an isolated subagent — file contents stay in the subagent's context, and only the final review returns to the main conversation.AskUserQuestionstill works in forked context.Sharpened description — First sentence now reads "Analyzes an existing codebase for modularity imbalances..." with explicit disambiguation: "use the design skill to create architectures from requirements instead." This prevents routing confusion when a user prompt matches both skills.
DDD communication constraint — Added from the moved "Communicating with the User" section: explain core/supporting/generic subdomains in plain language on first use.
HTML output now conditional — Step 4 aligned with the document skill change (see below).
design/SKILL.md(247 → 237 lines)context: fork— Same reasoning as review. The design skill reads requirements files and writes multiple output documents.Sharpened description — First sentence now reads "Designs modular architecture from a functional requirements document..." with disambiguation toward review for existing codebases.
Compacted AskUserQuestion tables — Three 3-column markdown tables (~200 tokens) described
AskUserQuestiontool call parameters (Header, Question, Options). Replaced with compact inline format:Header: "Approval", Options: "Approved — Proceed to design documents", .... LLMs don't need tabular format to understand tool call parameters — the inline format conveys identical information.File verification step — Added after Step 5: "verify all expected output files exist and are non-empty." The design skill writes architecture documents, module designs, and test specs across multiple directories — a verification step catches silent write failures.
DDD communication constraint — Same as review.
document/SKILL.md(153 → 154 lines)What was NOT changed
assets/template.html) — still available when HTML is requestedskills:frontmatter on review/design — working dependency mechanismTesting notes
context: forkon review/design should be tested to verify thatskills:dependency loading works correctly in forked subagent context. If it doesn't, the fix is removing one frontmatter line from each file.