---
name: multi-agent-hunk-ownership
description: Multi-agent hunk-ownership guidance for preserving user and other-agent changes while editing, formatting, staging, and committing.
---

# Multi-Agent Hunk Ownership

Use this skill before editing, formatting, staging, reverting, resolving conflicts, or committing in
a dirty worktree.

## Core Rule

Assume the user and other agents may be editing the same repository at the same time.

A hunk is one contiguous Git diff block, bounded by an `@@` header, that Git stages as one unit under
`git add -p`; it contains one or more added, removed, or replaced lines.

Do not delete, revert, overwrite, format, restage, or commit hunks you did not create unless the user
explicitly asks you to do so. File paths are not enough to prove ownership; ownership is tracked at
the hunk and line level.

## Before Editing

- Inspect `git status --short` in the target repo.
- Treat every pre-existing modified, staged, or untracked file as user-owned or other-agent-owned
  until proven otherwise.
- If your work must touch a dirty file, inspect `git diff -- <path>` and identify which hunks are
  yours to edit.
- If the existing hunks overlap semantically with the requested change, stop and ask one targeted
  question before editing.

## While Editing

- Keep a hunk log for multi-file work or any dirty-worktree task.
- Preserve unrelated hunks exactly as found.
- Do not run broad formatting or rewrite commands over dirty files unless the task explicitly owns
  every affected hunk.
- Prefer narrow edits that avoid moving unrelated lines.

## Before Staging

- Treat staging as commit intent, not as work-in-progress scratch space.
- Do not stage files until immediately before committing or handing off to `ship`.
- If you find staged changes you did not stage, assume another user or agent owns them.
- Do not unstage, amend, overwrite, or commit another actor's staged changes without explicit
  approval.
- If a file is `MM`, it has a staged snapshot plus newer unstaged edits. Inspect both
  `git diff --staged -- <path>` and `git diff -- <path>` before committing or changing the staged
  state.
- Do not commit an `MM` file unless the staged hunks are intentionally the next commit and the
  unstaged hunks are classified as separate work.
- Inspect `git diff -- <path>` and `git diff --staged -- <path>` when a file has mixed ownership.
- Use patch staging when a file contains both current-task hunks and unrelated hunks.
- Do not use `git add <path>` on a mixed-ownership file unless every changed hunk in that path is
  approved for the current commit unit.
- Classify every unstaged and untracked file as current-task, unrelated/user-owned,
  other-agent-owned, generated, intentionally excluded, or blocking/unclear.

## Hunk Log

For any dirty-worktree or multi-file task, record:

- path changed
- hunk or section changed
- purpose of the hunk
- whether the hunk belongs to the current task
- unrelated files or hunks observed and left untouched

## Stop Conditions

Stop and ask when:

- ownership of a hunk is unclear
- current-task and unrelated hunks cannot be safely separated
- a formatting, lint, generator, or merge tool would rewrite unrelated hunks
- another agent's staged work would need to be unstaged, rewritten, or committed by you
- staged changes exist but are not clearly ready and approved for the next commit
