| Crates.io | cc-sync-session |
| lib.rs | cc-sync-session |
| version | 0.4.0 |
| created_at | 2025-06-24 07:46:38.804143+00 |
| updated_at | 2025-07-01 10:24:13.649464+00 |
| description | A tool for syncing Claude Code session files |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1723958 |
| size | 93,912 |
A CLI tool to sync Claude Code session files from the local storage to a repository for version control.
Claude Code stores session files locally in ~/.claude/projects/. This tool helps you:
cargo install --path .
First, initialize your repository for session syncing:
# In a git repository
cc-sync-session init
# Or specify a repository directory
cc-sync-session init --repo-dir /path/to/your/repository
This creates .claude/ccss_sessions/ directory in your repository with a .gitkeep file.
Basic usage (auto-detects repository):
# Run from within a repository that has been initialized
cc-sync-session sync
With explicit repository:
cc-sync-session sync --repo-dir /path/to/your/repository
With custom source directory:
cc-sync-session sync --source-dir ~/.claude/projects --repo-dir /path/to/your/repository
Using environment variable for source directory:
export CC_SYNC_SESSION_SOURCE_DIR=~/.claude/projects
cc-sync-session sync
Dry run to preview changes:
cc-sync-session sync --dry-run
Verbose output:
cc-sync-session sync --verbose
Enable debug logging:
RUST_LOG=debug cc-sync-session sync
Repository Initialization: Use init command to create .claude/ccss_sessions/ directory in your repository. This marks the repository as ready for session syncing.
Auto-detection: The sync command can automatically find your repository by looking for directories with both .git and .claude/ccss_sessions in the current directory or parent directories.
Directory Name Conversion: Claude Code stores sessions with directory names where / is replaced with -. For example, /Users/yuta/project becomes -Users-yuta-project. This tool converts them back to the original path structure.
One-way Sync: Files are only copied from the source (Claude Code's session directory) to the target (your repository). This prevents accidental corruption of Claude Code's data.
Timestamp-based Updates: Only files that are newer in the source are copied, making subsequent syncs faster.
Timestamp Marking: After copying, the tool updates the file's timestamp in the target to track when it was last synced.
If your Claude Code sessions directory contains:
~/.claude/projects/
├── -Users-yuta-github.com-myproject/
│ ├── session.json
│ └── conversations/
│ └── conv1.json
└── -Users-yuta-work-project/
└── session.json
After running:
cd ~/my-sessions-backup
cc-sync-session init
cc-sync-session sync
Your repository will contain:
~/my-sessions-backup/
└── .claude/
└── ccss_sessions/
├── .gitkeep
├── Users/yuta/github.com/myproject/
│ ├── session.json
│ └── conversations/
│ └── conv1.json
└── Users/yuta/work/project/
└── session.json
-v, --verbose: Enable verbose output (logs to stderr)init subcommand-r, --repo-dir <PATH>: Repository directory (defaults to current directory or parent with .git)sync subcommand-s, --source-dir <PATH>: Source directory containing Claude Code sessions (defaults to $CC_SYNC_SESSION_SOURCE_DIR or ~/.claude/projects/)-r, --repo-dir <PATH>: Target repository directory (defaults to current directory or parent with .git and .claude/ccss_sessions)-d, --dry-run: Run in dry-run mode (show what would be done without making changes)CC_SYNC_SESSION_SOURCE_DIR: Default source directory when --source-dir is not specifiedRUST_LOG: Control log level (e.g., RUST_LOG=info, RUST_LOG=debug). When -v is used, defaults to infoYou can use cc-sync-session as a pre-commit hook to automatically sync Claude Code sessions before each commit.
Install pre-commit:
pip install pre-commit
Install cc-sync-session:
cargo install --path /path/to/cc-sync-session
Create a .pre-commit-config.yaml file in your repository:
repos:
- repo: https://github.com/higumachan/claude-code-work-arounds
rev: main # or specify a tag/commit
hooks:
- id: sync-claude-code-sessions
Install the pre-commit hook:
pre-commit install
Initialize your repository for session syncing:
cc-sync-session init
Now, every time you commit, cc-sync-session will automatically sync your Claude Code sessions to the repository.
sync-claude-code-sessions: Runs sync before each commitsync-claude-code-sessions-dry-run: Preview what would be synced (manual stage only)If you need to commit without syncing sessions:
git commit --no-verify
The tool uses the log crate with env_logger for logging. All logs are written to stderr.
-v flag: Only warnings and errors are displayed-v flag: Info level logs are enabled, showing:
RUST_LOG environment variable can override the log level# Run all tests
cargo test
# Run unit tests only
cargo test --test unit_tests
# Run integration tests only
cargo test --test integration_tests
The tool is designed with a clean architecture using dependency injection:
FileSystem trait: Abstracts file system operationsMockFileSystem: In-memory implementation for testingRealFileSystem: Actual file system implementationSessionSyncer: Core sync logic that works with any FileSystem implementationThis design allows for comprehensive unit testing without touching the actual file system.