The Problem: Lost Context on Branch Switches
If you use Claude Code while working across multiple git branches, you've experienced this: you're deep in a conversation about implementing a feature on feature/a, switch to main to check something, then return to feature/a only to find Claude has forgotten everything. Each claude invocation starts a fresh session, regardless of what you were previously discussing on that branch.
The Solution: claude-cc
claude-cc is a simple bash wrapper that solves this by automatically resuming the last Claude Code session for your current git branch. It's a single script with minimal dependencies that transparently handles session management.
How It Works
When you run cc (instead of claude), the script:
- Detects your current git branch with
git branch --show-current - Scans
~/.claude/projects/<project>/for session history files - Finds the most recent session that started on this specific branch
- Runs
claude --resume <session-id>if a matching session exists - Starts a fresh
claudesession if no previous session is found for the branch
Installation and Usage
npm install -g claude-cc
Requirements: claude (the Claude Code CLI) and python3 installed.
Once installed, use cc instead of claude:
# Switch to feature branch
git checkout feature/a
# Automatically resumes last session for feature/a
cc "Add the new authentication middleware"
# Switch to another branch
git checkout feature/b
# Resumes last session for feature/b (different from feature/a's session)
cc "Fix the bug in the payment processor"
# Create and switch to a new branch
git checkout -b feature/c
# Starts fresh session since no previous session exists for this branch
cc "Implement the new dashboard UI"
Key Features
- Transparent operation:
ccaccepts all the same flags asclaude - Outside git repos: Behaves identically to regular
claudecommand - No configuration needed: Works out of the box
- Minimal dependencies: Just bash and Python standard library
- Branch-specific sessions: Each branch maintains its own conversation history
How It Parses Session Data
The script includes a small embedded Python snippet that handles JSONL parsing (since bash can't reliably parse JSON). It reads Claude Code's session files to determine which branch each session belongs to based on metadata stored by Claude Code.
When This Is Most Useful
This tool shines when you're:
- Working on multiple features simultaneously across different branches
- Context-switching between bug fixes and feature development
- Pairing with Claude on complex refactoring that spans multiple sessions
- Maintaining separate conversations for different aspects of a project
Limitations to Know
- Requires being in a git repository to work its magic
- Relies on Claude Code's session storage format (which could change in future versions)
- Doesn't handle git worktrees or detached HEAD states
The Bigger Picture
While Claude Code has excellent session management capabilities, it doesn't natively understand git branch context. claude-cc bridges this gap with a simple, Unix-philosophy approach: do one thing well, compose with existing tools, and stay out of the way.





