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: claude -p --no-session-persistence leaves no saved session on disk

Claude
~/tips/tip-claude-no-session-persistence

claude -p --no-session-persistence "Explain what this error means: connection refused"

Runs a Claude Code print-mode query without saving the session to disk.

Claude Code normally saves every session so I can resume it later. For a one-off scripted question that I do not want lying around, that default is more than I need.

The CLI reference describes --no-session-persistence as disabling session persistence: sessions are not saved to disk and cannot be resumed. It works in print mode only.

claude -p --no-session-persistence "Explain what this error means: connection refused"

It fits scripts and cron jobs, which would otherwise leave a new saved session behind on every run. Piped input works too:

cat error.log | claude -p --no-session-persistence "Summarize the problem"

The reference also names the environment variable CLAUDE_CODE_SKIP_PROMPT_HISTORY, which does the same in any mode, interactive sessions included:

export CLAUDE_CODE_SKIP_PROMPT_HISTORY=1

A loop over several files shows where this helps, since none of the runs is saved:

for f in logs/*.log; do claude -p --no-session-persistence "Summarize $f"; done

The price is that you lose claude --continue for that run, as intended. The flag controls what Claude Code saves locally. The prompt still goes to the API like any other, so it hides nothing about what you send. I would not paste secrets into a prompt just because nothing gets stored.

Further reading: Claude Code CLI reference

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

Link