Skip to content

fix: merge-based hook installation preserves existing user hooks#203

Open
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:fix/hooks-schema-and-merge
Open

fix: merge-based hook installation preserves existing user hooks#203
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:fix/hooks-schema-and-merge

Conversation

@lngyeen
Copy link
Copy Markdown
Contributor

@lngyeen lngyeen commented Apr 10, 2026

Summary

install_hooks() now merges new entries into existing hooks instead of overwriting them via existing.update(). Creates a settings.json.bak backup before modification.

Motivation

The existing.update(hooks_config) call in install_hooks() replaces the entire hooks key, silently destroying user-defined hooks (e.g., linters, formatters, safety checks).

Note: The hook schema fix (invalid nested arrays, unsupported PreCommit event, Bash matcher) was already resolved upstream in PR #208. This PR's scope is narrowed to the merge logic, backup, and regression test only.

Closes #114

Changes

File Change
skills.py:install_hooks() Merge-based hook installation with backup
tests/test_skills.py Schema regression test + merge behavior test

Test plan

  • All skills tests pass
  • Full test suite passes with zero regressions
  • Verified hooks append correctly alongside existing user hooks

@tirth8205
Copy link
Copy Markdown
Owner

This PR addresses the hooks schema bug (#97, #114, #172, #188, #191, #201) which is still not fixed in main. The current skills.py:generate_hooks_config() still generates the invalid schema. This PR provides exactly what's needed: proper nested hooks arrays, removal of PreCommit/SessionStart (invalid events), narrowed PostToolUse matcher, and merge-based installation with backup. Worth reviving — this is the #1 most-reported bug in the issue tracker.

Two fixes for Claude Code hooks integration:

1. Hook schema: use proper Claude Code format with nested hooks array
   and remove unsupported PreCommit event. Narrow PostToolUse matcher
   from Edit|Write|Bash to Edit|Write since Bash commands do not
   directly modify source files. (cherry-picked from PR tirth8205#180)

2. Merge logic: install_hooks now merges new entries into existing
   hooks instead of overwriting them. Creates a backup of
   settings.json before modification. (based on PR tirth8205#145)

Closes tirth8205#97, tirth8205#114, tirth8205#172.
@lngyeen lngyeen force-pushed the fix/hooks-schema-and-merge branch from 13ddcba to cf756f4 Compare April 13, 2026 03:11
@lngyeen
Copy link
Copy Markdown
Contributor Author

lngyeen commented Apr 13, 2026

Rebased onto latest main — conflicts resolved, all 46 skill tests passing. The hook schema changes from #208 are now upstream, so this PR's scope is narrowed to the merge logic (append-don't-overwrite user hooks) + backup (settings.json.bak) + a detailed schema regression test. Ready for re-review.

@lngyeen lngyeen changed the title fix: valid Claude Code hook schema + merge existing hooks on install fix: merge-based hook installation preserves existing user hooks Apr 15, 2026
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.

code-review-graph install overwrites existing hooks for Claude

2 participants