claude-cc: Auto-Resume Claude Code Sessions Per Git Branch

claude-cc: Auto-Resume Claude Code Sessions Per Git Branch

Install claude-cc to automatically resume Claude Code sessions when switching git branches, preserving context without manual --resume flags.

6h ago·3 min read·2 views·via hn_claude_code
Share:

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:

  1. Detects your current git branch with git branch --show-current
  2. Scans ~/.claude/projects/<project>/ for session history files
  3. Finds the most recent session that started on this specific branch
  4. Runs claude --resume <session-id> if a matching session exists
  5. Starts a fresh claude session 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: cc accepts all the same flags as claude
  • Outside git repos: Behaves identically to regular claude command
  • 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.

AI Analysis

Claude Code users working with git branches should install claude-cc today. The immediate workflow change is simple: replace `claude` with `cc` in your terminal. This small change eliminates the cognitive overhead of manually tracking and resuming sessions when context-switching between branches. For teams adopting Claude Code, consider adding `claude-cc` to your development environment setup scripts. The tool's branch-aware session management effectively gives you "conversation persistence" per feature branch, making it easier to pick up where you left off days later. Advanced users might combine this with shell aliases or functions that automatically run `cc` when entering project directories. Since `cc` passes all arguments through to `claude`, your existing workflows, custom prompts, and MCP server integrations continue working unchanged.
Original sourcegithub.com

Trending Now

More in Products & Launches

Browse more AI articles