Track and version AI agent chat sessions with git commits
Project description
ReAlign
Track and version AI agent chat sessions with git commits
ReAlign automatically integrates your AI assistant (like Claude) chat sessions with your git commits, making it easy to understand the context behind code changes and search through your development history.
30-Second Quick Start
# 1. Install with pipx (recommended)
pipx install realign-git
# 2. Initialize in your project (auto-detects Claude Code!)
cd your-project
realign init
# 3. That's it! Now just commit as usual
git add .
git commit -m "Your commit message"
# 4. Search your AI conversations
realign search "bug fix"
realign show abc1234 # View session from commit
Using Claude Code? No extra setup needed - ReAlign auto-detects your sessions!
Want MCP integration? One command: claude mcp add --scope user --transport stdio realign -- uvx --from realign-git realign-mcp
Don't have pipx? See Installation for alternative methods.
Features
- ๐ Automatic Session Tracking: Copies agent chat histories into your repository on every commit
- ๐ Smart Summaries: Generates concise summaries of chat sessions (with LLM or local fallback)
- ๐ Powerful Search: Search through both commit messages and chat content
- ๐๏ธ Session Viewing: View full chat sessions from any commit
- ๐ Non-blocking: Never blocks commits even if session tracking fails
- ๐ฏ Git-native: Uses git hooks for seamless integration
- ๐ค MCP Support: Integrate with Claude and other AI agents via Model Context Protocol
Installation
For Users (Recommended): pipx
pipx is the recommended way to install ReAlign for end users. It installs ReAlign in an isolated environment while making the command globally available.
# Install pipx (if not already installed)
# macOS
brew install pipx
pipx ensurepath
# Ubuntu/Debian
sudo apt install pipx
pipx ensurepath
# Or via pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# Install ReAlign with pipx
pipx install realign-git
# Or install from GitHub (latest version)
pipx install git+https://github.com/yourusername/ReAlign.git
# Upgrade ReAlign
pipx upgrade realign-git
# Uninstall ReAlign
pipx uninstall realign-git
Benefits of pipx:
- โ Isolated environment: No dependency conflicts with other Python projects
- โ
Globally available: Use
realigncommand anywhere without activating virtual environments - โ Clean management: Easy to upgrade, reinstall, or uninstall
- โ Works everywhere: Git hooks will always find the realign commands
For Developers: From Source
If you're developing ReAlign or need to modify the code:
# Clone the repository
git clone https://github.com/yourusername/ReAlign.git
cd ReAlign
# Create virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in editable mode
pip install -e .
# Or with development dependencies
pip install -e ".[dev]"
# For LLM support (optional)
pip install -e ".[llm]"
# For MCP (Model Context Protocol) support
pip install -e ".[mcp]"
Note for developers: When developing, the git hooks will use your editable installation from the virtual environment. Make sure to activate the environment when testing hooks.
Alternative: pip install (Not Recommended)
You can install with pip, but this may cause dependency conflicts:
pip install realign-git
โ ๏ธ Not recommended because:
- May conflict with other projects' dependencies
- Requires virtual environment activation for git hooks to work
- Harder to manage and uninstall cleanly
Requirements
- Python 3.11+
- Git
- Dependencies (automatically installed):
- typer >= 0.9.0
- pyyaml >= 6.0
- rich >= 13.0.0
- mcp >= 1.0.0 (for MCP support)
- anthropic >= 0.18.0 (for Claude LLM summaries)
- openai >= 1.0.0 (for GPT LLM summaries)
Common Workflows
For End Users: pipx Installation Workflow
# 1. Install pipx (one-time setup)
brew install pipx # macOS
# or: sudo apt install pipx # Ubuntu/Debian
pipx ensurepath
# 2. Install ReAlign
pipx install realign
# 3. Use ReAlign in any project
cd ~/my-project
realign init
git commit -m "your changes"
# 4. Upgrade when new version available
pipx upgrade realign
# 5. If you encounter issues, reinstall cleanly
pipx uninstall realign
pipx install realign
For Developers: Development Workflow
# 1. Clone and setup (one-time)
git clone https://github.com/yourusername/ReAlign.git
cd ReAlign
python3 -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
# 2. Make changes and test
vim src/realign/hooks.py
pytest
# 3. Test in a real project
cd ~/test-project
source ~/Projects/ReAlign/venv/bin/activate # Use dev version
realign init
git commit -m "test" # Will use your modified code
# 4. When switching to production use
deactivate
pipx install ~/Projects/ReAlign # Install your local version globally
Switching Between Dev and Production
# Scenario: You have pipx-installed ReAlign, but want to test dev version
# Option 1: Temporarily use dev version (in specific project)
cd your-project
source ~/Projects/ReAlign/venv/bin/activate
# Now git hooks will use dev version while venv is active
# Option 2: Replace pipx version with dev version
pipx uninstall realign
pipx install -e ~/Projects/ReAlign
# Now all projects use dev version
# Option 3: Reinstall stable version
pipx install --force realign
MCP Integration
ReAlign supports the Model Context Protocol for seamless integration with AI agents like Claude!
Quick Setup (No Pre-Installation Required!):
# For Claude Code - one command, auto-installs from PyPI:
claude mcp add --scope user --transport stdio realign -- uvx --from realign-git realign-mcp
# For Claude Desktop - add to claude_desktop_config.json:
{
"mcpServers": {
"realign": {
"command": "uvx",
"args": ["--from", "realign-git", "realign-mcp"],
"env": {
"REALIGN_AUTO_DETECT_CLAUDE": "true",
"REALIGN_USE_LLM": "true"
}
}
}
}
๐ Full MCP setup guide: See MCP_SETUP.md
Quick Start
1. Initialize ReAlign in your repository
cd your-project
realign init
Note: If you're not in a git repository yet, ReAlign will offer to initialize one for you automatically!
This will:
- Initialize a git repository (if not already present)
- Create
.realign/directory structure - Install the git hook (
prepare-commit-msg) - Set up global configuration at
~/.config/realign/config.yaml - Create local history directory at
~/.local/share/realign/histories
2. Configure your agent to save sessions
Option A: Claude Code (Auto-detection - Recommended)
If you're using Claude Code, ReAlign will automatically detect your project's session directory! No manual configuration needed.
Claude Code saves sessions to:
~/.claude/projects/{project-name}/
ReAlign automatically detects this directory based on your project path and uses it for session tracking.
To disable auto-detection, set in ~/.config/realign/config.yaml:
auto_detect_claude: false
Option B: Manual Configuration
For other AI agents, configure them to save sessions to:
~/.local/share/realign/histories/
Or set a custom path in ~/.config/realign/config.yaml:
local_history_path: "/your/custom/path"
Sessions should be in JSON or JSONL format. See examples/example_session.jsonl for the expected format.
3. Make commits as usual
git add .
git commit -m "Add user authentication"
ReAlign will automatically:
- Find the latest chat session
- Generate a summary
- Copy the session to
.realign/sessions/ - Append metadata to your commit message
Your commit message will include:
Add user authentication
Agent-Summary: Discussion about implementing user authentication with JWT tokens
Agent-Session-Path: .realign/sessions/1699012345_alice_claude_a1b2c3d4.jsonl
Agent-Redacted: false
4. Search and view sessions
Search for commits and sessions:
realign search "authentication"
realign search "bug fix" --show-session
View a session from a commit:
realign show abc1234
realign show --session .realign/sessions/some_session.jsonl
Configuration
Global Configuration
Edit ~/.config/realign/config.yaml:
local_history_path: "~/.local/share/realign/histories"
summary_max_chars: 500
redact_on_match: false
hooks_installation: "repo"
use_LLM: true
llm_provider: "auto" # Options: "auto", "claude", "openai"
auto_detect_claude: true # Automatically detect Claude Code sessions
Configuration Options
local_history_path: Default directory for agent sessions (fallback when Claude not detected)summary_max_chars: Maximum length of commit message summaryredact_on_match: Auto-redact sensitive information (not yet implemented)hooks_installation: Git hooks installation mode ("repo"setscore.hooksPath)use_LLM: Use LLM API (Anthropic/OpenAI) for intelligent summaries (falls back to local if unavailable)llm_provider: LLM provider selection -"auto"(try Claude then OpenAI),"claude"(Anthropic only), or"openai"(OpenAI only)auto_detect_claude: Automatically detect and use Claude Code session directories
Environment Variables
Override configuration with environment variables:
export REALIGN_LOCAL_HISTORY_PATH="/custom/path"
export REALIGN_SUMMARY_MAX_CHARS=300
export REALIGN_USE_LLM=true
export REALIGN_LLM_PROVIDER=auto # Options: auto, claude, openai
export REALIGN_AUTO_DETECT_CLAUDE=true
# LLM API Keys
export ANTHROPIC_API_KEY="your-anthropic-api-key" # For Claude summaries
export OPENAI_API_KEY="your-openai-api-key" # For GPT summaries
Note: Setting REALIGN_LOCAL_HISTORY_PATH disables Claude auto-detection and uses the specified path directly.
LLM Summaries
ReAlign can use LLM APIs to generate intelligent summaries. It supports both Anthropic (Claude) and OpenAI (GPT).
Choosing Your LLM Provider
You can configure which LLM provider to use with the llm_provider setting:
# Method 1: Using realign config command
realign config set llm_provider auto # Try Claude first, then OpenAI (default)
realign config set llm_provider claude # Use only Claude (Anthropic)
realign config set llm_provider openai # Use only OpenAI (GPT)
# Method 2: Using environment variable
export REALIGN_LLM_PROVIDER=claude
# Method 3: Edit config file directly
vim ~/.config/realign/config.yaml
Option 1: Anthropic Claude (Recommended)
-
Install the anthropic package:
pip install anthropic
-
Set your API key:
export ANTHROPIC_API_KEY="your-api-key"
Get your API key from: https://console.anthropic.com/
Option 2: OpenAI GPT
-
Install the openai package:
pip install openai
-
Set your API key:
export OPENAI_API_KEY="your-api-key"
Get your API key from: https://platform.openai.com/api-keys
Configuration
Enable LLM summaries in your config (~/.config/realign/config.yaml):
use_LLM: true
llm_provider: "auto" # Options: "auto", "claude", or "openai"
Provider Behavior:
"auto"(default): Tries Claude first, falls back to OpenAI if Claude fails"claude": Uses only Claude (Anthropic API). Will not fall back to OpenAI if it fails."openai": Uses only OpenAI (GPT API). Will not try Claude.
If LLM generation fails or no API keys are set, ReAlign automatically falls back to local summarization.
Commands
realign init
Initialize ReAlign in a git repository. If not in a git repository, offers to initialize one for you.
realign init [--yes] [--skip-commit]
Options:
--yes, -y: Skip all confirmation prompts (including git initialization)--skip-commit: Don't auto-commit the hook file
Examples:
# Initialize in existing git repo
realign init
# Auto-initialize git and skip all prompts
realign init --yes
# Initialize without committing hooks
realign init --skip-commit
realign search
Search through commits and sessions.
realign search <keyword> [--show-session] [--max N]
Options:
--show-session: Display session content for matches--max N, -n N: Maximum number of results (default: 20)
realign show
Display a session from a commit or file.
realign show <commit>
realign show --session <path>
Options:
--session PATH, -s PATH: Direct path to session file--format FORMAT, -f FORMAT: Output format (pretty, json, raw)--pager, -p: Use pager (less) for output
realign config
Manage ReAlign configuration.
realign config init # Create default config file
realign config get # Show all config values
realign config get llm_provider # Get specific config value
realign config set llm_provider claude # Set LLM provider to Claude
realign config set llm_provider openai # Set LLM provider to OpenAI
realign config set llm_provider auto # Set LLM provider to auto (default)
realign config set use_LLM true # Enable LLM summaries
Options:
init: Create default config file at~/.config/realign/config.yamlget [key]: Display all config values or a specific valueset <key> <value>: Update a configuration value
Available configuration keys: local_history_path, summary_max_chars, redact_on_match, hooks_installation, use_LLM, llm_provider, auto_detect_claude, auto_detect_codex
realign version
Show ReAlign version.
realign version
Session File Format
ReAlign expects JSONL (JSON Lines) format for chat sessions:
{"role": "user", "content": "How do I implement X?", "timestamp": "2024-01-01T10:00:00"}
{"role": "assistant", "content": "Here's how you implement X...", "timestamp": "2024-01-01T10:00:05"}
Required fields:
role: "user" or "assistant"content: The message content
Optional fields:
timestamp: ISO 8601 timestamp- Any other metadata
Git LFS for Large Histories (Optional)
If your chat histories are large, consider using Git LFS:
git lfs install
git lfs track ".realign/sessions/*.jsonl"
git add .gitattributes
git commit -m "chore: track sessions with LFS" --no-verify
Development
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# With coverage
pytest --cov=realign --cov-report=html
Project Structure
ReAlign/
โโโ src/realign/ # Main package
โ โโโ cli.py # CLI entry point
โ โโโ config.py # Configuration management
โ โโโ commands/ # CLI commands
โ โโโ init.py # Init command
โ โโโ search.py # Search command
โ โโโ show.py # Show command
โโโ .realign/ # ReAlign data (in each project)
โ โโโ hooks/ # Git hooks
โ โ โโโ prepare-commit-msg
โ โโโ sessions/ # Copied chat sessions
โ โโโ tools/ # Helper scripts
โ โโโ agent_commit_helper.py
โโโ tests/ # Test suite
โโโ examples/ # Example files
โโโ pyproject.toml # Project configuration
How It Works
-
Hook Installation:
realign initsets git'score.hooksPathto.realign/hooks -
Commit Time: When you commit, the
prepare-commit-msghook runs -
Helper Execution: The hook calls
agent_commit_helper.pywhich:- Finds the latest chat session
- Generates a summary (LLM or local)
- Copies the session to
.realign/sessions/ - Returns JSON with summary and path
-
Message Enhancement: The hook appends metadata to the commit message
-
Session Versioning: The session file is git-added to the same commit
Security & Privacy
โ ๏ธ Important: Chat sessions may contain sensitive information!
- ReAlign does NOT automatically redact sensitive data (MVP)
- Review sessions before pushing to public repositories
- Consider adding
.realign/sessions/to.gitignorefor private projects - Use
.gitattributesto mark sessions as binary or use Git LFS
Future versions will include:
- Automatic secret detection
- Interactive redaction
- Configurable patterns
Troubleshooting
Hook not running
Check that the hook is installed:
git config core.hooksPath
# Should output: .realign/hooks
ls -la .realign/hooks/prepare-commit-msg
# Should be executable
"realign command not found" in git hooks
This usually means the realign commands are not in your PATH.
If you installed with pipx:
# Check if pipx binaries are in PATH
echo $PATH | grep ".local/bin"
# If not, run pipx ensurepath and restart your terminal
pipx ensurepath
# Then close and reopen your terminal
# Verify installation
which realign
realign version
If you installed with pip in a virtual environment:
# The virtual environment must be activated when git hooks run
# This is why pipx is recommended for end users
# Solution 1: Use pipx instead
pipx install realign
# Solution 2: Make sure venv is always activated
# Add to your shell rc file (~/.zshrc or ~/.bashrc):
source ~/path/to/your/venv/bin/activate
"No module named 'realign'" error
This means Python can't find the realign package.
# Check which python is being used
which python3
# Check if realign is installed for that python
python3 -c "import realign; print(realign.__file__)"
# If using pipx, verify installation
pipx list | grep realign
# If missing, reinstall
pipx install realign
Dev environment: Changes not taking effect
If you're developing ReAlign and your changes aren't being used:
# Check which realign is being used
which realign
# If it shows ~/.local/pipx/venvs/realign/..., you're using pipx version
# Option 1: Install in editable mode with pipx
pipx uninstall realign
pipx install -e ~/Projects/ReAlign
# Option 2: Use pip in virtual environment
cd ~/Projects/ReAlign
source venv/bin/activate
pip install -e .
# Now make sure this venv is active when testing
# Verify you're using the dev version
python3 -c "import realign; print(realign.__file__)"
# Should show: ~/Projects/ReAlign/src/realign/__init__.py
No sessions found
Verify your history path:
cat ~/.config/realign/config.yaml
ls ~/.local/share/realign/histories/
LLM summaries not working
Check your API keys:
# Check if API keys are set
echo $ANTHROPIC_API_KEY # For Claude
echo $OPENAI_API_KEY # For GPT
# At least one should output your key
# Test with LLM disabled to use local fallback
REALIGN_USE_LLM=false git commit -m "test"
pipx: command not found
Install pipx first:
# macOS
brew install pipx
# Ubuntu/Debian
sudo apt update
sudo apt install pipx
# Fedora
sudo dnf install pipx
# Or via pip (any OS)
python3 -m pip install --user pipx
# Then ensure PATH is set
python3 -m pipx ensurepath
# Restart your terminal after this
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details
Credits
Developed as part of the ReAlign project to improve the traceability and context of AI-assisted development.
Roadmap
- Automatic secret detection and redaction
- Support for Anthropic Claude LLM provider
- Support for local models (Ollama, etc.)
- Web UI for browsing sessions
- Session diff viewer
- Multi-agent support
- CI/CD integration
- VSCode extension
- Session compression
- Enhanced search with vector embeddings
BUGs๏ผ
- [] When a user makes manual modifications without any AI assistance, the commit summary will still default to the last chat history.
- [] summary is chinese right now
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file realign_git-0.3.3-py3-none-any.whl.
File metadata
- Download URL: realign_git-0.3.3-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b87728a031de01e9f2b239bd7d86c5689dd407abfd2027ce838a847d458893d
|
|
| MD5 |
1a4d1539fd59c06372c31cf94a27578a
|
|
| BLAKE2b-256 |
fdc0ba2cc7046cf638ab49b8119c2578312df6f966a8cc6202faedbbb7a77e22
|