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.
When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.
Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.
Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.