Skip to content
Sessions & Workflows Intermediate

Create and Resume a Session

Start a conversation, capture the session ID, and continue it later

Command

"color:#9CA3AF;font-style:italic"># Step 1: Create
$ RESULT=$("color:#7C5CFC">claude -p "Analyze the codebase" "color:#d97757">--output-format json)
  SESSION=$("color:#7C5CFC">echo "$RESULT" | "color:#7C5CFC">jq -r '.session_id')
  
"color:#9CA3AF;font-style:italic"># Step 2: Resume
$ "color:#7C5CFC">claude -p "Now focus on the database layer" "color:#d97757">--resume "$SESSION"

Response

{
  "session_id": "0e639165-79b1-4bd4-bb0f-4cb4c15115d4",
  "result": "I've analyzed the codebase...",
  "num_turns": 3
}

Parsing Code

059669">">const result1 = JSON.parse(execFileSync(059669059669">">'claude', [
  059669059669">">'-p', 059669059669">">'Analyze codebase', 059669059669">">'--output-format', 059669059669">">'json'
], opts));
059669">">const sessionId = result1.session_id;

059669">">// Resume with full conversation context
059669">">const result2 = JSON.parse(execFileSync(059669059669">">'claude', [
  059669059669">">'-p', 059669059669">">'Focus on database', 059669059669">">'--resume', sessionId, 059669059669">">'--output-format', 059669">'json'
], opts));

Gotchas

! --resume loads the full conversation history into the context window
! Sessions are stored in ~/.claude/projects/<encoded-path>/

Related Recipes