Skip to main content

Version-controlled memory system for LLM agents

Project description

gitmem

Version-controlled memory system for LLM agents. Gives AI agents persistent, structured memory using Git-like operations.

The Problem

LLM agents working on long tasks face:

  • Context overflow — conversations grow beyond the context window
  • Context decay — important early decisions get lost
  • No exploration — can't try alternatives without losing current progress
  • Session breaks — restarting means re-explaining everything

How It Works

GitMem creates a .gitmem/ workspace in your project with Git-inspired operations:

Command What it does
init Create a .gitmem/ workspace
commit LLM-summarized checkpoint of progress
branch Fork a reasoning path to explore alternatives
merge LLM-synthesized integration of branch insights
context Retrieve memory at low/medium/high resolution
checkout Switch between branches
log Append execution trace entries

Install

pip install gitmem

Or with uv:

uv add gitmem

For MCP server support:

pip install gitmem[mcp]

Quick Start

Python API

import asyncio
from gitmem import GitMem

gm = GitMem(root="./my-project")
gm.init()

# Log work as you go
gm.log("Analyzed authentication module")
gm.log("Found token expiration bug")

# Commit a checkpoint (uses LLM to summarize)
entry = asyncio.run(gm.commit(history="Found and fixed token expiration bug in auth.py"))
print(entry.summary)  # "Fixed token expiration bug in authentication module"

# Or commit with a manual message (no LLM needed)
entry = asyncio.run(gm.commit(history="n/a", message="Manual checkpoint"))

# Branch to explore an alternative
gm.branch("refactor-tokens", "Try sliding window token expiration")
asyncio.run(gm.commit(history="Implemented sliding window approach", message="Sliding window done"))

# Switch back and merge
gm.checkout("main")
summary = asyncio.run(gm.merge(source="refactor-tokens"))
print(summary)  # LLM-synthesized merge summary

# Retrieve context at different resolutions
ctx = gm.context(resolution="low")    # Project roadmap
ctx = gm.context(resolution="medium") # Commit summaries
ctx = gm.context(resolution="high")   # Full execution traces
ctx = gm.context(query="auth")        # Filter by keyword

MCP Server

GitMem ships as an MCP server compatible with Claude Code, Claude Desktop, and any MCP client.

Claude Code — add to ~/.claude/mcp_servers.json:

{
  "gitmem": {
    "command": "uvx",
    "args": ["gitmem[mcp]"],
    "env": {
      "ANTHROPIC_API_KEY": "your-key-here"
    }
  }
}

Claude Desktop — add to your config:

{
  "mcpServers": {
    "gitmem": {
      "command": "uvx",
      "args": ["gitmem[mcp]"],
      "env": {
        "ANTHROPIC_API_KEY": "your-key-here"
      }
    }
  }
}

This exposes 7 tools: gitmem_init, gitmem_commit, gitmem_branch, gitmem_merge, gitmem_context, gitmem_checkout, gitmem_log.

Configuration

GitMem requires an ANTHROPIC_API_KEY environment variable for LLM-powered operations (commit without a manual message, and merge). Get one at console.anthropic.com.

export ANTHROPIC_API_KEY="sk-ant-..."

The default model is claude-sonnet-4-20250514. You can change it:

gm = GitMem(root=".", model="claude-haiku-4-5-20251001")

Workspace Structure

.gitmem/
├── main.md                 # Project roadmap (low-res context)
├── HEAD                    # Current branch name
└── branches/
    └── main/
        ├── commit.md       # Append-only commit log (medium-res context)
        ├── log.md          # Execution traces (high-res context)
        └── metadata.yaml   # Branch metadata

All files are human-readable plain text. No binary formats, no database.

Development

git clone https://github.com/BradenStitt/gitmem.git
cd gitmem
uv sync --all-extras
uv run pytest tests/ -v
uv run ruff check src/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitmem-0.1.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitmem-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file gitmem-0.1.0.tar.gz.

File metadata

  • Download URL: gitmem-0.1.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitmem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ccd59ab000b654490579e353fbc67e2319b80a677e9fc50a799305bb724fc4a1
MD5 02c7be1178c3f53b725017f06d5c9fb6
BLAKE2b-256 abc9450416712bfc08827a8c2f5c83b8081d23fbcaebb2839df3708279f34950

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitmem-0.1.0.tar.gz:

Publisher: ci.yml on BradenStitt/gitmem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gitmem-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gitmem-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gitmem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d42065047b68cb387948469c717c00e3d03875215552ad2f7de5e22ff2fbafc0
MD5 68448a5248c7a0c0ee27a9a803773608
BLAKE2b-256 b4b30d9f4f2dce0898a8c2a5e6f409577e7dad0f7196b2389ec70a40d863d50f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitmem-0.1.0-py3-none-any.whl:

Publisher: ci.yml on BradenStitt/gitmem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page