What Happened
Developer raine released git-surgeon, an open-source Rust CLI that gives AI coding agents precise, non-interactive control over git changes at the hunk level. It's installable via Cargo, Homebrew, or a shell script, and ships with built-in skill installers for Claude Code, Codex, and OpenCode.
The core problem: AI agents can't use interactive git commands like git add -p. When an agent modifies five files but only two changes are related, it either stages everything in one messy commit or resorts to destructive workarounds like resetting entire files and manually reconstructing changes. Git-surgeon eliminates that by providing deterministic, non-interactive commands.
The tool works with stable hunk IDs - 7-character hex strings derived from SHA-1 hashes of the file path and hunk content. These IDs stay constant even when line numbers shift above a hunk, so an agent can reliably reference specific changes across multiple operations.
Key commands include hunks (list all changes with IDs), stage (stage specific hunks or line ranges), commit (atomic stage-and-commit), split (decompose a commit into focused pieces), fixup (fold changes into an earlier commit), and discard (permanently remove uncommitted changes for specific hunks). Line-range precision lets you stage lines 5-30 of a hunk while leaving the rest unstaged.
The project comes from the same developer behind workmux (git worktrees + tmux for parallel AI workflows) and claude-history (conversation history search).
Why It Matters
Anyone who uses AI coding agents has seen the commit quality problem. You ask an agent to refactor a function, and it touches the target function, fixes an unrelated import, reformats a docstring, and updates a test file. All of that ends up in one commit with a vague message like "refactor: update function."
Git-surgeon lets an agent break that into focused commits: one for the refactor, one for the import fix, one for the test update. The split command can even decompose commits retroactively, so you can clean up after the fact.
The stable hunk IDs are a smart design choice. Most approaches to programmatic git manipulation break when line numbers shift - you stage hunk at line 42, but another change above it pushed it to line 47. SHA-1 based IDs tied to content rather than position solve this cleanly.
For teams with strict commit hygiene standards, this removes one of the biggest friction points with AI-assisted development: getting clean, focused commits out of agents that think in terms of "solve the problem" rather than "make reviewable, atomic changes."
Our Take
This fills a genuine gap. We've watched Claude Code and other agents produce sprawling commits that mix unrelated changes, and the only fix today is manual cleanup or very specific prompting that agents don't always follow.
The skill installer approach is the right distribution model. Running git-surgeon install-skill --claude adds the capability to Claude Code without any workflow change - the agent just starts using it when making granular commits. That's the kind of friction-free integration that drives actual adoption.
The command set is well-designed. hunks, stage, commit, and split cover 90% of what you'd need. The fixup command for folding changes into earlier commits is a power feature that experienced git users will appreciate.
One watch item: this is a single-developer project. For something that touches git history (especially fixup, squash, and split), you want confidence in the implementation. The Rust foundation helps - memory safety matters when you're rewriting commits. But review the source and test on a non-critical repo before integrating it into your main workflow.
If you care about commit quality and use AI coding agents daily, install git-surgeon today. It's the kind of small, focused tool that quietly improves every coding session.