[FEATURE] Add --ephemeral flag to prevent saving conversation history in programmatic mode
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When running Claude Code programmatically with claude -p "Something", a conversation history is always created as a .jsonl file. This conversation then appears when running claude --resume, cluttering the conversation history with automated/scripted runs.
For CI/CD pipelines, automated scripts, and one-off programmatic queries, these ephemeral conversations should not persist in the resume history. Currently, there's no way to prevent this behavior.
Proposed Solution
Add an --ephemeral flag that prevents conversation history from being saved to disk.
Example usage:
# One-off programmatic query - no history saved
claude -p --ephemeral "Analyze this log file" < logs.txt
# CI/CD pipeline - don't clutter history
claude -p --ephemeral "Run linting and fix issues" --output-format json
The flag should:
- Skip creating the
.jsonlconversation file - Prevent the session from appearing in
claude --resume - Skip background conversation summarization jobs
[!NOTE] This flag should only work with --print mode since interactive sessions inherently expect persistence.
<details>
<summary><strong>Alternative Solutions</strong></summary>
Current workarounds:
- Post-execution cleanup: Parse
session_idfrom JSON output and manually delete the.jsonlfile
- Brittle and requires knowing the file location
- May conflict with background summarization jobs
Alternatives considered:
- Environment variable:
CLAUDE_EPHEMERAL=1- less discoverable than a CLI flag - Auto-cleanup after N days - doesn't solve the immediate clutter problem
</details>
Priority
High - Significant impact on productivity
Feature Category
CLI commands and flags
Use Case Example
CI/CD Pipeline:
# In GitHub Actions workflow
claude -p --ephemeral "Review PR for security issues" \
--output-format json --allowedTools Read,Grep > review.json
Automated Monitoring:
# Runs every hour via cron - would create 24+ conversations/day
echo "$logs" | claude -p --ephemeral "Detect anomalies" --output-format json
Quick Development Queries:
claude -p --ephemeral "Explain this error" < error.log
<details>
<summary><strong>Additional Context</strong></summary>
Related documentation:
- Conversation history is always stored: https://docs.anthropic.com/en/docs/claude-code/common-workflows
- No mention of ephemeral mode: https://docs.anthropic.com/en/docs/claude-code/headless
Similar features in other tools:
- Docker:
docker run --rm(ephemeral containers) - Git:
git commit --no-verify(skip hooks)
Implementation considerations:
- Should be mutually exclusive with
--continueand--resume - Should work with all output formats (
text,json,stream-json)
</details>
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗