Feature request: save session summaries from /compact

Status Closed — not planned
Maintainer reply None cached
Activity 8 comments · opened Mar 2, 2025 · closed Feb 2, 2026

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.

View original on GitHub ↗

8 Comments

agentience · 1 year ago

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.

kelp · 1 year ago

Plus one to this, I was think I wanted the exact same feature.

masszhou · 1 year ago

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

github-actions[bot] · 10 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

marcindulak · 9 months ago

I believe it's not implemented yet. Let's keep the issue open for a few more months.

github-actions[bot] · 8 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

marcindulak · 8 months ago

This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.

github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.