--continue picks the most recent conversation. In a script that runs several jobs, “most recent” can be the wrong one.
session_id=$(claude -p "Review src/ for performance issues" --output-format json | jq -r '.session_id')
claude -p "Now write the three biggest issues as GitHub issue text" --resume "$session_id"
With --output-format json the reply is one JSON object, with the answer in result and the conversation ID in session_id. Store the ID, pass it to --resume, and the follow-up lands in exactly that conversation with all its context. The JSON also has total_cost_usd, and on a resumed run it reports the total of the whole conversation so far.
The two commands don’t have to run in the same folder. Claude Code finds the session by its ID in any project on the machine. --resume also accepts the absolute path to a session’s .jsonl transcript file.
I think this is neater than --continue as soon as anything runs in parallel. It also makes a script’s behaviour reproducible: the second step always builds on the first, whatever else happened.
It won’t work with --no-session-persistence on the first run, because then nothing is saved to resume. And sessions are local files, so a CI runner that starts fresh each time can’t resume yesterday’s ID.
Further reading: Run Claude Code programmatically: continue conversations