skip to content

A Claude Code skill sets context: fork with agent: Explore — what does the forked run see, and when does that design backfire?

level: seniorimportance: should knowfreq 9%

answer

  1. fresh subagent, not a conversation copy
  2. SKILL.md becomes the task prompt
  3. agent decides tools and model
  4. background by default since 2.1.218
  5. guidelines without a task return nothing

basics

~20 s

A new Explore subagent starts with the SKILL.md content as its task and no conversation history; Explore also skips CLAUDE.md and git status. It backfires for reference-only skills and for tasks that depend on what was discussed.

solid answer

~50 s

`context: fork` makes Claude Code start a new subagent of the type named in `agent` (`Explore`, `Plan`, `general-purpose` or a custom agent from `.claude/agents/`; `general-purpose` when omitted). The agent type supplies the system prompt, tools and permissions, and the rendered `SKILL.md` becomes the task. Despite the name, it is not a fork of the conversation: the subagent sees none of your history, and `Explore` and `Plan` also skip CLAUDE.md and git status. Since 2.1.218 the fork runs in the background by default; `background: false` makes the invoking turn wait, and a backgrounded fork gets a narrower tool set and makes edits outside checkpoints, so `/rewind` cannot undo them. It backfires when the body is conventions with no task, since the subagent returns nothing useful, and when the work depends on context only the main conversation has.

code

yaml · 13 lines
yaml
---
name: migration-check
description: Check pending database migrations for table rewrites, missing rollbacks and other risky operations. Use before merging a schema change.
context: fork
agent: Explore
---

Review the five newest files under db/migrations/:

1. Flag statements that rewrite or lock a whole table.
2. Flag migrations with no rollback section.
3. Flag NOT NULL columns added without a default.
4. Report each finding with its file and line number.

go deeper

for a junior

Recall that context: fork runs the skill in a separate subagent whose type comes from the agent field, rather than inline in your conversation.

for a middle

Explain what the fork receives (SKILL.md as task, the agent type's prompt and tools) and what it lacks (history, and for Explore or Plan also CLAUDE.md).

for a senior

Show the release-aware failure modes: background by default since 2.1.218, background: false, the narrower background tool set, and edits that escape /rewind.

for a principal

Weigh isolating a skill's work to protect the main context against losing conversation state and undo, and set a team rule for which skills may fork.

## What `context: fork` does By default a skill runs **inline**: its rendered `SKILL.md` is added to your conversation and the main session follows it. Setting `context: fork` in the frontmatter changes that. Claude Code starts a **new subagent**, of the type the `agent` field names, and hands it the skill content as its prompt. The subagent works in its own context window and returns a summary to your conversation when it finishes. The `agent` field accepts the built-in `Explore`, `Plan` and `general-purpose` agents or any custom subagent defined in `.claude/agents/`. If `agent` is omitted, the fork uses `general-purpose`. The agent type determines the execution environment: its system prompt, its tools and its permissions. A `model` field in a forked skill's frontmatter sets the forked subagent's model rather than the session's. ## What the forked subagent sees | Input | Main conversation | Fork with `general-purpose` | Fork with `Explore` | | :- | :- | :- | :- | | Your conversation history | Yes | No | No | | Rendered `SKILL.md` | As a message | As its task | As its task | | System prompt | Claude Code's | The agent type's | The agent type's | | CLAUDE.md | Yes | Yes, per the agent's startup context | No | | Git status snapshot | Yes | Yes, when available | No | The name misleads: a `context: fork` skill does **not** run in a fork of the current conversation, which would hand the subagent everything discussed so far. When a task depends on that history, forking the conversation is the tool for it, not this field. ## Background by default (since 2.1.218) Since **Claude Code 2.1.218**, a forked skill runs in the **background**: you keep working, and its result arrives in the conversation when it completes. Before 2.1.218 a forked skill always blocked the turn. Today: - `background: false` in the frontmatter makes the invoking turn wait for the result. - Claude Code waits anyway in non-interactive runs (`-p` or the Agent SDK), when `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS` is `1`, when the same skill is invoked while an earlier run is still going, and when a scheduled task fires with the skill as its prompt. - A backgrounded fork runs with the **narrower tool set** that applies to background subagents. If the skill's steps need a tool outside that set, set `background: false`. - A backgrounded fork applies its edits **outside the session's checkpoints**, so `/rewind` does not undo them; revert with git. ## When the design backfires 1. **Reference content.** A body like "use these migration conventions" has no task. The subagent receives guidelines but nothing to do, and returns without meaningful output, while the main conversation, which needed the conventions, never receives them as instructions. Reference skills belong inline. 2. **Work that depends on the conversation.** "Check the migration we just discussed" fails because the fork has no history. The skill's instructions must stand on their own. 3. **Rules from CLAUDE.md that matter.** With `agent: Explore` or `Plan`, project memory is skipped to keep the context small. Restate any rule the task depends on inside `SKILL.md`. 4. **Edits you may want to undo.** Backgrounded edits escape `/rewind`; pick `background: false` or a read-only agent. 5. **A read-only agent for a writing task.** `Explore` provides read-only tools aimed at exploring code. A skill that must create a migration file needs `general-purpose` or a custom agent that can edit. ## Writing a forked skill that works Because the subagent starts with nothing but the skill and its agent type, the body has to carry everything: 1. Name the inputs explicitly: which directory, which files, which branch. 2. Restate any project rule the task depends on, especially with `Explore` or `Plan`. 3. Say what to return and in what shape, such as one finding per line with file and line number, since only the subagent's summary comes back. 4. Pick the agent by the tools the task needs, and decide up front whether the turn should wait. ## Where it fits A forked skill suits a **self-contained, explicit task** whose intermediate work would otherwise clutter the main context: reading every pending migration and reporting risky statements, for example. The inverse arrangement, a custom subagent that preloads skills as reference material through its own definition file, is a subagent-definition subject; here the skill writes the task and borrows an agent type to run it.

  • The forked migration-check skill reports a turn later, after you have moved on. How do you make the invoking turn wait for it?
    Set `background: false` in the skill's frontmatter, available since 2.1.218; the turn then blocks until the subagent returns, and the fork keeps the full tool set rather than the narrower background one. Claude Code also waits on its own in `-p` and Agent SDK runs, with `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1`, when the same skill is already running, and when a scheduled task fires it.
  • A backgrounded forked skill edited files and the result is wrong. Can /rewind undo it?
    No. A forked skill running in the background applies its edits outside the session's checkpoints, so `/rewind` does not restore them; revert with git. If a forked skill writes files you may want to roll back that way, set `background: false` or keep the fork on a read-only agent such as `Explore`.

  • context: fork hands the subagent a copy of the current conversation.
  • A forked skill always blocks the turn until its result comes back.
  • With agent: Explore, the fork still loads the project's CLAUDE.md.
  • context: fork works just as well for a conventions-only reference skill.
  • The agent field is mandatory; without it the fork cannot start.
  • /rewind reverts the edits a backgrounded forked skill made.

Assumes Claude Code 2.1.286; since 2.1.218 a context: fork skill runs in the background by default, and background: false makes the invoking turn wait.