Session management for Claude CLI - preserve context across projects
Project description
Claude Session Manager
Advanced session management system for Claude CLI that preserves conversation context across sessions.
Features
- Automatic Context Preservation: Conversations are automatically captured and saved every 2 seconds
- Session Management: Create, resume, and delete sessions for different projects
- Auto-start Sessions: New sessions start automatically after creation
- CLAUDE.md Integration: Context is loaded via CLAUDE.md without disrupting existing content
- Working Directory Memory: Each session remembers and returns to its working directory
- Export Functionality: Export conversations to Markdown or JSON format
- Real-time Capture: Conversations are saved even if terminal is forcefully closed
Installation
From PyPI
pip install claude-session-manager
From source
git clone https://github.com/ahmetkumass/claude-session-manager
cd claude-session-manager
pip install -e .
Quick Start
Basic Commands
# Quick start - creates and starts a session immediately
cs quick
# Create named session - automatically starts
cs create --name "api_project"
# Create without starting
cs create --name "api_project" --no-start
# List all sessions
cs list
# Resume existing session
cs resume <session_id>
# Delete session
cs delete <session_id>
# Delete all sessions
cs delete --all
# Export session
cs export <session_id>
Usage Guide
Starting a New Project
# Navigate to project directory
cd ~/projects/my-api
# Create and start session
cs create --name "my_api"
# Work with Claude - context is automatically saved
> Create a FastAPI application structure
> Add user authentication endpoints
# Exit anytime - context is preserved
# Use Ctrl+C, /exit, or close terminal
Resuming Work
# List available sessions
cs list
# Output:
# ID Name Created Context Description
# --------------------------------------------------------------------------------
# abc123 my_api 2024-01-15 10:30 25
# def456 frontend 2024-01-14 15:45 42 React dashboard
# Resume session - previous context is automatically loaded
cs resume abc123
# Claude remembers your previous conversation
> Continue with the authentication endpoints we discussed
Project Switching
# Working on API
cs resume api_session_id
> Implement rate limiting
# Switch to frontend project
cs resume frontend_session_id
> Debug the login component
# Each session maintains its own context
Command Reference
| Command | Description | Alias |
|---|---|---|
create --name <name> |
Create and start new session | new |
create --name <name> --no-start |
Create without starting | |
quick |
Create quick session with timestamp name | q |
list |
List all sessions | ls |
resume <id> |
Resume session with context | |
resume <id> --full |
Resume with full history | |
delete <id> |
Delete specific session | rm |
delete --all |
Delete all sessions | |
export <id> |
Export to Markdown | |
export <id> --format json |
Export to JSON | |
save <id> <message> |
Manually save message | |
current |
Show current session |
Short Aliases
The cs command is the primary alias. Additional shortcuts:
cs q # Quick start
cs ls # List sessions
cs rm <id> # Delete session
How It Works
Context Loading
When resuming a session, the system:
- Reads existing CLAUDE.md if present
- Appends session context to CLAUDE.md
- Claude automatically reads the context
- On exit, restores original CLAUDE.md content
Automatic Capture
Conversations are captured through:
- Background monitoring every 2 seconds
- Signal handlers for clean exits
- Parsing Claude's JSONL log files
- Automatic save even on terminal force-close
File Structure
~/.claude-sessions/
├── current_session.json # Active session tracker
├── <session_id>.json # Session data and context
└── context_<session_id>.md # Formatted context file
Advanced Usage
Full History Loading
# Load complete conversation history
cs resume <session_id> --full
Manual Context Addition
# Add custom context to session
cs save <session_id> "Important: API key is in .env file" --role user
cs save <session_id> "Understood, I'll read from .env" --role assistant
Session Information
# View current active session
cs current
# List sessions with context count
cs list
Best Practices
- One session per project - Keep contexts separate and organized
- Descriptive names - Use meaningful session names for easy identification
- Regular exports - Export important sessions for backup
- Clean up regularly - Delete old sessions with
cs delete --all
Technical Details
Context Preservation
- Monitors
~/.claude/projects/for JSONL changes - Parses conversation data from Claude's native format
- Updates session context in real-time
- Preserves working directory per session
CLAUDE.md Integration
- Preserves existing CLAUDE.md content
- Adds session context under
## Session Contextsection - Restores original content on exit
- No permanent modifications to project files
Contributing
Contributions are welcome. Please submit pull requests with:
- Clear commit messages
- Updated documentation
- Test coverage for new features
License
MIT License - see LICENSE file for details.
Support
For issues and feature requests, please use the GitHub issue tracker.
This is an independent project and is not affiliated with Anthropic or Claude.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_session_manager-1.0.0.tar.gz.
File metadata
- Download URL: claude_session_manager-1.0.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d88c607c45f665c8d3d14d3475eccd555b72639e7bd91deb2589a0615bea0c22
|
|
| MD5 |
b775406d05934051416a7d6356f32985
|
|
| BLAKE2b-256 |
7378f9d74e1d17c7acf05f9249bd2bd08790c2217758d00244eaefc57993a6a9
|
File details
Details for the file claude_session_manager-1.0.0-py3-none-any.whl.
File metadata
- Download URL: claude_session_manager-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77ec83f550e6a7e79cba1f674844cd66dda4b6044528dc6e341515a5c3e6fd55
|
|
| MD5 |
e517737e6a1995d954cd2188238f6986
|
|
| BLAKE2b-256 |
dfff091849dd8b962a7e9ca7b29ae18c3056475208714103c7d2d5a65d4c866d
|