chore: local shellcheck gate on edited shell scripts - #2
Open
Chikimuras wants to merge 1 commit into
Open
Conversation
Runs the same check the CI shellcheck job runs (-S warning -x, dotfiles/ excluded) on every shell script Claude writes or edits, so a lint failure surfaces at edit time rather than after a push. Exit 2 feeds shellcheck's diagnostic back into the session. No-ops on anything that is not a shell script, and on machines without shellcheck installed — it is a convenience, not a substitute for the CI job, which stays the gate that decides what merges. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The added hook command has a couple of correctness/robustness issues (dotfiles exclusion matching and missing jq presence guard) that can cause unexpected behavior during edits.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a Claude Code local hook configuration to run the same shellcheck invocation as CI whenever Claude writes/edits shell scripts, surfacing diagnostics immediately during editing (without changing CI behavior).
Changes:
- Introduces
.claude/settings.jsonwith aPostToolUsehook onWrite|Edit. - Runs
shellcheck -S warning -xon edited*.shscripts (with an intended exclusion fordotfiles/), and returns exit code2on failure.
File summaries
| File | Description |
|---|---|
.claude/settings.json |
Adds a Claude Code PostToolUse hook that runs shellcheck on edited shell scripts to catch issues at edit-time. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "jq -r \"(.tool_response.filePath // .tool_input.file_path) // empty\" | { read -r f || exit 0; case \"$f\" in */dotfiles/*) exit 0 ;; *.sh|*/bootstrap.sh) ;; *) exit 0 ;; esac; command -v shellcheck >/dev/null || exit 0; shellcheck -S warning -x \"$f\" >&2 || exit 2; }", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branche séparée de #1 : ce gate ne dépend d'aucun des correctifs qui s'y trouvent, et il ne touche pas la CI.
Ce que ça fait
Un hook
PostToolUsesurWrite|Editlance, sur chaque script shell que Claude écrit ou modifie, exactement le contrôle du job CIshellcheck:shellcheck -S warning -x,dotfiles/exclu. Un échec sort en code 2, ce qui renvoie le diagnostic dans la session — la faute se voit à l'édition, pas après un push.Le hook ne fait rien sur autre chose qu'un script shell, ni sur une machine sans shellcheck installé. C'est un confort, pas un substitut à la CI, qui reste le gate qui décide de ce qui se merge.
Vérification
Commande pipe-testée avec la charge stdin réelle du hook (
bash -cpour reproduire le process du harness), sur cinq cas :install/50-stow.sh(sain)README.md(non-shell)dotfiles/jira/.config/jira-cli/aliases.sh(exclu)bootstrap.sh(sans extension.sh)Puis re-testée après écriture, en relisant la commande depuis le JSON (
jq -r), pour vérifier que l'échappement du fichier n'a rien cassé.jq -esur le chemin.hooks.PostToolUse[].hooks[]: OK.Non vérifié : que le hook se déclenche réellement en session. Il ne peut pas l'être ici — la session courante a pour projet un autre dépôt, donc les settings de
forgen'y sont pas chargés. À la prochaine session ouverte dansforge,/hookspermet de le relire, l'éditer ou le désactiver.🤖 Generated with Claude Code