Sessions & Workflows Intermediate
Fork a Session
Branch a conversation to explore alternatives without losing the main thread
Command
$ "color:#7C5CFC">claude -p "Try approach B instead" \ "color:#d97757">--resume "$SESSION_ID" \ "color:#d97757">--fork-session \ "color:#d97757">--output-format json
Response
{
"session_id": "b9395772-b2e3-4f46-b380-c81f9d766afe",
"result": "FORKED_MESSAGE",
"total_cost_usd": 0.01683075,
"modelUsage": { "claude-opus-4-6": { "costUSD": 0.01683075 } }
} Parsing Code
059669">">const forked = JSON.parse(execFileSync(059669059669">">'claude', [ 059669059669">">'-p', 059669059669">">'Try approach B', 059669059669">">'--resume', originalSessionId, 059669059669">">'--fork-session', 059669059669">">'--output-format', 059669059669">">'json' ], opts)); // forked.session_id is NEW — original session unchanged
Gotchas
! Original session stays completely unchanged
! New session gets a full copy of the conversation history