Skip to main content
Glama
Git Branch History MCP Server

Git Branch History MCP Server

by amaraa87

Git Branch History MCP Server

An MCP (Model Context Protocol) server that manages Claude conversation history per Git branch. When you switch branches, Claude automatically loads the relevant context. When history gets too long, it compacts and summarizes.

Features

  • Branch-aware history — Each Git branch has its own conversation context

  • Auto-detect branch — Detects current branch via git branch --show-current

  • Auto-compact — Warns when approaching token limits, supports compaction with snapshot backup

  • Docker Desktop MCP Toolkit — Installs as a server in Docker Desktop's MCP Toolkit

  • Persistent storage — SQLite database persisted via Docker volume

  • Snapshots — Old history saved before compaction for reference

  • Host path mapping — Translates host filesystem paths to container paths automatically

Related MCP server: memory-mcp

Tools

Tool

Description

git_history_get_branch

Detect current branch and check if history exists

git_history_save

Save/append conversation context to current branch

git_history_load

Load conversation history for current/specified branch

git_history_compact

Replace history with a summary (saves snapshot of old)

git_history_list_branches

List all branches with saved history and stats

git_history_delete

Delete a branch's history permanently

git_history_check_switch

Detect branch switches and auto-load new context

Setup with Docker Desktop MCP Toolkit

1. Build the Docker Image

docker build -t git-branch-history-mcp .

2. Create a Persistent Volume

docker volume create git-branch-history-data

3. Create and Import the Catalog

Create a catalog.yaml file:

version: 3
name: git-branch-history
displayName: Git Branch History
registry:
  git-branch-history:
    description: Manages Claude conversation history per Git branch.
    title: Git Branch History
    type: server
    image: git-branch-history-mcp:latest
    tools:
      - name: git_history_get_branch
      - name: git_history_save
      - name: git_history_load
      - name: git_history_compact
      - name: git_history_list_branches
      - name: git_history_delete
      - name: git_history_check_switch
    env:
      - name: MAX_TOKENS
        value: "100000"
      - name: COMPACT_THRESHOLD
        value: "0.75"
      - name: HOST_MOUNT_PREFIX
        value: /Users/yourname
      - name: CONTAINER_MOUNT_POINT
        value: /host
    volumes:
      - '/Users/yourname:/host:ro'
      - 'git-branch-history-data:/data'
    metadata:
      category: developer-tools
      tags:
        - git
        - branch
        - history
        - context
      license: MIT License

Important: Replace /Users/yourname with your actual home directory path.

Import and enable:

docker mcp catalog import catalog.yaml
# When prompted, enter: git-branch-history

docker mcp server enable git-branch-history

4. Connect to Your Client

docker mcp client connect claude-code
# Or: docker mcp client connect cursor

Restart your client for the tools to appear.

Verify

docker mcp tools ls | grep git_history

Manual Docker Run (without MCP Toolkit)

docker run -i --rm \
  -v "/Users/yourname:/host:ro" \
  -v "git-branch-history-data:/data" \
  -e HOST_MOUNT_PREFIX=/Users/yourname \
  -e CONTAINER_MOUNT_POINT=/host \
  git-branch-history-mcp

Usage Workflow

1. Start working on a branch

You: "Check my branch context for /Users/me/projects/my-app"
Claude: [calls git_history_check_switch] -> Detects branch `feature/gift-wrapping`
        [calls git_history_load] -> Loads previous context for this branch

2. Save progress during conversation

You: "Save our conversation progress"
Claude: [calls git_history_save] -> Saves summary of what was discussed/decided
        -> Reports: "Saved. Token usage: 45% (45,000 / 100,000)"

3. Switch branches

You: "I switched to the payment-fix branch, load that context"
Claude: [calls git_history_check_switch] -> Detects switch to `fix/payment-ux`
        [calls git_history_load] -> Loads payment branch context
        "Loading context for fix/payment-ux. Last session: you were fixing the credit card form validation..."

4. Compact when approaching limits

Claude: "History is at 78% of token limit. Want me to compact?"
You: "Yes, compact it"
Claude: [summarizes the full history into key points]
        [calls git_history_compact] -> Replaces with summary, saves snapshot
        "Compacted! Went from 78,000 to 12,000 tokens (85% savings)"

Environment Variables

Variable

Default

Description

HISTORY_DB_DIR

/data

Directory for SQLite database

MAX_TOKENS

100000

Maximum token estimate before warning

COMPACT_THRESHOLD

0.75

Percentage of max before warning (0.0-1.0)

HOST_MOUNT_PREFIX

""

Host path prefix to strip (e.g., /Users/yourname)

CONTAINER_MOUNT_POINT

/host

Where the host filesystem is mounted in the container

Architecture

+--------------------------+
|   Claude / Claude Code   |
|        (Client)          |
+-----------+--------------+
            | stdio (MCP Protocol)
            v
+--------------------------+
| Docker Desktop MCP       |
| Toolkit Gateway          |
+-----------+--------------+
            | stdio
            v
+--------------------------+
| Git Branch History MCP   |
|   (Docker Container)     |
|                          |
| +----------------------+ |
| |   FastMCP Server     | |
| +----------+-----------+ |
|            |             |
| +----------v-----------+ |
| |   SQLite Database    | |
| |  /data/branch_       | |
| |   history.db         | |
| +----------------------+ |
|            |             |
| +----------v-----------+ |
| |   Git CLI            | |
| |  (branch detect)     | |
| +----------------------+ |
+--------------------------+
     |              |
     v              v
  /host (ro)    /data (rw)
  (your home)  (persistent)

Database Schema

  • projects — Tracks repositories by path

  • branch_histories — One row per branch per project, stores history text

  • history_snapshots — Backup of old history before compaction

Tips

  • Your home directory is mounted as read-only (:ro) for safety

  • The /data volume persists across container restarts

  • Use git_history_list_branches to see all tracked branches and their token usage

  • Compact early and often — don't wait until you hit the limit

  • The server auto-creates entries for new branches on first access

  • Add "Check my branch context" to your CLAUDE.md for automatic context loading

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides persistent context management for Claude AI coding assistants, allowing you to save and restore conversation context, create checkpoints, and organize information across sessions to prevent losing important work history and decisions during long coding sessions.
      150 npm
      137
      MIT
    • A
      license
      Not graded
      quality
      A
      maintenance
      Provides a persistent memory layer for Claude coding assistants, enabling users to save, search, organize, and restore context, decisions, and progress across sessions using channels, checkpoints, and git-aware tracking. Multiple sessions can share the same stored context, so work survives context compaction, resets, or parallel sessions.
      150 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables persistent context management for Claude AI coding assistants by saving, searching, checkpointing, restoring, and sharing project context across sessions and parallel conversations.
      150 npm
      MIT