Skip to content

fix(bash-format,ruff-format): skip formatting files that drifted before the edit - #6677

Merged
kyle-sexton merged 1 commit into
mainfrom
fix/format-hooks-honor-repo-config
Oct 9, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
fix/format-hooks-honor-repo-config

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: workplan item W2 (format-on-edit hooks producing whole-file churn).

Summary

bash-format and ruff-format rewrote whole files on small edits, for example re-indenting every case arm in a file after switch_case_indent = true reached this repo's .editorconfig (797 tracked shell files are not shfmt-clean under it today). The hooks were already reading the repo's config. The churn came from files that had drifted from that config before the edit.

Fix

  • Each hook now reads the pre-edit bytes from the Write/Edit tool_response.originalFile and checks them with the same tool and config: shfmt -d --filename <file> for bash-format; ruff check --diff and ruff format --check with --stdin-filename for ruff-format.
  • A mutating pass runs only when the file was already clean for that pass. A file that drifted keeps its layout, and the linters still report.
  • A new file (originalFile: null), or a payload without the field, is formatted as before.
  • README notes and changelog fragments are included for both plugins.

Verification

  • New tests: bash-format.test.sh (drifted file left byte-identical with no disclosure, clean file's edit formatted, new file formatted) and ruff-format.test.sh (format drift left, pending safe fixes not applied, clean file's edit formatted). With the hook changes stashed, the drift cases fail (2 per suite).
  • scripts/affected-tests.sh --run: both suites pass (bash-format 116/0, ruff-format 77/0).
  • shellcheck, markdownlint, validate-plugins.sh, check-changelog-fragments.sh --check, check-changed-skills.sh origin/main, and check-killswitch-hoist.sh all pass.

Related

  • Other formatter plugins (biome-format, go-format, powershell-format) were not changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VxGrZW26Qs1qeo3RFgmbvp

…re the edit

The format hooks already honor the repo's .editorconfig and Ruff config; the
churn came from files that were not clean under that config before the edit
(for example, flush-left case arms after switch_case_indent = true was synced
in), so any edit reformatted every drifted line.

Each hook now checks the pre-edit bytes (tool_response.originalFile) with the
same tool and config, and runs a mutating pass only when the file was already
clean for it. A new file, or a payload without the field, formats as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VxGrZW26Qs1qeo3RFgmbvp
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 9, 2026 16:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T16:38:18.146106Z 41092b0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 7m 7s —— View job


Code review in progress

  • Gather context (diff, CLAUDE.md/REVIEW.md, changed files)
  • Review bash-format.sh changes
  • Review bash-format.test.sh changes
  • Review ruff-format.sh changes
  • Review ruff-format.test.sh changes
  • Review README/changelog fragments
  • Adversarial validation of candidate findings (verifier running)
  • Post findings and final summary

Docs and changelog fragments match the code change; no issues there. Waiting on independent verification of one candidate finding about the new drift gate before reporting.

@claude

claude Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 16s —— View job


Security review — /review:security-review

  • Gather context (PR diff, changed files, custom instructions)
  • Invoke /review:security-review for this PR
  • Post findings

Scope: plugins/bash-format/hooks/bash-format.sh, plugins/ruff-format/hooks/ruff-format.sh, their test files, READMEs, and changelog fragments (diff: origin/main...HEAD, head 41092b0).

Findings: none.

What the change does: both hooks now read the pre-edit bytes from tool_response.originalFile via a jq filter ((.tool_response | objects | .originalFile | strings | "1" + . + ".") // "0"), and gate the mutating format pass on that content already being clean under the same formatter/config (shfmt -d --filename / ruff check --diff + ruff format --check). I checked this for the obvious classes a security review should catch here:

  • Injection via file content: the pre-edit bytes are only ever piped to the formatter over stdin (printf '%s' "$PRE_EDIT" | ... "$RUFF_BIN" ... - in ruff-format.sh#L205-L207, and shfmt -d --filename "$TOOL_FILE" in bash-format.sh#L250-L264). It is never interpolated into a command line, eval'd, or used to build a path — no command-injection surface.
  • Gate direction: both changes only make the mutating pass more restrictive (it now requires the pre-edit content to already pass the same check), never less. The jq-failure/null-original fallback path (return 0 / PRE_EDIT_KNOWN=0) reproduces the pre-PR behavior (format unconditionally) rather than introducing a new always-on or always-off bypass.
  • Trust boundary: tool_response.originalFile comes from Claude Code's own PostToolUse payload for the file already being edited — same trust level as $FILE/$TOOL_FILE content these hooks already read elsewhere (e.g. the existing subscript guard in bash-format.sh), not a new untrusted input class.
  • Flags unchanged: RUFF_FIX=(--no-unsafe-fixes --unfixable F401) in ruff-format.sh#L187 factors out exactly the flags the fix pass already used; no fix/format behavior widened.
  • No secrets, tokens, or credentials are touched; no authz/access-control surface in these hooks; no GitHub Actions workflow files changed.
  • Instruction-surface check: no CLAUDE.md/AGENTS.md/rules file/hook allowlist or block list is deleted, narrowed, or softened by this diff — it only adds a new internal gating function to two formatter hooks, so the instruction-exception-register lens doesn't apply here.

Nothing rises to CRITICAL/IMPORTANT/SUGGESTION severity. This is an advisory formatting hook with no injection path, no privilege boundary, and no instruction-surface change — I have no security findings to raise.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

claude-security-review has reviewed this pull request through 41092b0; a later push is reviewed from there.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

claude-review has reviewed this pull request through 41092b0; a later push is reviewed from there.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit ca24971 Oct 9, 2026
32 of 42 checks passed
@kyle-sexton
kyle-sexton deleted the fix/format-hooks-honor-repo-config branch October 9, 2026 17:48
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