Skip to content

Remind to show diff on gh pr/issue edit; let classifier handle gh issue edit - #311

Merged
ikuwow merged 2 commits into
mainfrom
gh-edit-diff-reminder
Jul 20, 2026
Merged

Remind to show diff on gh pr/issue edit; let classifier handle gh issue edit#311
ikuwow merged 2 commits into
mainfrom
gh-edit-diff-reminder

Conversation

@ikuwow

@ikuwow ikuwow commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Purpose

Two friction points around gh pr edit / gh issue edit:

  1. gh issue edit * was in permissions.ask, so every invocation stopped for a dialog even in auto mode.
  2. Neither command shows the caller what is being overwritten. --title / --body / --body-file silently replace the existing value, and a mistake was hard to catch until after the fact.

Key changes

  • claude/settings.json: drop "Bash(gh issue edit *)" from permissions.ask so the auto-mode classifier decides (gh pr edit * is already in allow and stays there); register a new PostToolUse hook on the Bash matcher that invokes remind_show_edit_diff.py
  • claude/hooks/remind_show_edit_diff.py (new): matched gh {pr,issue} edit calls with a title/body-overwrite flag get an additionalContext reminder to show the before/after diff. Matches are anchored to tokens[0:3] and stop scanning at the first shell operator (so ... && grep -F pat doesn't over-fire), and split on = so --title=NEW is caught. Match rules and kill switch in the module docstring.
  • claude/rules/git-essentials.md: add a slim ## PR / issue body edits section stating the pre-edit-diff expectation, pointing at the git-workflow skill's Update a PR / issue procedure

Design choice: kept the rule short (rule = mandate, skill procedure = how). Kept the hook stateless (fires every edit) since the diff reminder is cheap for the model and the failure mode of missing a diff is user-visible content loss. The reminder honestly notes that recovery only works when the prior value is still in context — re-fetching post-edit returns the new value.

Verification

  • python3 -m py_compile claude/hooks/remind_show_edit_diff.py — clean
  • python3 -m doctest claude/hooks/remind_show_edit_diff.py — 12 tests pass
  • Positive: gh pr edit 123 --body-file /tmp/x → fires
  • Positive: gh issue edit 5 --title "new title" → fires
  • Positive: gh pr edit 123 --title=NEW (=-form) → fires
  • Positive: gh pr edit 123 -t new (short flag) → fires
  • Negative: gh pr edit 123 --add-label foo (edit without overwrite flag) → no output
  • Negative: gh pr edit 123 --add-label foo && grep -F pat log (short flag in compound command) → no output
  • Negative: gh pr edit 123 --add-label foo | tee -a out (pipe) → no output
  • Negative: non-Bash tool call → no output
  • Negative: gh pr create --body-file /tmp/x (create, not edit) → no output
  • jq . claude/settings.json → valid JSON after the ask-list removal and the new PostToolUse block
  • End-to-end in a fresh session after ./scripts/deploy.sh: run an actual gh issue edit to confirm the classifier path (no ask dialog stall) and see the reminder land as additionalContext in the next turn

ikuwow and others added 2 commits July 20, 2026 21:57
gh pr edit / gh issue edit with --title, --body, or --body-file
silently replaces existing content, and a mistaken value is otherwise
easy to lose without a round-trip to git history. Add a PostToolUse
hook that reminds the agent to present the before/after diff whenever
such a command runs, and codify the same expectation in the
git-essentials rule, pointing at the existing procedure in the
git-workflow skill. Also drop the ask-permission entry for gh issue
edit so the classifier decides instead of always prompting.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Three review agents flagged: (1) MESSAGE told the model to re-fetch to
recover the prior value, but by PostToolUse the edit is already applied
and re-fetch returns the new body; (2) `--flag=value` tokens like
`--title=NEW` slipped past exact set-membership matching; (3) short
flags (`-t`, `-b`, `-F`) matched anywhere in compound commands like
`... && grep -F pat`.

- Anchor matcher to `tokens[0:3] == [gh, (pr|issue), edit]` and stop
  scanning at the first shell operator, so compound commands don't
  over-fire while short flags remain supported for the intended shape
- Split `=` before flag lookup so `--title=X` and friends match
- Rewrite MESSAGE: acknowledge recovery is only possible when the
  prior value is still in context; point at the git-workflow skill's
  `Update a PR / issue` procedure for future edits instead of framing
  it as retroactive
- Add `isinstance(tool_input, dict)` guard so schema drift fails open
  silently instead of raising AttributeError
- Rule bullet: drop the trailing rationale clause and switch the skill
  reference to the section name (numeric anchors drift when the skill
  is renumbered)
- Add doctests covering the `=`-form, short flags, compound commands,
  and the create-vs-edit boundary

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ikuwow
ikuwow marked this pull request as ready for review July 20, 2026 13:16
@ikuwow
ikuwow merged commit 91c4c98 into main Jul 20, 2026
6 checks passed
@ikuwow
ikuwow deleted the gh-edit-diff-reminder branch July 20, 2026 13:16
ikuwow added a commit that referenced this pull request Jul 20, 2026
…allowlist-187

Resolve claude/settings.json conflicts:
- deny: union of this branch push --delete/--mirror/colon-refspec and
  checkout -- denies with main force-with-lease denies
- ask: apply this branch removal of the git claw-back entries (they
  fall through to default ask), keep main gh api patterns, and do not
  restore gh issue edit which main removed in #311

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RGD2NDthkx859WNGeDKKBN
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.

1 participant