Module 12: Session Fork
Creating parallel conversation branches for exploration.
What You’ll Learn
- Forking a session to create independent branches
- Using
CLIOptions.forkSession(true)
- When forking is preferable to continuing
Fork vs Resume
Why Fork?
Forking creates a snapshot you can explore without affecting the original:
- Try alternative approaches
- Run “what if” scenarios
- Parallel experimentation
- Safe exploration without side effects
Forking a Session
How Forking Works
Fork Use Cases
Key Points
- Fork copies context but creates a new session ID
- Original session remains unchanged
- Both branches can continue independently
- Forked sessions can be forked again
Tradeoffs
- Storage multiplication: Each fork creates a full copy of the session state. Forking a large conversation multiple times increases storage proportionally.
- No merge capability: Forked branches cannot be merged back. Insights from one branch must be manually transferred to another.
- Coordination complexity: Managing multiple active branches requires tracking multiple session IDs and their relationships.
- Context duplication cost: Each forked branch carries the full history. Querying both branches costs the same as two independent conversations of that length.
Avoid forking for routine follow-up questions. Fork only when you need to preserve the original session state for later use.
Source Code
View on GitHub
Running the Example
Next Module
Module 13: Advanced Async Patterns - Cross-turn handlers and advanced reactive patterns.