惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - Franky
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
量子位
V
Visual Studio Blog
Y
Y Combinator Blog
小众软件
小众软件
N
Netflix TechBlog - Medium
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网

Show HN

GitHub - astefanutti/shaderbang: Shebang for Shaders Show HN: AI agents for UK GDAD PCF roles and their skills The Two Pillars: Mixer Mode and Meta-Software in the Reorganization of Software Work After AI GitHub - JaiCode08/teleport-env What 1,000+ Harness Experiments Taught Me About Self-Improving Agents Show HN: Liiists, a Markdown-first, iOS and CLI list app SwiperTab – Get this Extension for 🦊 Firefox (en-US) GitHub - kouhxp/fftext: Summarize, explain, fact-check, or translate any text, URL, or file. No GPU. No cloud. One command GitHub - sweetpad-dev/sweetpad: Develop Swift/iOS projects using VSCode GitHub - dogmaticdev/IRON: IRON a.k.a. Intermediate Representation Object Notation is a Interpreter/Database that is used to create Programming Languages. GitHub - sjhalani7/vaen: Package your AI coding harness into a portable .agent file, and share it across repos, teams, & the community without ever having to copy-paste instructions, skills, MCP config, or secrets. Show HN: Gandalf the Grader Show HN: Citadeld – replay any CI failure locally from a single file GitHub - tdortman/cuSBF: High-Performance GPU Super Bloom Filter coral-ai/claude-code-token-xray at main · Coral-Bricks-AI/coral-ai GitHub - ulyssestenn/funes: Funes is a Git-based framework for LLM-managed knowledge work: an AI Librarian ingests raw sources, builds an interlinked Markdown knowledge base, and uses it to produce cited reports, analyses, and other outputs. GitHub - harmont-dev/harmont-cli: Command-line client for the Harmont CI platform GitHub - brooksmcmillin/mcp-authflow: OAuth 2.0 Authorization Server framework for MCP servers GitHub - javaid-codes/audit-supply-chain-agents GitHub - amorey/gochan: A small library of common channel architectures for Go, inspired by Rust GitHub - arifozgun/OpenGem: Free, Open-Source AI API Gateway with Gemini, OpenAI & Anthropic Compatibility in 1 file GitHub - Pranesh950/BioPetals: 🌸 Run BIOxAI models at home, BitTorrent-style. Fine-tuning and inference up to 10x faster than offloading GitHub - cnguyen14/bounty-doctor: Diagnose a GitHub bounty issue before you waste hours: detects honeypot scam repos, AI-bot attempt swarms, and stale contests. Show HN: CoreMCP – MCP Server for On-Prem DBs Show HN: KittyHTML – Render HTML/CSS as an inline image in your terminal GitHub - bingud/filemat: Web-based file manager Show HN: TruthLens – Free multi-signal deepfake image detector GitHub - apexlocal-jz/claude-usage-tray: Windows system-tray app showing your Claude Code rate-limit usage at a glance. Zero deps, ~300 lines of PowerShell. Cross-IDE (works regardless of VS Code, Cursor, plain terminal). Release v0.1.2.1 · kouhxp/yapsnap GitHub - noopolis/moltnet: Self-hostable chat network for AI agents. Pre-built bridges for Claude Code, Codex, and the Claws. Rooms, DMs, history. No Slack bots, no Matrix, no glue code.
GitHub - ThatXliner/gah: Git Add Hunk, built for agents t...
thatxliner · 2026-05-28 · via Show HN

gah — Git Add Hunks

gah - Git Add Hunks

CI Crates.io License: MIT Claude Code Plugin

Non-interactive hunk-based staging for git. Stage specific hunks by index, content anchor, regex, or line range—no interactive prompts required. Split hunks into smaller pieces and stage individual changed lines, the non-interactive equivalent of git add -p's split and edit modes.

gah demo

The Problem

git add -p is great for selective staging, but it requires interactive stdin. That makes it unusable for:

  • AI coding agents (Claude, Copilot, Cursor) that can't interact with prompts
  • Scripts and automation that need deterministic staging
  • Remote/headless environments where interactive TTY isn't available

Installation

CLI

cargo install gah

Claude Code

Install the CLI above, then:

/plugin install ThatXliner/gah

Or manually:

mkdir -p .claude/skills
git clone https://github.com/ThatXliner/gah.git .claude/skills/gah

Claude Code will auto-use gah for selective staging instead of git add -p.

Other AI Agents (Codex, Cursor, etc.)

Install the CLI, then add the skill instructions from skills/gah/SKILL.md to your agent's context.

Usage

Preview hunks

# Show hunks with indices
gah preview src/main.rs

# Preview all modified files
gah preview --all

# Machine-readable JSON output
gah preview src/main.rs --json

Output:

[1:Apparent] @@ -341,7 +341,8 @@ fn render_key_summary(
    context line
 + new line
 - old line
    context line

[2:Caption] @@ -363,7 +364,15 @@ fn render_binding_summary(
    ...

src/main.rs: 2 hunks

The word after the index is the anchor—a single-token content hash that stays stable even when line numbers shift. Anchors are chosen to be single tokens in common LLM tokenizers for maximum efficiency.

Stage by hunk index

# Stage specific hunks
gah add src/main.rs --hunks 1,3,5

# Stage a range
gah add src/main.rs --hunks 1-3,7

Stage by anchor (content hash)

Anchors are stable identifiers based on hunk content. Unlike indices, they don't change when other hunks are staged or when line numbers shift. Ideal for AI agents that preview once, then stage later.

# Stage by full or partial anchor
gah add src/main.rs --anchor Apparent
gah add src/main.rs -a App      # prefix match works

Stage by regex

# Stage hunks containing a pattern
gah add src/main.rs --grep "TODO"

# Exclude hunks matching a pattern
gah add src/main.rs --grep "debug" --invert

Stage by line range (partial hunks)

--lines stages only the changed lines within the given working-tree range, trimming each matched hunk down to that range. Additions outside the range are dropped; deletions outside the range are left in place. This lets you stage a single changed line out of a larger block—something git add -p's split mode can't do for adjacent changes.

# Stage only the changes on lines 100-150 (working tree lines)
gah add src/main.rs --lines 100-150

# Stage one line out of a multi-line edit
gah add src/main.rs --lines 142

# Multiple ranges
gah add src/main.rs --lines 100-150,200-250

Split hunks into smaller pieces

By default git groups nearby changes into one hunk. --split re-diffs with zero context so each change becomes its own hunk, then you can preview or stage them independently.

# Preview the finest-grained hunks
gah preview src/main.rs --split

# Stage one of the split-out changes by anchor
gah add src/main.rs --split --anchor Beast

Adjacent changed lines can't be separated by --split (git keeps them in one hunk even at zero context)—use --lines to pick individual lines out of such a block.

Stage by AST symbol (requires tree-sitter feature)

Stage hunks that touch specific functions, classes, or other code symbols using tree-sitter AST analysis.

# Install with tree-sitter support
cargo install gah --features tree-sitter

# Stage hunks touching a function
gah add app.py --symbol subtract

# Multiple symbols
gah add app.py --symbol subtract --symbol multiply

Supported languages: Python, JavaScript, TypeScript, Rust, Go.

Combine filters

gah add src/main.rs --grep "feature" --lines 300-500

Dry run

# See what would be staged without actually staging
gah add src/main.rs --hunks 1,3 --dry-run

JSON Output

Add --json for structured output:

gah preview src/main.rs --json
{
  "file": "src/main.rs",
  "hunks": [
    {
      "index": 1,
      "anchor": "Apparent",
      "header": "@@ -341,7 +341,8 @@",
      "old_start": 341,
      "old_count": 7,
      "new_start": 341,
      "new_count": 8,
      "content": "...",
      "function_context": "fn render_key_summary(",
      "additions": 1,
      "deletions": 0
    }
  ]
}

Why not just use...

git add -p — Requires interactive stdin. Can't be used programmatically.

git add -N + git add -p — Still requires interactive input.

git apply — Works, but you need to manually construct the patch. gah handles the patch construction for you.

Editor integrations — Great when available, but not always accessible to scripts or agents.

How it works

  1. Runs git diff to get the current changes
  2. Parses the diff into individual hunks
  3. Filters hunks based on your criteria
  4. Reconstructs a minimal patch for selected hunks
  5. Applies via git apply --cached

License

MIT