Compose the semantic commit message from immutable evidence. Let ai-commit own deterministic preparation, commit,
index reconciliation, and push mechanics.
Run every command from the target repository cwd. Do not surround ai-commit with extra git status, git log, or
git diff calls: preparation provides the complete evidence for this workflow. Use --porcelain only in deterministic
automation that explicitly parses its stable TSV records. The normal skill flow consumes the human-readable sections.
1. Parse Arguments
Arguments: $ARGUMENTS
ai-commitselects the message format from repository config. Pass--naturalor--conventionalonly as an explicit one-off override, never to reproduce repository policy.--all: capture all worktree and index changes. This intentionally risks including another agent's work.--staged: capture exactly the current index. Do not add session paths. It conflicts with--all.--natural: force Natural Language Format for this commit.--conventional: force Conventional Prefix Format for this commit.--push: request a push after commit. Otherwise push only when standing instructions authorize it.--rebase: with--push, letai-commitrebase a behind branch onto its fetched upstream before the push. Pass it with every authorized push unless the user excludes it.--close <issue_numbers>: append oneCloses #Ntrailer per positive decimal issue number. Accept comma- or space-separated input.--finding <finding_ids>: append oneFinding-ID: <id>trailer per ledger finding this commit fixes. Accept comma- or space-separated input. Also infer a finding from context when this session's commit fixes a specific ledger finding. Never include or resolve findings the commit does not actually fix.--squash: replace every branch commit after the merge base with one commit that carries the net branch diff. The helper finds the merge base with the resolved default branch. Squash mode requires a clean tree and index and an attached non-default branch. It conflicts with--all,--staged, and--push.--base <branch>: override default-branch detection. Use it only with--squash.- In Conventional Prefix Format, a positional type keyword overrides the inferred type. In Natural Language Format, a positional verb or category keyword overrides the inferred verb. Quoted positional text overrides the inferred description or subject.
If the requested operation is only to push a clean branch that is already ahead, skip preparation. Resolve the push destination below, then use its push command.
Push Destination
When working on an existing PR, resolve its head repository and branch from gh pr view before committing or pushing.
Use the PR's head as the destination, including when the local branch has a different name. Verify the configured
upstream against that destination. A push to another branch does not update the PR.
ai-commit supports a named upstream with the same branch name. A fork URL configuration can appear to have no upstream
and trigger its fallback to origin. For a fork URL or differently named PR branch, commit without --push. Fetch the
PR head and verify that the committed head contains it. Then push the verified commit explicitly:
git push --no-follow-tags '<head-repository-url>' '<commit-oid>:refs/heads/<head-branch>'
Do not force-push. Re-read the PR and verify that its head SHA matches the pushed commit before reporting completion.
For other supported destinations, use ai-commit push --rebase or the commit command's --push --rebase flags.
Squash Mode
Enter squash mode only when the user explicitly requests a squash. Never infer it from branch state, a merge request, or
standing instructions. When --squash is present, follow references/squash.md for the plan and
reset steps. Then continue with steps 2 to 5 in --staged mode. Never pass --push in squash mode, even when standing
instructions authorize a push. The squash reference adds the co-author trailers, the rollback on failure, and the squash
report.
2. Prepare Once
Run one preparation command:
ai-commit prepare [--all | --staged] [--natural | --conventional] --diff full \
[--exclude-baseline '<path>=<oid>']... [-- <session-modified-paths>...]
-
Read the full preparation output. Never pipe it through
tail,head,awk,grep, or similar. It carries both the printed transaction ID and the diff step 3 must analyze, and a truncating pipe discards the evidence along with the ID. -
Use
--diff summaryinstead only when the full diff is too large to read in one pass (for example, a repository-wide migration across hundreds of files) and this session already reviewed the content. In that case, compose the message from the name-status, shortstat, and that review. -
Before default-mode preparation, run the repository's formatter on this session's edited paths only, so a formatting pre-commit hook cannot modify the content after it is pinned.
-
Build the default-mode path list from individual repository-relative files with changes attributable to this session. Expand directory paths to those file paths, including new and deleted files. Never build the list by parsing
git statusorgit status --porcelainoutput, which can include another agent's untracked or modified files. Default mode requires every path edited in this session. For a rename, include both old and new file paths, including case-only file or directory renames. -
Before default-mode preparation, run
ai-coord touchedwhen available and reconcile its output against the session path list. For that cross-check, add missed session-edited paths. Ignore paths this session did not semantically change. Touched paths are best-effort evidence, not authority. When the command is unavailable or the session is unrecognized, skip this cross-check silently. -
--allaccepts no explicit paths and captures all tracked, untracked, modified, deleted, and staged changes. -
--stagedaccepts neither explicit paths nor baseline exclusions and captures the shared index exactly. -
ai-commit prepareautomatically applies this session's ai-coord stale-dirt baselines. Auto-applied exclusions appear in the preparation evidence and must be disclosed unchanged. Explicit--exclude-baselineremains available for overrides, and--no-auto-baselinedisables discovery for deterministic automation. Never revert unrelated changes.If coordination re-entry records this session's completed edits as a baseline, compare its blob IDs with retained session or preparation evidence. Use
--no-auto-baselineonly when every selected file's entire delta is attributable to the authorized task. Preserve exclusions for mixed ownership or uncertain attribution.
Preparation pins the exact tree and delta under the printed transaction ID without changing the shared index. Keep that ID. The later commit reuses the transaction instead of recomputing intended content from the mutable worktree or shared index. It applies that immutable delta to the locked current branch and fails safely if intervening branch movement conflicts. If preparation fails before issuing a transaction ID, correct the evidenced argument, attribution, or input problem and retry preparation within the authorized scope.
3. Analyze and Compose
Analyze the single prepared full diff. Do not replace a valid preparation merely to get different evidence. Oversized
per-file sections arrive cut with a DIFF_TRUNCATED disclosure. Their name-status and shortstat evidence still governs
the message.
- Use the printed message format and message-format rules.
ai-commitis the source of those rules. Do not load a separate Conventional or Natural reference. - Apply positional overrides, detect breaking changes, infer scope or context from the code, and include a body only when it adds material rationale.
- Add
Closes #Ntrailers from--closeand from transcript issue references only when this commit actually resolves them. De-duplicate issue numbers. - Add one
Finding-ID: <id>trailer per finding supplied by--findingor inferred from context that this commit actually fixes. De-duplicate finding IDs. - Append the exact
Agent-Session:line from the preparation trailer section when present.ai-commithas already validated it. Do not synthesize or repair a missing or malformed trailer.
Compose one subject paragraph, an optional body paragraph, and one final trailer paragraph containing all Closes,
Finding-ID, and Agent-Session lines.
ai-commit receives every -m value verbatim and rejects a literal \\n. Write real line breaks inside the quoted
argument, as in the step 4 example.
4. Commit the Transaction
Run:
ai-commit commit <transaction-id> -m '<subject>' [-m '<body>'] [-m '<trailers>'] [--push --rebase]
For example, a two-item body is one -m argument containing a physical newline:
ai-commit commit <transaction-id> -m '<subject>' -m '- first material change
- second material change' [-m '<trailers>'] [--push --rebase]
Append --push --rebase when a push is authorized and the Push Destination rules select ai-commit. It then rebases a
behind branch onto its fetched upstream only when no Git operation is in progress and the working tree and index are
clean. It aborts a rebase that stops. The same command handles default, --all, and --staged transactions. Never
stage or commit them with direct Git commands.
Transactions are idempotent. After an interruption, lock race, or retryable exit, retry the same transaction ID and message arguments. For those retryable failures, do not prepare a replacement from newer mutable state. A replay recovers or returns the retained receipt without creating a duplicate commit. Never delete an index lock.
For a deterministic content failure proven to precede commit creation, correct the authorized work and supersede the
uncommitted preparation using the recovery reference. This includes snapshot-check hook modified prepared content. An
immutable retry cannot repair content pinned in a failed snapshot. Existing task authority covers this recovery.
Read references/failure-recovery.md before superseding a failed preparation or adding
--no-verify or --no-gpg-sign. Bypass flags are explicit per-attempt recovery options, not first-attempt defaults.
After COMMITTED <transaction-id> <commit-oid>, resolve every included finding with
ai-coord finding resolve '<id>' --as fixed --commit '<commit-oid>'. The OID is a 12-character abbreviation. Pass it
as-is.
5. Completion and Receipt
Keep the receipt compact and forward its outcome lines without decoration:
-
COMMITTED <transaction-id> <commit-oid>proves commit creation or idempotent recovery. Without push authorization, it is completion. -
HOOK_ADDED <path>identifies content introduced by a hook outside the prepared path set. Disclose every such line. -
REBASED <branch> <count>discloses thatai-commitrebased the branch onto<count>upstream commits before the push. In the commit workflow, anINTEGRATEDline follows it. -
PUSHED <branch>orPUSHED_NEW <branch>proves propagation and completes push-authorized or push-only work. -
PUSHED <transaction-id> <commit-oid>is the retained proof returned when an already-pushed transaction is replayed. -
INTEGRATED <transaction-id> <head-oid>discloses that the branch no longer contains the transaction's original commit, but HEAD holds its content, for example after a rebase or an identical upstream commit. ThePUSHEDline that follows still completes the work. Cite the head OID as the pushed evidence, not theCOMMITTEDOID. -
SUPERSEDED <transaction-id> <commit-oid>is safe noncompletion: the branch contains neither the commit nor its content, and nothing was pushed. Inspect the branch. If the change is still needed, discard the transaction and prepare it again. -
BEHIND <branch> <count>is safe noncompletion, never completion:ai-commitfetched and refused to integrate or push. A precedingCOMMITTEDstill proves the local commit.Without
--rebase, replay the same transaction command with--push --rebase(or runai-commit push --rebasefor push-only work). With--rebase, the stderr line names why the upstream was not integrated. When another Git operation is in progress or the working tree or index is not clean, stop and report that branch reconciliation is required. When the rebase stopped and was aborted, report the conflicting paths and ask the user before resolving them. Never autostash, and never rebase by hand.
Do not report unrelated tree state, ahead/behind counts not emitted by the command, staging narration, or successful hook activity. Add only a required one-line bypass disclosure from the recovery reference.