Skip to content

feat(install): check for node availability and back up settings.json#58

Closed
jccidc wants to merge 1 commit intoJuliusBrussee:mainfrom
jccidc:feat/install-sh-safety
Closed

feat(install): check for node availability and back up settings.json#58
jccidc wants to merge 1 commit intoJuliusBrussee:mainfrom
jccidc:feat/install-sh-safety

Conversation

@jccidc
Copy link
Copy Markdown
Contributor

@jccidc jccidc commented Apr 9, 2026

Two small safety improvements to hooks/install.sh. Both purely additive — no behavior change on the happy path, only on failure modes.

1. Fail fast if node is missing

The script uses node -e to merge the hook config into ~/.claude/settings.json, but doesn't check that node is on PATH first. Claude Code itself ships node, but users running install.sh via curl pipe on a fresh machine (before installing Claude Code) hit a cryptic error from inside the heredoc.

Adds a command -v node check at the top with a helpful message:

if ! command -v node >/dev/null 2>&1; then
  echo "ERROR: 'node' is required to install the caveman hooks (used to merge"
  echo "       the hook config into ~/.claude/settings.json safely)."
  echo "       Install Node.js from https://nodejs.org and re-run this script."
  exit 1
fi

2. Back up settings.json before the node merge

The script now copies $SETTINGS to $SETTINGS.bak before running the node rewrite. If the merge fails mid-write (disk full, interrupted script, node crash, power loss), the user can recover their config from the backup instead of losing it.

cp "$SETTINGS" "$SETTINGS.bak"

This matters more now that the script wires up two hook entries (SessionStart + UserPromptSubmit) in a single node -e write. More state at risk per transaction.

Scope

  • 1 file changed: hooks/install.sh
  • +13 lines, -0 lines
  • Syntax-checked with bash -n
  • No new dependencies, no new flags, no new behavior on the happy path

Second PR in a small batch today. Independent of the others — can be merged in any order. Close if it doesn't fit your vision. 🪨

Two small safety improvements to hooks/install.sh:

1. Fail fast if node is missing. The script uses 'node -e' to merge
   the hook config into ~/.claude/settings.json, but does not check
   that node is on PATH before running. If the user doesn't have
   node installed (Claude Code ships it, but users running
   install.sh via curl pipe on a fresh machine may not), the script
   currently fails with a cryptic error from inside the heredoc.
   Add a 'command -v node' check at the top with a helpful message
   pointing to nodejs.org.

2. Back up settings.json before the node merge. The script now
   copies $SETTINGS to $SETTINGS.bak before running the node
   rewrite. If the merge fails mid-write (disk full, interrupted
   script, node crash), the user's config can be recovered from
   the backup instead of being lost. This is especially important
   now that the script wires up two hook entries (SessionStart +
   UserPromptSubmit) — more state at risk in a single write.

Both changes are purely additive — no behavior change on the happy
path, only on failure modes.

Verified syntax with 'bash -n'.
jccidc added a commit to jccidc/caveman-harness that referenced this pull request Apr 9, 2026
@JuliusBrussee JuliusBrussee requested a review from Copilot April 9, 2026 20:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds safety checks to the hook installer script to improve failure-mode UX when installing Claude Code “caveman” hooks.

Changes:

  • Fail fast with a clear message when node is not available on PATH.
  • Back up ~/.claude/settings.json to settings.json.bak before performing the Node-based merge.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hooks/install.sh
Comment on lines +9 to +13
if ! command -v node >/dev/null 2>&1; then
echo "ERROR: 'node' is required to install the caveman hooks (used to merge"
echo " the hook config into ~/.claude/settings.json safely)."
echo " Install Node.js from https://nodejs.org and re-run this script."
exit 1
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error messages are printed to stdout; for CLI scripts it’s better to send errors to stderr (e.g., echo ... >&2) so callers can separate normal output from failures when piping/redirecting.

Copilot uses AI. Check for mistakes.
@JuliusBrussee
Copy link
Copy Markdown
Owner

Implemented in latest release! Thanks for raising the issue.

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.

3 participants