AI-assisted, non-interactive git refactoring via MCP — a focused toolset for rebase & commit perfection, usable by agents or chat users directing the MCP tools.
git-hex is an MCP (Model Context Protocol) server that provides AI assistants with safe, powerful git refactoring capabilities. It handles the complexity of interactive rebasing, fixup commits, and commit amendments while ensuring your repository is never left in a broken state.
Name note: “git-hex” is simply a short label for this git-history refactoring toolkit (not related to hex encoding).
See CHANGELOG.md for notable changes. Version metadata also lives in VERSION and .claude-plugin/plugin.json.
Quick links: docs/install.md • docs/safety.md • docs/clients.md • docs/reference/tools.md • docs/reference/mcp.md • SECURITY.md • CONTRIBUTING.md
- Quick Start
- Safety First
- How it works
- Requirements
- Configuration
- Common workflows
- Tool reference
- CLI testing/debugging
- Diagnostics & Health
- Docker
- Troubleshooting
- Support
- Security
- Safety first: Conflict-prone operations abort cleanly by default and create backup refs so you can always undo.
- Deterministic git: Focus on well-defined history rewrites (rebase, fixup, amend, split-by-file) with predictable outputs.
- Minimal surface: Tools only—no extra services. Everything runs through the MCP Bash Framework.
- Respect the sandbox: Every path is validated against your client’s allowed folders (MCP
roots); read-only mode blocks mutating tools. - Agent friendly: Outputs are structured, include summaries, and prefer explicit parameters over magic.
- Safe Rebasing: Automatic abort on conflicts so git-hex operations leave the repo clean if conflicts arise
- Fixup Commits: Create fixup! commits for later auto-squashing
- Commit Amendments: Safely amend the last commit with staged changes
- Cherry-picking: Single-commit cherry-pick with strategy options
- Undo Support: Backup refs for history-mutating operations (amend, fixup, cherry-pick, rebase, split); undo is safe unless new commits were added after the backup (see
force) - Path Security: All operations respect your client’s allowed folders (MCP
roots) for sandboxed access
Claude Code (recommended):
/plugin marketplace add yaniv-golan/git-hex
/plugin install git-hex@git-hex-marketplace
Cursor / Claude Desktop / Windsurf (MCP config):
git clone https://github.com/yaniv-golan/git-hex.git ~/git-hexThen add to your MCP settings:
{
"mcpServers": {
"git-hex": {
"command": "~/git-hex/git-hex.sh"
}
}
}Windows (Git Bash): see docs/clients.md#windows-git-bash
Prerequisites: git and jq/gojq. No install step needed — the runtime is included. See docs/install.md.
In your AI chat (in a repo), ask:
“Show me the last 5 commits I could rebase onto
main.”
When connected, your AI can use tools like git-hex-getRebasePlan to answer.
Having issues?
- Diagnostics (no persistent changes):
./git-hex.sh doctor - Install/repair prerequisites:
./git-hex.sh install - macOS apps launched from Finder/Spotlight/Dock: use
git-hex-env.sh(seedocs/clients.md) - Install/uninstall details:
docs/install.md - Allowed folders (“roots”) explanation:
docs/concepts.md
- Allowed folders enforcement: repo paths must be inside configured allowed folders (MCP
roots). - Backups for mutations: every history-mutating tool creates
refs/git-hex/backup/...so you can recover. - Conflict safety: rebases/cherry-picks abort and restore by default on conflicts.
- Read-only mode: set
GIT_HEX_READ_ONLY=1to block all mutating tools. - Scoped guarantees: git-hex tools do not run
git push/fetch/pull; dependency installation may use the network unless you preinstall/pin it.
Details: docs/safety.md
- Stage a fix:
git add <files> - In your AI chat, ask it to create a fixup targeting a commit, then autosquash onto
main- Tools involved:
git-hex-createFixup→git-hex-rebaseWithPlan(withautosquash=true)
- Tools involved:
The typical git-hex workflow for cleaning up a feature branch after code review:
flowchart LR
A[Review feedback] --> B[getRebasePlan]
B --> C{Inspect commits}
C --> D[Stage fix]
D --> E[createFixup]
E --> C
C --> F[rebaseWithPlan<br/>autosquash=true]
F --> G[Clean history ✓]
flowchart TB
subgraph readonly["Read-Only"]
plan[getRebasePlan]
predict[checkRebaseConflicts]
conflictStatus[getConflictStatus]
end
subgraph mutating["History & State Changes"]
rebase[rebaseWithPlan]
split[splitCommit]
fixup[createFixup]
amend[amendLastCommit]
cherry[cherryPickSingle]
end
subgraph conflict["Conflict Helpers (no backups)"]
resolve[resolveConflict]
cont[continueOperation]
abort[abortOperation]
end
subgraph safety["Safety Net"]
undo[undoLast]
end
predict -.->|"simulate"| rebase
plan -.->|"plan first"| rebase
fixup -->|"then squash"| rebase
rebase --> conflictStatus
cherry --> conflictStatus
conflictStatus --> resolve
resolve --> cont
abort -.-> rebase
rebase --> undo
split --> undo
fixup --> undo
amend --> undo
cherry --> undo
All history-mutating operations create backup refs, enabling undoLast to restore the previous state. Conflict-resolution helpers (resolveConflict, continueOperation, etc.) do not create backups.
| Dependency | Version/Notes |
|---|---|
MCP Bash Framework (mcp-bash) |
v0.9.6+ |
| bash | 3.2+ |
| jq or gojq | Required |
| git | 2.20+ (2.33+ for ort, 2.38+ for git-hex-checkRebaseConflicts) |
| Variable | Description |
|---|---|
MCPBASH_PROJECT_ROOT |
Project root containing tools/. Auto-set by git-hex.sh and generated wrappers; required only if you invoke mcp-bash directly from outside the repo. |
| Variable | Default | Description |
|---|---|---|
GIT_HEX_READ_ONLY |
unset | 1 blocks mutating tools (see docs/safety.md) |
GIT_HEX_MCPBASH_SHA256 |
unset | If set, ./git-hex.sh install downloads the FRAMEWORK_VERSION tarball and verifies it against this checksum (fails on mismatch) instead of cloning. |
GIT_HEX_MCPBASH_ARCHIVE_URL |
unset | Optional override for the tarball URL used when GIT_HEX_MCPBASH_SHA256 is set. |
MCPBASH_TOOL_ALLOWLIST |
(set by launchers) | Framework v0.7.0+: allowlisted tools may execute. The launchers set an explicit list of git-hex tool names by default (and narrow it in read-only mode). Override to * only for trusted environments. |
Examples:
# Read-only mode (inspection only, no history changes)
GIT_HEX_READ_ONLY=1 ./git-hex.sh
# Verified framework install (CI/supply-chain security)
GIT_HEX_MCPBASH_SHA256="10524108..." ./git-hex.sh install
# In MCP client config (e.g., Claude Desktop)
{
"mcpServers": {
"git-hex": {
"command": "/path/to/git-hex.sh",
"env": { "GIT_HEX_READ_ONLY": "1" }
}
}
}git-hex ships completion providers (refs, commits, conflict paths) registered declaratively via server.d/register.json. Completions require jq/gojq.
Tip: Running
mcp-bashoutside this repo withoutMCPBASH_PROJECT_ROOTstarts the framework’s getting-started helper, not git-hex. Use./git-hex.sh(CLI) or./git-hex-env.sh(macOS apps launched from Finder/Spotlight/Dock; seedocs/clients.md) when launching from other directories or GUI clients.
- Current development version:
0.2.0(seeVERSION). - We plan to publish GitHub Releases with signed tags, release notes, and checksums for verification. Until those are published, pin a specific commit for reproducibility (e.g.,
git checkout <commit-sha>).
- Lint shell scripts:
./test/lint.sh - Run all tests:
./test/run.sh(or./test/integration/run.sh/./test/security/run.sh) - Optional pre-commit hook to auto-run lint:
git config core.hooksPath .githooks - Contributors: see
CONTRIBUTING.mdfor./git-hex.sh validateand the full workflow
Start here: docs/install.md (includes verified framework installs and uninstall/cleanup).
git clone https://github.com/yaniv-golan/git-hex.git ~/git-hexSee docs/clients.md for Claude Code plugin setup, MCP client configuration (Cursor/Windsurf/Claude Desktop/CLI), and launcher guidance.
These examples show how to combine git-hex tools for typical development tasks.
After receiving review feedback, create targeted fixups and squash them:
1. Review current commits
→ git-hex-getRebasePlan { "onto": "main" }
2. For each piece of feedback:
- Make the fix in your editor
- Stage the changes: git add <files>
- Create a fixup targeting the original commit:
→ git-hex-createFixup { "commit": "<hash-of-commit-to-fix>" }
3. Squash all fixups into their targets:
→ git-hex-rebaseWithPlan { "onto": "main", "autosquash": true }
Rebase your feature branch onto the latest main:
1. First, update main:
git checkout main && git pull
2. Switch back to your feature branch:
git checkout feature/my-branch
3. Preview what will be rebased:
→ git-hex-getRebasePlan { "onto": "main" }
4. Perform the rebase:
→ git-hex-rebaseWithPlan { "onto": "main" }
If conflicts occur, git-hex automatically aborts and restores your branch.
Resolve conflicts manually, then retry.
Amend the most recent commit with additional changes:
1. Make your changes in the editor
2. Stage them: git add <files>
3. Amend:
→ git-hex-amendLastCommit { "addAll": true }
Or with a new message:
→ git-hex-amendLastCommit { "message": "Better commit message" }
Bring one specific commit to your current branch:
1. Find the commit hash on the source branch:
git log other-branch --oneline
2. Cherry-pick it:
→ git-hex-cherryPickSingle { "commit": "<hash>" }
If conflicts occur, git-hex aborts automatically.
Made a mistake? Undo it:
→ git-hex-undoLast {}
This restores HEAD to its state before the last git-hex operation.
Works for: amendLastCommit, createFixup, rebaseWithPlan, cherryPickSingle, splitCommit
- On shared/protected branches — Use on personal feature branches only
- For hunk-level splitting —
splitCommitsplits by file only; usegit add -p+ manual commits for line-level splits - On repos with contribution models you don't control — Understand the project's rebase policy first
git-hex handles the local craft of shaping commits, while remote collaboration tools handle working with teammates. Together, they cover the complete pull request lifecycle:
-
Local craft (git-hex) — shape your commits:
git-hex-getRebasePlan— review messy historygit-hex-createFixup— fix earlier commitsgit-hex-rebaseWithPlan— squash/reword for clean history
-
Push:
git push --force-with-lease -
Remote collaboration — work with teammates:
- With GitHub Plugin (from the Official Claude Plugin Marketplace): use its tools for PRs, reviewers, comments
- With GitHub CLI:
gh pr create,gh pr view,gh pr edit
-
After review feedback: return to step 1 for more local craft
Full per-tool parameters, examples, and outputs: docs/reference/tools.md
Detailed safety model, read-only mode, and recovery procedures: docs/safety.md
# Run a tool directly (debug/CI)
./git-hex.sh run-tool git-hex-getRebasePlan --roots /path/to/repo --args '{"count": 5}'
# Run with MCP Inspector (must be run from project root or use ./git-hex.sh)
cd /path/to/git-hex
npx @modelcontextprotocol/inspector --transport stdio -- mcp-bash
# Alternative: use git-hex.sh wrapper (works from any directory)
npx @modelcontextprotocol/inspector --transport stdio -- /path/to/git-hex/git-hex.shNote: The MCP Bash Framework CLI (
mcp-bash) auto-detects the project root when run from within the git-hex directory. If running from elsewhere, either use the./git-hex.shwrapper or setMCPBASH_PROJECT_ROOT=/path/to/git-hex.
- Project validation:
./git-hex.sh validate(ormcp-bash validatefrom the repo) - Ready check:
./git-hex.sh --health(stdio exit code:0ready,1unhealthy,2misconfigured) installpolicy refusal: exits3when refusing to modify a user-managed framework install (e.g.,MCPBASH_HOMEpoints outside the managed path).- Debug a single tool without starting MCP:
./git-hex.sh run-tool <tool> --args '{}' --roots <repo> - Backup inventory:
git for-each-ref refs/git-hex/
docker build -t git-hex .
docker run -i --rm -v /path/to/repo:/repo git-hexUse Docker in one of two modes:
-
Run the MCP server (stdio) in the container (for MCP clients), and configure your client’s allowed folders (MCP
roots/allowedRoots) to include the mounted repo (seedocs/concepts.md). -
Debug a single tool call in the container via
run-tool(in this mode,--rootsis valid because it applies torun-tool). -
With MCP Inspector:
npx @modelcontextprotocol/inspector --transport stdio -- \ docker run -i --rm -v /path/to/repo:/repo git-hex
-
With a client config that starts the server:
{ "mcpServers": { "git-hex": { "command": "docker", "args": ["run", "-i", "--rm", "-v", "/path/to/repo:/repo", "git-hex"] } } }
repoPath must be within an allowed folder (MCP roots); pass it explicitly when you mount multiple repositories.
Debug a single tool call in the container:
docker run --rm -v /path/to/repo:/repo git-hex \
run-tool git-hex-getRebasePlan --roots /repo --args '{"count": 5}'undoLastfails because of new commits: re-run with"force": trueif you intend to discard the commits added after the git-hex operation. If a rebase/merge/cherry-pick is paused, resolve/abort it first.- Stuck rebase/cherry-pick: run
git-hex-getConflictStatus, resolve files, thengit-hex-continueOperation; if you want to abandon, usegit-hex-abortOperation. - MCP connectivity or repo path errors: ensure
repoPathis inside your configured allowed folders (MCProots) and that the repo is clean when required (see tool prerequisites anddocs/concepts.md). - GPG signing/pinentry hangs: tools that create commits default to unsigned commits to avoid non-interactive hangs. If you want signed commits, set
"signCommits": trueon the relevant tool call.
User docs:
- Install:
docs/install.md - Safety & recovery:
docs/safety.md - Client setup:
docs/clients.md - Tool reference:
docs/reference/tools.md - MCP/framework details:
docs/reference/mcp.md
Plugin/workflows:
- Skills:
skills/git-hex-branch-cleanup/SKILL.md,skills/git-hex-conflict-resolution/SKILL.md,skills/git-hex-pr-workflow/SKILL.md - Claude command templates:
claude-commands/
Project:
- CHANGELOG:
CHANGELOG.md - Plugin metadata:
.claude-plugin/ - Server metadata/policy:
server.d/
See SUPPORT.md.
See SECURITY.md for how to report vulnerabilities.
MIT License - see LICENSE for details.
Contributions welcome! Please ensure:
- All tools pass
mcp-bash validate(MCP Bash Framework CLI) - New tools follow the naming convention (
git-hex-toolName) - Tests are included for new functionality
Download the latest bundle from GitHub Releases — look for git-hex-<version>.mcpb.
Install by double-clicking the .mcpb file in Claude Desktop or other MCPB-compatible clients. The bundle includes the embedded framework, all tools, prompts, and resources.
For development or custom builds:
make bundle # Output: dist/git-hex-<version>.mcpb- mcp-bash-framework - The MCP server framework powering git-hex
- Model Context Protocol - The protocol specification
