← All resources

Agent skill

Automated Version Control

Use when the user signals end-of-task and a non-clean working tree exists — explicit verbs ("commit", "push", "save", "snapshot", "back this up", "ship it") or completion phrases ("done", "looks good") after a round of edits with files modified. Inspects what changed, infers the repo's commit-message style from recent history (informal lowercase by default; conventional commits if the repo already uses them), runs project-specific build hooks (e.g., the CV rebuild when `code/cv.tex` is staged), commits, and pushes to the current branch. Honors the git-safety rules from the system prompt: never `git add -A`, never `--no-verify`, never `--amend` after a hook failure, never force-push to `main`.


Automated Version Control

Committing well is a separate cognitive task from the work itself. By the time you finish editing a paper section or a script, you no longer want to think about which files belong in which commit, what the message should say, or whether the CV PDF still matches cv.tex. This skill offloads that.

It commits and pushes. It does not open PRs — this repo’s workflow is solo on main. For collaborative repos with a PR convention, invoke gh pr create separately after the skill finishes.


Movement 1 — When to fire

Fire when all of the following hold:

Do not fire when:

If a fire condition is ambiguous, ask one question: “Commit current changes? <one-line summary of what's staged + unstaged>“. Don’t ask repeatedly across the same session — once is enough.


Movement 2 — Snapshot the state

Run in parallel:

git status --short
git diff --stat
git log -10 --oneline

From these, decide:

Never assume conventional-commit format unless the recent log already uses it.


Movement 3 — Project-specific build hooks

CV rebuild (this repo)

If code/cv.tex is in the diff, the website’s docs/assets/cv.pdf must be regenerated before the commit, or the source and the published PDF will drift.

TINYTEX="/c/Users/kaizhu/AppData/Roaming/TinyTeX/bin/windows"
cd code
PATH="$TINYTEX:/c/Windows/System32" "$TINYTEX/pdflatex.exe" \
  -interaction=nonstopmode \
  -output-directory="../output" \
  "\def\hideabstracts{}\input{cv.tex}"
cd ..
cp output/cv.pdf docs/assets/cv.pdf

(Short version — no abstracts — because that is what the website ships.)

If pdflatex returns non-zero, stop. Print the last ~30 lines of the log and ask the user to resolve. Do not commit a stale or partial PDF.

If code/cv.tex is not staged but docs/assets/cv.pdf is — that is suspicious, because the PDF is built from source. Warn before committing: “Committing cv.pdf without cv.tex change — did you mean to?”

Other repos

Read the project’s CLAUDE.md for build commands. If it documents a pre-commit build (e.g., Quarto render, LaTeX compile, figure regeneration tied to a script change), run it in the same way: detect the trigger file, run the build, fail closed on errors.


Movement 4 — Group and stage

Stage by topic, not by file count. If the diff cuts across two unrelated topics (e.g., a CV update and a skill edit), make two commits — one per topic.

Never use git add -A or git add .. Sensitive files (.env, credentials, large binaries) sneak in that way. Stage by explicit path:

git add code/cv.tex docs/assets/cv.pdf

If git status shows files you do not recognize (unexpected untracked files, configuration overrides, build artifacts), investigate before staging. Do not silently include them.


Movement 5 — Draft the message

The subject line carries the meaning. Body text is rare — only when the why is non-obvious from the diff.

Subject — match the repo’s pattern, with these defaults for this user’s repos:

Body — only include when:

Trailers:

Forbidden subject patterns — these waste the line:


Movement 6 — Commit and push

git commit -m "<subject>"
git push

If a pre-commit hook fails:

  1. Read the hook’s output.
  2. Fix the underlying issue (lint error, type error, formatting).
  3. Re-stage and make a new commit — do not --amend. After a hook failure the original commit did not happen, so --amend would silently modify the previous commit (potentially someone else’s, or your own earlier work) and destroy history.

If the push is rejected (non-fast-forward):


Movement 7 — Output

Print three lines and stop:

✓ <new HEAD short SHA> — "<subject>"
  files: <comma-separated list, truncated to ~6 items + "and N more">
  push:  <ok | failed: reason>

(If the user dislikes the checkmark glyph, drop it — match their preference, no emoji elsewhere.)

Do not produce a multi-paragraph summary of what was committed. The diff is on disk; the user can read it.


Cross-references