Demonstrates forked context execution. This skill runs in an isolated sub-agent context with its own conversation history and tool access.
This skill demonstrates the context: fork feature, which allows a skill to run in an isolated sub-agent context with its own conversation history and state.
When a skill uses context: fork, it:
agent field to determine sub-agent behaviorComplex Multi-Step Operations
Isolated Testing
Specialized Agent Behavior
State Management
context: fork # Enables forked context
agent: general-purpose # Specifies agent type
.claude/agents/Ask me to perform a complex analysis:
Analyze this codebase and create a detailed report
Behavior:
Test that the forked context has separate history:
First, tell me your name in the forked context
Then ask in the main conversation what we discussed
Expected: The main conversation won't see the forked context's internal messages
Test with different agent types:
# For planning tasks
context: fork
agent: Plan
# For exploration
context: fork
agent: Explore
# For code review
context: fork
agent: code-reviewer
Forked context works with hooks:
context: fork
agent: general-purpose
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "echo 'Forked context: Running Bash'"
Limit tools in forked context:
context: fork
agent: general-purpose
allowed_tools:
- Read
- Grep
# No Write - read-only analysis
Use specific model in forked context:
context: fork
agent: general-purpose
model: claude-sonnet-4-20250514
| Aspect | Non-Forked (Default) | Forked Context |
|---|---|---|
| Conversation History | Shared with main | Separate/isolated |
| State | Global state | Independent state |
| Tool Access | Inherits from main | Configured independently |
| Context Window | Uses main context | Separate context window |
| Overhead | None | Sub-agent creation |
| Use Case | Simple tasks | Complex/isolated tasks |
Main Conversation
↓
User requests task using context-fork-skill
↓
Skill Engine
↓
Detects context: fork
↓
Sub-Agent Factory
↓
Creates new agent instance
↓
Forked Context
↓
Executes task in isolation
↓
Returns results
↓
Main Conversation (receives results)
Forked context:
Forked context overhead:
Total overhead: ~150-250ms per invocation
Use for complex tasks
Choose appropriate agent
Combine with tool restrictions
Document the isolation
Don't use for simple tasks
Don't forget about isolation
Don't overuse
Don't assume shared state
Verify forked context behavior:
Problem: Skill runs in main context
Solutions:
context: fork is in YAML frontmatterProblem: Uses default agent instead of specified one
Solutions:
Problem: Forked context completes but no results
Solutions:
---
name: deep-code-analysis
description: Perform deep code analysis in isolation
context: fork
agent: Explore
allowed_tools:
- Read
- Grep
- Glob
---
Usage:
Analyze the authentication system deeply
---
name: security-audit
description: Run security audit in isolated context
context: fork
agent: general-purpose
allowed_tools:
- Read
- Grep
- Bash
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "echo 'Security audit: Executing command'"
---
---
name: architecture-planner
description: Create architecture plan in isolation
context: fork
agent: Plan
---
Usage:
Create a detailed plan for refactoring the payment system
Forked context provides:
Use when you need isolation, complex processing, or specialized agent behavior.
Version: 1.0.0 Last Updated: 2026-01-10 Maintainer: SDK Team