Running Skills in a Subagent and the Skill Lifecycle
context: fork — Run a Skill in Isolation
By default a skill's instructions join your current conversation. Adding context: fork to the frontmatter runs the skill in an isolated subagent instead — the SKILL.md content becomes the prompt that drives that subagent, which works in its own context and returns only a result. This is how you get a skill's benefits without its (possibly verbose) work cluttering your main thread.
---
name: deep-research
description: Research a topic thoroughly
context: fork
agent: Explore
---
Research $ARGUMENTS thoroughly:
1. Find relevant files using Glob and Grep
2. Read and analyze the code
3. Summarize findings with specific file referencesForking needs a TASK, not just guidelines
context: fork only makes sense for skills with explicit instructions to DO something. If your skill is pure reference ('use these API conventions') with no task, the subagent receives guidelines but no actionable prompt and returns nothing useful. Fork task-skills, keep reference-skills inline.
The agent Field
When context: fork is set, the agent field picks which subagent configuration runs the skill — determining the model, tools, and permissions. Options are the built-in Explore, Plan, or general-purpose, or any custom subagent from .claude/agents/. If omitted, it defaults to general-purpose.
| agent value | What it provides |
|---|---|
| Explore | Read-only, Haiku — fast codebase research (skips CLAUDE.md/git for speed) |
| Plan | Read-only research for planning |
| general-purpose (default) | All tools, inherits main model — full capability |
| a custom agent | Your own .claude/agents/ definition's model and tools |
The agent field decides the execution environment for a forked skill. Explore is great for read-only research tasks.
Skills + Subagents, Both Directions
Skills and subagents combine two ways, and it's worth keeping them straight. (1) A SKILL with context: fork runs inside a subagent — the skill IS the task. (2) A SUBAGENT can preload skills via its skills: frontmatter field — the skill is reference material the subagent carries. Crucially, subagents do NOT inherit your skills automatically; you must list them.
Two directions: a forked skill runs AS a subagent (skill = task); a subagent's skills: field preloads skills as reference (skill = knowledge).
The Skill Content Lifecycle
Once a skill is invoked, its rendered SKILL.md content enters the conversation as a single message and STAYS there for the rest of the session — Claude Code does not re-read the file on later turns. So write instructions that should apply throughout a task as standing guidance, not one-time steps.
- •Invoked skill content persists across turns (it isn't re-read each turn).
- •Auto-compaction re-attaches recent skills within a ~25,000-token budget (first 5,000 tokens of each), most-recent first — older skills can drop after compaction.
- •If a skill seems to stop influencing behavior, the content is usually still present; strengthen its description/instructions, or re-invoke it after compaction.
- •For guaranteed behavior, pair skills with hooks (deterministic) rather than relying on the model to keep preferring the skill.
Section complete
You've mastered multi-file skills, dynamic injection, and subagent execution. Next section covers getting skills to OTHER people: scope, precedence, and sharing via git, plugins, and managed settings.
Key Takeaways
- ✓context: fork runs a skill in an isolated subagent — the SKILL.md content becomes the subagent's task prompt; only the result returns.
- ✓context: fork only suits skills with an explicit TASK; pure reference skills should stay inline (a forked reference skill has no actionable prompt).
- ✓The agent field (Explore / Plan / general-purpose / custom) sets the model, tools, and permissions for a forked skill; defaults to general-purpose.
- ✓Skills + subagents combine two ways: a forked skill runs AS a subagent (skill = task); a subagent's skills: field preloads skills as REFERENCE.
- ✓Subagents do NOT inherit your skills automatically — you must list them in the subagent's skills: field.
- ✓Invoked skill content stays in context for the session (not re-read); auto-compaction re-attaches recent skills within ~25k tokens — re-invoke or use hooks if behavior fades.
Check Your Understanding
Test what you learned in this lesson.
Q1.What does adding context: fork to a skill's frontmatter do?
Q2.Why does context: fork only make sense for skills with explicit instructions?
Q3.Do subagents automatically have access to your skills?
Q4.What happens to a skill's content after it's invoked, across later turns?
Practice This Lesson