Cursor agent rules¶
Guidelines that constrain the Cursor editor agent into making atomic, sane git commits. Drop these into Cursor's rules to stop the agent from batching unrelated changes or skipping pre-commit hooks.
Atomic Git Commits¶
Git commits created by the agent must be atomic — one commit equals one complete, verified, logical change. If any step fails, nothing gets committed.
Before Committing¶
- Run
git statusandgit diff --stagedto review exactly what will be committed. - Verify every staged file is relevant to the current task. Never include unrelated changes.
- Run the project's lint, compile, or build step (e.g.,
mvn compile,npm run lint,tsc --noEmit) to confirm the change doesn't break the codebase. If it fails, fix first, then commit. - Never stage or commit files that likely contain secrets:
.env,credentials.json,**/secrets/**,*.pem,*.key. Warn the user if they specifically ask to commit those files.
Commit Rules¶
- One logical change per commit. Don't bundle unrelated fixes, refactors, or features.
- Write the commit message as a concise summary of why, not what. Use past tense or imperative mood consistently with the repo's existing style. Check
git log --oneline -10to match conventions. - For multi-line commit messages, use
git commit -m "line 1" -m "line 2"(multiple-mflags). This works in all shells — PowerShell, bash, and cmd. Example:git commit -m "feat: add user validation" -m "Validate email format and check for duplicates before saving." - For single-line messages, a simple
git commit -m "message"is fine. - Never use HEREDOC syntax (
<<'EOF') — it is not supported in PowerShell. - Never commit with
--allow-empty,--no-verify, or--no-gpg-signunless the user explicitly asks.
After a Failed Commit¶
If the commit fails (pre-commit hook rejection, merge conflict, etc.):
- Fix the root cause.
- Create a new commit. Never
git commit --amendon a failed commit.
Amend Restrictions¶
Only use --amend when all of these are true:
- The user explicitly requested an amend, or the commit succeeded but a pre-commit hook auto-modified files that need including.
- The HEAD commit was created by the agent in this conversation (verify with
git log -1 --format='%an %ae'). - The commit has not been pushed to remote (verify:
git statusshows "Your branch is ahead").
If any condition is false, create a new commit instead.
Forbidden Operations (always ask the user)¶
git add .orgit add -A(stages everything blindly — stage specific files instead)git commitwithout reviewinggit diff --stagedfirstgit push(never push unless the user explicitly asks)git push --forceorgit push --force-with-lease(warn if targeting main/master)git reset --hardgit rebase -i(requires interactive input)git stash droporgit stash clear- Any git config changes