Feature request: save session summaries from /compact
First, let me just gush over how awesome Claude Code is. You guys are brilliant in building the ecosystem around the best coding model. The overall value is more than the sum of the parts.
I have spent significant time (and API fees!) in the last few days with Claude Code and have decided it is my preferred way to work. The /compact feature is awesome. I might use it two or three times per hour. The summary it produces is valuable history. Please provide a way to automatically save it as Markdown files with timestamps in the file name so that the chronological order is preserved when sorting alphabetically. Given that the files will have their own timestamp metadata, it may not be necessary to include the timestamp in the filename, but I think it will be useful anyway. Perhaps this preference should be configurable.
I'm using a home-baked solution by including the following in CLAUDE.md:
## Session Initialization
At the beginning of each new session, regardless of the current working directory:
1. Check if `claude_compact_recent.txt` exists in the current directory
2. If it exists, ask the user if they would like to continue with the conversation context from that file
3. If the user agrees, incorporate the content as context for the current session
## Conversation Management
When handling the "/compact" command:
1. Add the conversation summary to `claude_compact_history.txt` with timestamp
2. Overwrite `claude_compact_recent.txt` with the same content
3. Format the header as: `# Conversation Summary - <timestamp>`
4. Use local time with format: `YYYY-MM-DD HH:MM:SS TZ`
I also check this into my repo. Would be much better if were baked into Claude Code in a format that can be committed.
Plus one to this, I was think I wanted the exact same feature.
inspired by @coygeek 's solution in #1335, I wrote a script for interactive env.
add a script with chmod +x
#!/bin/bash
SCRIPT_DIR="/Users/<Name>/.claude/dev/scripts"
# Get current system time and format it
CURRENT_TIME=$(date '+%Y-%m-%d %H:%M:%S %Z')
DEFAULT_PROMPT="This session starts from $CURRENT_TIME"
# Get prompt from argument or use default
PROMPT="${1:-$DEFAULT_PROMPT}"
# Start the conversation and capture the session ID
echo "Starting Claude session with prompt: '$PROMPT'"
initial_output=$(claude -p "$PROMPT" --output-format json)
# Check if the command was successful
if [ $? -eq 0 ]; then
# Clean the output to handle control characters that break jq parsing
cleaned_output=$(echo "$initial_output" | tr -d '\000-\037')
SESSION_ID=$(echo "$cleaned_output" | jq -r '.session_id' 2>/dev/null)
if [ "$SESSION_ID" != "null" ] && [ -n "$SESSION_ID" ]; then
export SESSION_ID
echo "Started session: $SESSION_ID"
echo "Environment variable SESSION_ID has been set: $SESSION_ID"
claude -r "$SESSION_ID"
else
echo "Failed to extract session ID from response"
echo "Response: $initial_output"
fi
else
echo "Failed to start Claude session"
echo "Make sure 'claude' command is available and properly configured"
fi
then add a alias in you e.g. .zshrc, and source .zshrc
# Claude session starter script
add alias claude_session='~/.claude/dev/scripts/claude_session.sh'
each time when you start claude code with this alias, it will firstly produce a session id from headless mode and update this session id into env variable, where other program in the same shell session can access this