This directory contains scripts for managing persistent context logging for Claude sessions.
The Claude Session Management System provides:
- Persistent session tracking with UUID-based identification
- JSON-based logging format for structured data
- Automatic session recovery for interrupted work
- Cleanup mechanisms for old session logs
- Integration with Claude's workflow
Main session logging script that handles creating, updating, and retrieving sessions.
Usage:
# Create a new session
./log-session.sh create [project_path] [user_query]
# Update session fields
./log-session.sh update <session_id> <field> <value>
# Get session data
./log-session.sh get <session_id>
# List sessions
./log-session.sh list [status]Update fields:
todo_add- Add item to todo listfile_modified- Add modified filetech_stack- Add tech stack itemlast_operation- Set last operationstatus- Set session status (in_progress/completed/interrupted)next_step- Add next stepoperation- Add operation (JSON format)
Session recovery tool for resuming interrupted work.
Usage:
# Auto-detect session for current project
./recover-session.sh auto
# Show last incomplete session
./recover-session.sh last [project_path]
# Show specific session
./recover-session.sh show <session_id>
# Save recovery context
./recover-session.sh save [session_id] [output_file]
# Show recent sessions
./recover-session.sh recent [limit]Manages old session logs with configurable retention period.
Usage:
# Delete sessions older than N days
./cleanup-sessions.sh clean [days]
# Preview what would be deleted
./cleanup-sessions.sh dry-run [days]
# Show session statistics
./cleanup-sessions.sh stats
# Archive old sessions
./cleanup-sessions.sh archive [days]
# Interactive cleanup
./cleanup-sessions.sh autoExample script demonstrating how to use the session management system.
Sessions are stored as JSON files in ~/.claude/sessions/session-{uuid}.json:
{
"session_id": "uuid",
"created_at": "ISO-8601 timestamp",
"updated_at": "ISO-8601 timestamp",
"project_path": "/absolute/path/to/project",
"user_query": "Original user request",
"context": {
"todo_list": ["task1", "task2"],
"files_modified": ["file1.js", "file2.py"],
"tech_stack": ["Node.js", "Python"],
"last_operation": "Description of last action",
"working_directory": "/current/directory"
},
"status": "in_progress|completed|interrupted",
"next_steps": ["step1", "step2"],
"operations": [
{
"type": "operation_type",
"timestamp": "ISO-8601",
"description": "What was done",
"details": {}
}
]
}Add to your ~/.bashrc or ~/.zshrc:
# Claude session management
alias claude-resume='~/code/claude-config-template/scripts/recover-session.sh auto'
alias claude-sessions='~/code/claude-config-template/scripts/recover-session.sh recent'
alias claude-cleanup='~/code/claude-config-template/scripts/cleanup-sessions.sh auto'
alias claude-stats='~/code/claude-config-template/scripts/cleanup-sessions.sh stats'Sessions can be automatically created and updated by Claude or integrated into your development workflow.
~/.claude/
├── sessions/ # Session JSON files
│ ├── session-{uuid}.json
│ └── archive/ # Archived sessions
└── commands/ # Command documentation
├── resume-context.md
└── last-session-recovery.md
- Regular Updates: Update session context as work progresses
- Clear Descriptions: Use meaningful descriptions for operations
- Complete Sessions: Mark sessions as completed when done
- Regular Cleanup: Run cleanup monthly (30-day retention by default)
- Project Organization: Sessions are tracked per project path
- Check if
~/.claude/sessions/exists - Verify you're in the correct project directory
- List all sessions with
./log-session.sh list
- Ensure
jqis installed:brew install jq(macOS) orapt install jq(Linux) - Check JSON syntax in session files
- Verify proper escaping of special characters
- Ensure scripts are executable:
chmod +x *.sh - Check directory permissions:
ls -la ~/.claude/
- Bash 4+ (for associative arrays)
- jq (for JSON processing)
- Standard Unix tools: date, find, grep, sed
These scripts are part of the claude-config-template project.