Learn Claude Code: Custom Skills Running Skills in Subagents

Running Skills in Subagents

Intermediate 🕐 13 min Lesson 6 of 11
What you'll learn
  • Use <code>context: fork</code> to run a skill in an isolated subagent context
  • Choose the right agent type for a forked skill based on what tools and context it needs
  • Prevent subagent skills from interrupting the main conversation with <code>disallowed-tools</code>

When a skill needs isolation

Most skills run inline — their content enters the current conversation and Claude acts on it with full access to everything in context. That is usually what you want.

But some skills work better in a clean environment. A research skill that searches the codebase should not need to wade through ten turns of deployment discussion to understand what it is looking for. A PR summary skill that fetches live GitHub data and produces a structured report does not need your conversation history at all — it just needs the PR data and a task.

Adding context: fork to a skill's frontmatter runs the skill in a subagent with a fresh context. The skill content becomes the subagent's prompt. Results come back to your main conversation as a summary.

The PR summary example

This skill fetches a live PR, analyzes it in isolation, and returns a clean summary to your main session:

---
name: pr-summary
description: Summarize changes in a pull request. Use when the user asks to review or summarize a PR.
context: fork
agent: Explore
allowed-tools: Bash(gh *)
---

## Pull request context

- PR diff: !`gh pr diff`
- PR comments: !`gh pr view --comments`
- Changed files: !`gh pr diff --name-only`
- PR description: !`gh pr view`

## Your task

Summarize this pull request:
1. What does it do? (2-3 sentences)
2. Key implementation decisions
3. Potential risks or review focus areas
4. Missing: tests, documentation, migration steps?

When you invoke /pr-summary, Claude Code runs the four gh commands via injection, then spawns an Explore subagent with the fully-rendered content as its prompt. The subagent produces the summary and the result appears in your main conversation.

Choosing the right agent

The agent frontmatter field specifies which subagent type to use. The most useful options:

Agent
Tools
Loads CLAUDE.md
Best for
Explore
Read-only
No
Research, codebase search, PR analysis
general-purpose
All tools
Yes
Implementation tasks, anything that writes files
Custom agent
Defined in .claude/agents/
Depends on agent
Specialized workflows with specific tool sets

Explore is the right choice for skills that only need to read — it starts faster, uses less context, and cannot accidentally modify files. Use general-purpose when the skill needs to make changes. If agent is omitted, general-purpose is the default.

The Explore and Plan built-in agents skip CLAUDE.md and git status at startup to keep their context small. A forked skill using agent: Explore sees only its own SKILL.md content and the agent's system prompt.

Preventing interruptions with disallowed-tools

A forked skill running autonomously should not pause to ask you questions. Adding disallowed-tools: AskUserQuestion to the frontmatter removes Claude's ability to interrupt during the skill's run. The restriction clears automatically when you send your next message to the main conversation.

---
name: daily-standup
description: Prepare a standup summary from recent commits and open PRs
context: fork
agent: Explore
allowed-tools: Bash(git *) Bash(gh *)
disallowed-tools: AskUserQuestion
---

Prepare a daily standup summary:

## Recent work
!`git log --oneline --since="24 hours ago" --author="$(git config user.name)"`

## Open PRs
!`gh pr list --author @me --json number,title,reviewDecision`

## Tasks
Summarize what was completed yesterday, what is in progress today, and whether any PR reviews are needed. Be concise — standup format.

Inline vs fork: the trade-off

Forked skills are not always better. The fork creates a subagent with a separate context, which takes slightly longer to spin up and means the subagent cannot use anything from your current conversation as background. An inline skill that references a file you just discussed can use that context; a forked skill cannot.

Use context: fork when:

  • The skill produces a self-contained output (report, summary, analysis) that does not need conversation history
  • You want the skill to run without influencing the current context budget
  • The skill needs to run many tool calls autonomously without per-step prompts

Run inline (no context: fork) when:

  • The skill needs to know what you have been discussing
  • The skill's instructions should influence how Claude handles the rest of the conversation
  • The skill is short and the overhead of a subagent is not worth it
Key takeaways
  • <code>context: fork</code> runs a skill in an isolated subagent — the skill content becomes the subagent's prompt and results are returned to your main conversation
  • The <code>Explore</code> agent is the right choice for read-only research skills — it starts lighter, cannot modify files, and skips CLAUDE.md for a clean context
  • <code>disallowed-tools: AskUserQuestion</code> prevents an autonomous forked skill from interrupting the session — the restriction clears on your next message
  • Inline skills can use current conversation context; forked skills start fresh — choose based on whether conversation history is relevant to the task
  • The <code>agent</code> field accepts built-in types (Explore, Plan, general-purpose) or any custom agent defined in <code>.claude/agents/</code>