Use --no-session-persistence for Ephemeral Automated Runs
By default, Claude Code saves every session to disk so you can resume it later. In automated pipelines, this creates unnecessary clutter. The --no-session-persistence flag prevents sessions from being written to disk entirely.
claude -p --no-session-persistence "Run the test suite and report failures"
This is ideal for CI/CD jobs, cron tasks, and any scripted workflow where the session is disposable. Without this flag, each automated run creates a session file that accumulates over time, eventually eating disk space and making --resume harder to navigate.
It pairs naturally with other print-mode flags for clean, ephemeral pipelines:
# Ephemeral run with JSON output and a spending cap
claude -p \
--no-session-persistence \
--output-format json \
--max-budget-usd 1.00 \
"Analyse this PR diff and return a risk score"
One thing to note: this flag only works in print mode (-p). Interactive sessions always persist because the whole point of interactive mode is that you might want to come back later.
If you are running hundreds of automated Claude Code invocations (for example, processing a batch of files), this flag prevents your .claude/ directory from ballooning with session data you will never revisit.
Keep your automated runs clean by telling Claude not to remember them.
Log in to leave a comment.
The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.
The language setting makes Claude respond in your preferred language by default, across every session and project.
The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.