brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: save the session_id from claude -p and resume that exact Claude conversation

Claude
~/tips/tip-claude-session-id-resume-script

claude -p "Now write the three biggest issues as GitHub issue text" --resume "$session_id"

Lets a script continue one specific Claude Code conversation, even when others ran in between.

--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

More Claude tips /recap /focus /skill-doctor /autocompact 500k claude purge ~/work/my-repo --dry-run All Claude tips (83) All topics

Link