claude-code - 💡(How to fix) Fix [FEATURE] Conditional section loading in skills based on $ARGUMENTS [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49090Fetched 2026-04-17 08:51:08
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
0
Timeline (top)
commented ×2labeled ×2

When a skill is invoked, the entire SKILL.md is injected into the context regardless of which subcommand/argument the user passes. For skills with multiple subcommands, this creates significant token waste — the model receives instructions for all operations when it only needs one.

Root Cause

When a skill is invoked, the entire SKILL.md is injected into the context regardless of which subcommand/argument the user passes. For skills with multiple subcommands, this creates significant token waste — the model receives instructions for all operations when it only needs one.

Fix Action

Fix / Workaround

Current workaround: Split into separate skills (my-tool-create, my-tool-list, etc.). This works but:

  • Clutters the skills list (each entry costs ~14 tokens in the listing, always present)
  • Loses the ergonomic single-command UX (/my-tool list vs /my-tool-list)
  • Duplicates shared context (common paths, conventions) across files

Code Example

---
name: my-tool
argument-hint: "[create|list|delete|info] [name]"
---

---

## Argument parsing
Parse $ARGUMENTS to extract subcommand...

## Subcommand: create
(~150 tokens of instructions)

## Subcommand: list
(~100 tokens of instructions)

## Subcommand: delete
(~80 tokens of instructions)

## Subcommand: info
(~60 tokens of instructions)

---

my-tool/
├── SKILL.md           # shared context (always loaded)
├── create.md          # loaded when $ARGUMENTS starts with "create"
├── list.md            # loaded when $ARGUMENTS starts with "list"
└── ...

---

---
name: my-tool
routes:
  - match: "^create"
    include: create.md
  - match: "^list"
    include: list.md
---

# Shared context (always loaded)
...

---

---
name: my-tool
sections:
  create:
    match: "^create"
    file: create.md
  list:
    match: "^list"
  default:
    match: "*"
---

---

<!-- @if $ARGUMENTS starts with "create" -->
## Create instructions
...
<!-- @endif -->

<!-- @if $ARGUMENTS starts with "list" -->
## List instructions
...
<!-- @endif -->
RAW_BUFFERClick to expand / collapse

Summary

When a skill is invoked, the entire SKILL.md is injected into the context regardless of which subcommand/argument the user passes. For skills with multiple subcommands, this creates significant token waste — the model receives instructions for all operations when it only needs one.

Problem

Consider a skill with 4 subcommands (~500 tokens total prompt):

---
name: my-tool
argument-hint: "[create|list|delete|info] [name]"
---
## Argument parsing
Parse $ARGUMENTS to extract subcommand...

## Subcommand: create
(~150 tokens of instructions)

## Subcommand: list
(~100 tokens of instructions)

## Subcommand: delete
(~80 tokens of instructions)

## Subcommand: info
(~60 tokens of instructions)

When the user runs /my-tool list, all ~500 tokens are injected — but only ~100 are relevant. The other ~400 tokens are dead weight.

Current workaround: Split into separate skills (my-tool-create, my-tool-list, etc.). This works but:

  • Clutters the skills list (each entry costs ~14 tokens in the listing, always present)
  • Loses the ergonomic single-command UX (/my-tool list vs /my-tool-list)
  • Duplicates shared context (common paths, conventions) across files

Token cost analysis

ApproachSkills list cost (always)Per-invocation cost
1 skill, 4 subcommands~14 tokens~500 tokens (all sections)
4 separate skills~56 tokens~60-150 tokens (only relevant)
Proposed: conditional sections~14 tokens~60-150 tokens (only relevant)

Proposed solution

Allow SKILL.md to define conditional sections that are only included when $ARGUMENTS matches a pattern. Possible syntax options:

Option A: Multi-file skill with argument routing (recommended)

my-tool/
├── SKILL.md           # shared context (always loaded)
├── create.md          # loaded when $ARGUMENTS starts with "create"
├── list.md            # loaded when $ARGUMENTS starts with "list"
└── ...

With frontmatter routing:

---
name: my-tool
routes:
  - match: "^create"
    include: create.md
  - match: "^list"
    include: list.md
---

# Shared context (always loaded)
...

Option B: Frontmatter-based sections

---
name: my-tool
sections:
  create:
    match: "^create"
    file: create.md
  list:
    match: "^list"
  default:
    match: "*"
---

Option C: Markdown directive syntax

<!-- @if $ARGUMENTS starts with "create" -->
## Create instructions
...
<!-- @endif -->

<!-- @if $ARGUMENTS starts with "list" -->
## List instructions
...
<!-- @endif -->

Benefits

  1. Token efficiency — only load relevant instructions per invocation
  2. Clean UX — keep single skill with subcommands (/tool action)
  3. Lower skills list overhead — one entry instead of N
  4. Scales well — skills with many subcommands don't bloat context proportionally

Environment

  • Claude Code version: Latest (April 2026)
  • Platform: All

extent analysis

TL;DR

Implement conditional sections in SKILL.md to only include relevant instructions based on user input, reducing token waste and improving efficiency.

Guidance

  • Explore the proposed syntax options (Option A, B, or C) to determine the best approach for defining conditional sections in SKILL.md.
  • Consider the trade-offs between each option, such as the complexity of implementation and the flexibility of routing rules.
  • Evaluate the potential benefits of each option, including token efficiency, clean UX, and lower skills list overhead.
  • Test and validate the chosen approach to ensure it works as expected and does not introduce any unintended consequences.

Example

<!-- @if $ARGUMENTS starts with "create" -->
## Create instructions
...
<!-- @endif -->

<!-- @if $ARGUMENTS starts with "list" -->
## List instructions
...
<!-- @endif -->

This example illustrates the Markdown directive syntax (Option C) for defining conditional sections.

Notes

The proposed solution assumes that the Claude Code platform (version: Latest, April 2026) supports the implementation of conditional sections in SKILL.md. It is essential to verify the feasibility and compatibility of the chosen approach with the platform.

Recommendation

Apply the workaround of splitting skills into separate files (e.g., my-tool-create, my-tool-list, etc.) until a more permanent solution is implemented, as it provides a functional, albeit imperfect, solution to the problem.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING