Add a history-tidying rule and tooling for agents#284
Merged
Conversation
This packages, for Claude Code, the mechanics of tidying a branch's history before a pull request. history-hygiene.sh reuses the repository's single commit linter (tools/commit-lint/lint-commit-message.sh), so it never disagrees with the commit-msg hook or the CI gate about a conforming header. It only reads and reminds — blocking pull-request creation on CI-fatal history and nudging after a committing or pushing git command — and never rewrites anything. The /tidy-history command runs the assess, propose and (after an explicit go-ahead) rewrite procedure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01197kHcdbAr9Q547gef8Cpy
This repository merges pull requests with a merge commit, so every commit a branch carries reaches main's protected history — a messy branch is not squashed away on merge. Nothing prompted an agent to tidy up before opening or updating a pull request; the new AGENTS.md section does, and CLAUDE.md inlines the essentials. The rule: read origin/main..HEAD, propose a cleanup when the history is messy, and rewrite only while the branch is yours alone and only after a go-ahead — the endpoint the maintainer approves, never the agent's to force. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01197kHcdbAr9Q547gef8Cpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This repository merges pull requests with a merge commit, so every commit a
branch carries lands in
main's history — a messy branch is not squashed awayon merge. This PR makes an agent tidy a branch's history on its own initiative
before a pull request: it adds the rule to
AGENTS.md(essentials inlined inCLAUDE.md) and the Claude Code mechanics that carry it out. The rule isadvisory and the rewrite always waits for an explicit go-ahead — no agent
rewrites a branch's endpoint any more than it merges one.
Type of change
Changes
AGENTS.md— new section "Tidying history before a pull request (actingagent)": read
origin/main..HEADbefore opening a PR and after pushing morecommits to an open one; propose a cleanup when the history is messy (pending
fixup!/squash!, non-conforming headers, wip/typo/review-fix commits, onechange split across non-standalone commits or two folded into one); rewrite
only while the branch is yours alone, after an explicit go-ahead, with
git push --force-with-lease, leaving the diff againstorigin/mainunchanged.
CLAUDE.md— the same rule inlined as one essentials bullet, linking theAGENTS.mdsection and the/tidy-historycommand..claude/commands/tidy-history.md— a/tidy-historyslash command packagingthe assess → propose → (on approval) rewrite → verify → publish procedure.
.claude/hooks/history-hygiene.sh+.claude/settings.json— a hook thatreuses the repository's own commit linter
(
tools/commit-lint/lint-commit-message.sh), so it never disagrees with thecommit-msghook or the CI gate. It blocks pull-request creation on CI-fatalhistory (
fixup!/squash!placeholders, headers the lint rejects) and printsan advisory reminder after a committing or pushing git command. It only reads
and reminds; it never rewrites anything.
Testing
No .NET production code is touched (only
.claude/tooling and repository docs),so the solution build and test suite are not exercised by this change:
dotnet build FirstClassErrors.sln— not run (no .NET code changed)dotnet test FirstClassErrors.sln— not run (no .NET code changed)FirstClassErrors.Analyzers.UnitTests) — not run (no analyzer changed)Run instead:
sh -non the hook (syntax) and functional runs in a throwaway git repo — ona messy branch
pre-prblocks and lists the CI-fatal commits andpost-commitreminds; on a clean branch and one even withmain, both aresilent (exit 0). The hook's
pre-prcheck also passes on this very branch.(
tools/commit-lint/lint-commit-message.sh --ci -).Documentation
This PR is a documentation + tooling change.
AGENTS.mdandCLAUDE.mdcarrythe rule; no public API,
README,doc/, or user-facing library behaviorchanges, so the French translation needs no sync.
doc/updated — n/adoc/handwritten/for-users/README.fr.md) updated — n/a (no user-facing behavior change)AGENTS.md/CLAUDE.md)Architecture decisions
Checked against the ADR base. This PR adds an agent/contributor process
convention and its tooling — not a public API contract, a cross-cutting code
invariant, a supported-platform floor, or a dependency/security policy — so I
judge it embarks no architectural decision. Flagging for the maintainer to
overrule if the agent-governance rule is considered ADR-worthy.
Related issues
None — this originated from a maintainer request, not a tracked issue.
🤖 Generated with Claude Code
https://claude.ai/code/session_01197kHcdbAr9Q547gef8Cpy
Generated by Claude Code