Skip to content

learning-opportunities-auto: make post-commit nudge more robust#9

Open
larssn wants to merge 1 commit into
DrCatHicks:mainfrom
larssn:fix/post-commit-hook-robustness
Open

learning-opportunities-auto: make post-commit nudge more robust#9
larssn wants to merge 1 commit into
DrCatHicks:mainfrom
larssn:fix/post-commit-hook-robustness

Conversation

@larssn
Copy link
Copy Markdown

@larssn larssn commented Apr 20, 2026

Three small changes to post-tool-use.sh. Trigger gate and nudge phrasing unchanged.

  • Fix counter. offers previously bumped on every hook fire, burning the 2/session cap even when no nudge landed. Now increments only on emit, de-duped per commit SHA.
  • Guard failed commits. If git commit was rejected, HEAD is the previous commit. Skip silently unless HEAD's timestamp is within ~30s.
  • Add commit context. Nudge prefixes (${SHA}: ${SUBJECT}) so the skill has a concrete topic. Subject sanitized + truncated for safe JSON embedding.

No new dependencies.

Happy to split into three commits if you'd prefer cherry-pickability.

Three small changes to `hooks/post-tool-use.sh`. Trigger gate and
nudge phrasing are unchanged.

- Fix offer counter: previously incremented on every hook fire, which
  silently burned the 2/session quota even when a nudge didn't land
  (e.g. on non-commit Bash calls whose command text matched the loose
  grep, or commits Claude decided not to act on). Now the counter
  increments only at the point a nudge is actually emitted, and is
  de-duped per commit SHA so a single commit can't consume multiple
  offers if the hook is invoked more than once for it.

- Guard against failed commits: if `git commit` was rejected (e.g. by
  a pre-commit hook), HEAD is still the previous commit. Checking HEAD's
  commit timestamp and exiting silently if it isn't very recent avoids
  nudging about stale work that wasn't actually just committed.

- Include short commit context in the nudge: add the short SHA and the
  commit subject to additionalContext so the skill has a concrete
  topic handle when asking the user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants