{"id":51525617,"url":"https://github.com/deligoez/hc","last_synced_at":"2026-07-08T21:01:24.246Z","repository":{"id":368845172,"uuid":"1202156621","full_name":"deligoez/hc","owner":"deligoez","description":"Hunk-based atomic git commits for AI agents. One JSON plan, N commits.","archived":false,"fork":false,"pushed_at":"2026-07-02T13:58:52.000Z","size":195,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-07-02T14:15:49.519Z","etag":null,"topics":["ai-agents","atomic-commits","cli","developer-tools","git","golang"],"latest_commit_sha":null,"homepage":"https://github.com/deligoez/hc/releases","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deligoez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-05T17:11:39.000Z","updated_at":"2026-07-02T13:59:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/deligoez/hc","commit_stats":null,"previous_names":["deligoez/hc"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/deligoez/hc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligoez%2Fhc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligoez%2Fhc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligoez%2Fhc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligoez%2Fhc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deligoez","download_url":"https://codeload.github.com/deligoez/hc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligoez%2Fhc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35278166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","atomic-commits","cli","developer-tools","git","golang"],"created_at":"2026-07-08T21:01:22.184Z","updated_at":"2026-07-08T21:01:24.238Z","avatar_url":"https://github.com/deligoez.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hc -- Hunk Commits\n\nHunk-based atomic commits for AI agents. One JSON plan, N commits.\n\nAI agents produce large diffs that should be split into atomic commits. The agent knows *which hunks belong together* but has no reliable way to execute that plan -- `git add -p` is interactive, manual `git apply` requires line-number arithmetic, and full-file `git add` can't split a file across commits.\n\n`hc` solves this: the agent writes a JSON plan mapping hunks to commits, and `hc` handles everything else.\n\n## Install\n\n**Homebrew** (macOS / Linux):\n\n```bash\nbrew install deligoez/tap/hc   # alias for the deligoez-hc formula; installs the 'hc' binary\n```\n\n**Go**:\n\n```bash\ngo install github.com/deligoez/hc/cmd/hc@latest\n```\n\nOr download a binary from [releases](https://github.com/deligoez/hc/releases).\n\n## Quick Start\n\n```bash\n# 1. See what changed -- indices, enclosing function, and the changed lines in one call\nhc diff --json\n```\n\n```json\n{\n  \"files\": [{\n    \"path\": \"auth.go\",\n    \"hunks\": [{\n      \"index\": 0,\n      \"header\": \"@@ -12,3 +12,5 @@\",\n      \"section\": \"func Login(w http.ResponseWriter, r *http.Request) {\",\n      \"added\": 5, \"deleted\": 3,\n      \"fingerprint\": \"3f2a9c184b0d\",\n      \"content\": \"-if token == \\\"\\\" {\\n+if len(token) \u003c 16 {\\n...\"\n    }]\n  }],\n  \"summary\": {\"files\": 1, \"hunks\": 1, \"added\": 5, \"deleted\": 3}\n}\n```\n\n```bash\n# 2. Write a plan\ncat \u003e plan.json \u003c\u003c 'EOF'\n{\n  \"commits\": [\n    {\n      \"message\": \"fix(auth): validate token length\",\n      \"files\": [{\"path\": \"auth.go\", \"hunks\": [0, 1]}]\n    },\n    {\n      \"message\": \"feat(auth): add refresh endpoint\",\n      \"files\": [\n        {\"path\": \"auth.go\", \"hunks\": [2, 3]},\n        {\"path\": \"handler.go\"}\n      ]\n    }\n  ]\n}\nEOF\n\n# 3. Execute\nhc run plan.json\n```\n\n## How It Works\n\n```\nAgent  --writes--\u003e  plan.json  --stdin/file--\u003e  hc  --git calls--\u003e  repository\n         Looks at diff once.      Validates plan.       Stages \u0026 commits.\n         Assigns hunks.           Re-indexes hunks.     Working tree untouched.\n         Done.                    Builds patches.\n```\n\n1. Agent runs `hc diff --json` to see all hunks with indices, enclosing function, and changed lines\n2. Agent writes a commit plan (JSON) mapping hunks to commits\n3. Agent runs `hc run plan.json` -- all commits created in one call\n\nThe agent never touches `git add`, `git apply`, or `git commit` directly.\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `hc diff` | Show current diff with numbered hunk indices |\n| `hc diff --json` | Same, as structured JSON with hunk content, section, and fingerprint |\n| `hc run \u003cplan\u003e` | Execute commit plan from file |\n| `hc run -` | Execute commit plan from stdin |\n| `hc run --dry-run \u003cplan\u003e` | Validate plan without committing |\n| `hc plan` | Draft working-tree plan (file-first + section-split, TODO messages) |\n| `hc log \u003cbase\u003e..\u003chead\u003e` | Per-commit indexed hunks (`--files-only` for a cheap survey) |\n| `hc split \u003cbase\u003e..\u003chead\u003e` | Emit a draft one-file-per-commit rewrite plan |\n| `hc rewrite \u003cplan\u003e` | Split existing commits -- conflict-free history rewrite with backup ref |\n| `hc --version` | Show version |\n\n## Splitting Existing Commits\n\nToo-coarse commits that already exist (pre-hc history, over-grouped runs) can be split retroactively:\n\n```bash\nhc log main..HEAD --json     # per-commit indexed hunks, same schema as hc diff\nhc rewrite plan.json         # {\"rewrites\":[{\"commit\":\"\u003csha\u003e\",\"commits\":[...]}]}\n```\n\nEach split must reproduce the original commit's tree byte-for-byte (verified), so downstream commits re-parent without conflicts, the working tree is never touched, and the branch moves in one atomic step with the old head saved at `refs/hc/backup/\u003cbranch\u003e`. Author identities/dates are preserved; pushed commits require `--force`.\n\n## Plan Format\n\n```json\n{\n  \"commits\": [\n    {\n      \"message\": \"commit message\",\n      \"files\": [\n        {\"path\": \"file.go\", \"hunks\": [0, 2]},\n        {\"path\": \"other.go\"}\n      ]\n    }\n  ],\n  \"allow_unplanned\": [\"wip.go\"]\n}\n```\n\n- **`hunks`**: Indices from `hc diff` output. Omit to stage the entire file.\n- **`--prefix`**: `hc run --prefix \"WB-1234: \" \u003cplan\u003e` prepends the string to every commit message (idempotent). For per-commit tickets, write them into the messages.\n- **`allow_unplanned`**: Files/globs excluded from coverage validation (`*` = one level, `**` = recursive).\n- Every hunk in the diff must be assigned to exactly one commit (complete coverage).\n- Renamed/moved files appear as two entries -- a deletion (old path) and a new file -- and both must be planned; git reconstructs the rename in history automatically.\n\n## Architecture\n\n**Two-phase execution:**\n\n- **Phase 1 (Validation):** Parse plan, capture diff, validate coverage, sequential dry-run with temporary index. If anything fails: exit 2, no git state changed.\n- **Phase 2 (Execution):** For each commit: reconstruct the staged file content from the original diff, stage it directly into the index, commit.\n\n**Key algorithms:**\n- Content reconstruction: staged content is rebuilt from the original diff coordinates (base blob + selected hunks) and staged directly via `git hash-object` + `git update-index` -- no patch application, no hunk re-matching\n- Byte-for-byte verification of every deletion against the base, plus a base+all-hunks == working-tree invariant before any commit\n- SHA-256 content fingerprinting exposed in `hc diff --json`\n\n## Exit Codes\n\n| Code | Meaning |\n|------|---------|\n| 0 | Success |\n| 2 | Validation error (plan issue, no git state changed) |\n| 3 | Execution error (unexpected git failure) |\n\nAll errors include `error`, `code`, and `hint` fields for agent consumption. On exit 3 the full result is still printed -- every commit with its `status` and `sha` -- so the caller can re-plan only the remaining changes.\n\n## Claude Code Skill\n\n```bash\nnpx skills add -g deligoez/hc\n```\n\nUpdate after new releases:\n\n```bash\nnpx skills update -g deligoez/hc\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeligoez%2Fhc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeligoez%2Fhc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeligoez%2Fhc/lists"}