Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/cad0p/pi-steering-hooks/llms.txt

Use this file to discover all available pages before exploring further.

git commit --amend rewrites the last commit’s SHA. That is occasionally useful in a solo workflow, but it creates real problems in review-driven environments: reviewers tracking diffs across pushes lose the SHA anchor for per-line comments, git bisect and git blame results become harder to read, and the amended commit presents as a brand-new revision with no continuity to the previous one. The no-amend rule pack blocks --amend globally so the agent never uses it as a reflexive “clean up the last commit” shortcut. If you need to fix the content or message of the last commit, the clean alternative is a follow-up commit — git commit -m "fix: ..." — and a squash-merge at the end of review to collapse the chain.

Configuration

import { defineConfig } from "pi-steering";

export default defineConfig({
  rules: [
    {
      name: "no-amend",
      tool: "bash",
      field: "command",
      // Mirrors the pre-subcommand flag slot used by
      // DEFAULT_RULES.no-force-push so `git -C /path commit --amend`,
      // `git -c key=val commit --amend`, and
      // `git --git-dir=/x commit --amend` are all caught.
      pattern:
        "^git\\b(?:\\s+-{1,2}[A-Za-z]\\S*(?:\\s+\\S+)?)*\\s+commit\\b.*--amend\\b",
      reason:
        "Don't rewrite history with --amend. Create a new commit instead. If you need to fix the last commit's message, do it in a follow-up commit — PR reviewers track diffs across pushes and amend confuses that.",
    },
  ],
});
This rule is purely additive — it does not conflict with any of pi-steering’s shipped DEFAULT_RULES.

The pre-subcommand flag slot

The pattern ^git\b(?:\s+-{1,2}[A-Za-z]\S*(?:\s+\S+)?)*\s+commit\b handles git flags that appear before the subcommand:
  • git -C /path commit --amend — changes the working directory before running commit
  • git -c key=val commit --amend — sets a config value for this invocation
  • git --git-dir=/x commit --amend — overrides the repository path
The AST backend’s wrapper detection handles sh -c 'git commit --amend' and sudo git commit --amend at the extraction layer, so the regex itself does not need to encode those forms.

cwd-scoped variant

Some teams want to apply the rule selectively — for example, a monorepo where some sub-projects enforce linear history and others are more permissive. The when.cwd clause makes the rule apply only when the effective working directory of the extracted command matches a given pattern.
{
  "rules": [
    {
      "name": "no-amend-in-personal",
      "tool": "bash",
      "field": "command",
      "pattern": "^git\\b(?:\\s+-{1,2}[A-Za-z]\\S*(?:\\s+\\S+)?)*\\s+commit\\b.*--amend\\b",
      "when": { "cwd": "^/home/[^/]+/projects/personal/" },
      "reason": "In personal/shared repos, don't rewrite history. Create a new commit instead."
    }
  ]
}
The key property of when.cwd is that it tests against the effective cwd of each extracted command, not the session’s working directory. A command like cd /home/me/projects/personal/site && git commit --amend, run from a completely different session directory, is still caught because the AST walker resolves the cd before evaluating the cwd predicate. In TypeScript form, the same clause is:
when: { cwd: "^/home/[^/]+/projects/personal/" },
To adapt this for a monorepo, replace the regex with the prefix path of the subtrees that should enforce linear history.

Adversarial matrix

CommandResult
git commit --amend🚫 blocked
git commit --amend -m "fix"🚫 blocked
git -C /path commit --amend🚫 blocked
git -c user.email=x commit --amend🚫 blocked
sh -c 'git commit --amend'🚫 blocked
git commit -m "fix: typo"✅ allowed
git commit --no-edit✅ allowed
echo 'git commit --amend'✅ allowed

Install

cp examples/no-amend/steering.ts .pi/steering/index.ts
For the cwd-scoped variant, copy the steering.ts and add a when.cwd clause inline on the rule. The JSON form (steering.cwd-scoped.json) is provided as a migration reference and can be converted with:
pi-steering import-json examples/no-amend/steering.cwd-scoped.json -o .pi/steering/index.ts

Build docs developers (and LLMs) love