Claude Code Trace - Export Claude Code chat sessions into markdown and XML
Claude Code Trace - Export Claude Code chat sessions into markdown and XML
Export and import Claude Code sessions.
Claude Code stores conversation history in ~/.claude/projects//*.jsonl. This tool extracts those sessions into portable formats for archival, analysis, or sharing.
v2.0 adds portable sessions: export a session to your git repository, push it, and let someone else import it to continue where you left off. The original export functionality remains unchanged.
Exports to ~/claude_sessions/exports/ with timestamped directories. This is the original behavior and remains the default.
python3 export_claude_session.py
Produces:
~/claude_sessions/exports/2025-07-02_16-45-00_f33cdb42/
├── raw_messages.jsonl # Original session data
├── conversation_full.md # Human-readable markdown
├── conversation_full.xml # Structured XML with full metadata
├── session_info.json # Session metadata
└── summary.txt # Statistics
Exports to .claude-sessions// within your repository. Designed to be committed and shared.
python3 export_claude_session.py --in-repo --export-name my-session
Produces:
.claude-sessions/my-session/
├── .cctrace-manifest.json # Required for import
├── RENDERED.md # Renders on GitHub
├── session/
│ ├── main.jsonl # Session transcript
│ ├── file-history/ # File snapshots from undo history
│ ├── todos.json # Todo state
│ └── plan.md # Plan file if present
├── config/
│ ├── commands/ # Slash commands
│ ├── skills/ # Skills
│ └── ... # Other .claude/ config
└── [legacy files] # For backwards compatibility
The portable export includes everything needed to resume the session: conversation history, file snapshots, todos, plans, and project-specific Claude Code configuration.
Someone clones your repo and wants to continue your session:
python3 import_session.py .claude-sessions/my-session/
claude -c # Lists available sessions, including the imported one
.cctrace-manifest.jsoncwd paths to the local project directory~/.claude/projects//Certain fields are cryptographically signed or tied to Anthropic's API and must not be modified:
message.id (Anthropic message ID)requestId (Anthropic request ID)signature in thinking blockstool_use.id (tool invocation ID)These are left untouched. Only the session-local identifiers (sessionId, uuid, parentUuid, agentId, cwd) are regenerated.
If an import causes problems:
python3 restore_backup.py # Show snapshot info
python3 restore_backup.py --restore # Restore pre-import state
Restore requires typing "RESTORE" to confirm. The --yes flag bypasses this for automation.
Claude Code normalizes project paths for storage:
| Character | Replacement |
|---|---|
/ |
- |
\ |
- |
: |
- |
. |
- |
_ |
- |
Unix paths are prefixed with -. Windows paths are not.
Examples:
/mnt/c/python/my_project becomes -mnt-c-python-my-projectC:\Users\dev\project becomes C-Users-dev-projectcctrace replicates this normalization to locate and import sessions correctly.
Existing cctrace users are unaffected:
--in-repo flag is required to use the new portable formatRequires Python 3.6+ and access to ~/.claude/projects/.
git clone https://github.com/jimmc414/cctrace.git
cd cctrace
./setup.sh
Or manually:
cp export_claude_session.py ~/claude_sessions/
cp import_session.py ~/claude_sessions/
cp restore_backup.py ~/claude_sessions/
mkdir -p ~/.claude/commands
cp .claude/commands/*.md ~/.claude/commands/
# Classic export to ~/claude_sessions/exports/
python3 export_claude_session.py
# Portable export to .claude-sessions/
python3 export_claude_session.py --in-repo --export-name feature-work
# Export specific session
python3 export_claude_session.py --session-id f33cdb42-0a41-40d4-91eb-c89c109af38a
# Adjust active session detection window (default: 300 seconds)
python3 export_claude_session.py --max-age 600
# Import from local export
python3 import_session.py .claude-sessions/my-session/
# Skip config file import
python3 import_session.py .claude-sessions/my-session/ --skip-config
# Skip auxiliary files (file-history, todos, plans)
python3 import_session.py .claude-sessions/my-session/ --skip-auxiliary
# Non-interactive mode
python3 import_session.py .claude-sessions/my-session/ --non-interactive
If installed to ~/.claude/commands/:
/export-session [name] # Portable export
/import-session # Import
/restore-backup # Restore from snapshot
When multiple sessions exist for a project, cctrace identifies the correct one by:
.jsonl files in the project's Claude storage directory--max-age secondsThe original session format. Each line is a JSON object representing a message or event. Contains all fields exactly as stored by Claude Code.
Human-readable conversation with:
RENDERED.md includes a header with session metadata and is formatted for GitHub rendering.
Structured format preserving:
Required for import. Contains:
| Path | Purpose |
|---|---|
~/.claude/projects// |
Claude Code session storage |
~/claude_sessions/exports/ |
Classic export destination |
.claude-sessions/ |
Portable export destination (in repo) |
~/.claude-session-imports/ |
Import logs and snapshots |
~/.claude/commands/ |
User slash commands |
python3 -m pytest tests/ -v
33 tests covering manifest validation, UUID regeneration, path normalization, and restore functionality.
MIT
No open issues yet, or sync has not completed.