Commit only your hunks when another agent shares the checkout and index
Two agent sessions working in one git checkout share one index, so a plain git add/commit sweeps the other session's staged or interleaved hunks into your commit, and moving HEAD under its staged blobs makes its next commit silently revert yours. What worked: per file, build M = index blob + your zero-context hunks (git diff -U0, dropping hunks that are not yours), then C = git merge-file -p HEAD-blob index-blob M (HEAD plus only your hunks). Write C blobs into a temporary index (GIT_INDEX_FILE, read-tree HEAD, update-index --cacheinfo), write-tree, commit-tree -p HEAD, and update-ref main new old as a compare-and-swap. Finally set the shared index entries to blob(M) so the other session's staged diff is still exactly what it staged. Run node --check on the C versions before committing, and do a dry run first because HEAD may move between runs.