feat(cli): update install-hook to add SessionEnd analysis hook#250
feat(cli): update install-hook to add SessionEnd analysis hook#250
Conversation
Adds SessionEnd hook for zero-config native session analysis (Issue #241). Default install now installs both Stop (sync) and SessionEnd (analysis) hooks. New --sync-only / --analysis-only flags for granular control. Uninstall-hook now cleans both hook types. Telemetry tracks installed types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TA Review (Phase 1 - Insider): feat(cli): update install-hook to add SessionEnd analysis hook — Round 1Data Contract Impact
Test Coverage (TDD Domain Verification)
Pattern Consistency
Architecture Alignment
Issues Found🔴 FIX NOW:
🟡 SUGGESTION:
🔵 NOTE:
Phase 1 Verdict
One FIX NOW item: Add mutual exclusivity guard for |
TA Synthesis (Phase 2): feat(cli): update install-hook to add SessionEnd analysis hook — Round 1Consolidated Review (For Dev Agent)FIX NOW:
SUGGESTIONS (non-blocking, not required for this PR):
NOT APPLICABLE:
Final VerdictChanges Required — One FIX NOW item. Once the mutual exclusion guard is added, this PR is ready. |
Passing both flags together previously resolved to neither hook being installed with misleading output. Now exits early with a clear error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review AddressalFIX NOW items addressed:
Pre-PR gate: All review items addressed. Ready for re-review or merge. |
Triple-Layer Code Review — Round 1Reviewers
Pre-Review Gates
Issues Found & Resolution🔴 FIX NOW (resolved)
🟡 SUGGESTIONS (non-blocking, pre-existing)
Round 1 verdict: PASS — Ready for merge |
…o test - Remove per-hook "already installed" prints; single consolidated message shows which hooks were already present (e.g. "sync + analysis") - Add console.log spy to mutual exclusion test to guard against silent removal of the error message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review Addressal (Round 2)Items addressed:
Pre-PR gate: |
…p homedir - Replace process.argv[1] with import.meta.url-based path resolution so hook commands written to settings.json are stable across npm link, global install, and npx (where argv[1] points to a changing cache path) - Rewrite test setup to mock os.homedir() via vi.mock with a mutable sentinel object (avoids ESM hoisting issue with let declarations); each test gets an isolated temp dir — real ~/.claude/settings.json is never touched Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review Addressal (Round 3)Items addressed:
Pre-PR gate: |
What
Updates
install-hookto install both aStop(sync) hook and aSessionEnd(analysis) hook by default. Adds--sync-onlyand--analysis-onlyflags for granular control. Updatesuninstall-hookto remove both hook types.Closes #241.
Why
The
insightscommand (Issue #240) can now analyze sessions viaclaude -pwith no API key. To make this automatic, users need aSessionEndhook that firescode-insights insights --hook --native -qwhen a session ends. Without this PR, users must manually run analysis.How
installHookCommand()now acceptsInstallHookOptions({ syncOnly?, analysisOnly? })StopandSessionEndentries to~/.claude/settings.jsonSessionEndhook hastimeout: 120000(2 minutes — analysis can take ~15-30s)uninstallHookCommand()filters bothStopandSessionEndarrayshook_types,sync_installed,analysis_installedHook Event Verification
SessionEndis a valid Claude Code hook event, confirmed via Context7 docs against the officialanthropics/claude-coderepo. Full event list:PreToolUse,PostToolUse,Stop,SubagentStop,SessionStart,SessionEnd,UserPromptSubmit,PreCompact,Notification. No fallback toStopwas needed.Schema Impact
InstallHookOptionsinterface is internal to install-hook.ts)Stophooks are preservedTesting
cli/src/commands/__tests__/install-hook.test.tspnpm buildpasses from repo rootTest plan
--sync-onlyinstalls only Stop hook--analysis-onlyinstalls only SessionEnd hookuninstall-hookremoves both hook typesuninstall-hookpreserves non-code-insights hooks in both arraysuninstall-hookcleans up empty hooks objecttimeout: 120000