Skip to content

refactor: unified protect lifecycle via registry, consolidate hookutil#137

Merged
cyyever merged 1 commit intomainfrom
fix/cleanup-hooks-on-stop
Mar 23, 2026
Merged

refactor: unified protect lifecycle via registry, consolidate hookutil#137
cyyever merged 1 commit intomainfrom
fix/cleanup-hooks-on-stop

Conversation

@cyyever
Copy link
Collaborator

@cyyever cyyever commented Mar 23, 2026

Summary

All protection mechanisms now use a single lifecycle path via the agent registry, ensuring complete cleanup on every exit path.

Before

After

  • Claude Code hooks registered as a FuncTarget in registry/builtin.go
  • protect.UninstallAll() = registry.Default.RestoreAll() β€” one call covers everything
  • HookInstaller interface, InstallHooks, claudeHookInstaller removed
  • Adding a new agent only requires one registration in builtin.go

Architecture

registry.Default.RestoreAll()
  β”œβ”€β”€ HTTPAgent "OpenClaw"          β†’ restore baseUrl
  β”œβ”€β”€ FuncTarget "Claude Desktop"   β†’ restore MCP config
  β”œβ”€β”€ FuncTarget "Cursor"           β†’ restore MCP config
  β”œβ”€β”€ FuncTarget "Windsurf"         β†’ restore MCP config
  β”œβ”€β”€ FuncTarget "Claude Code"      β†’ restore MCP config
  β”œβ”€β”€ FuncTarget "Neovim"           β†’ restore MCP config
  └── FuncTarget "Claude Code (hooks)" β†’ hookutil.Uninstall()

Called by: protect.Stop(), daemon.stopCleanup(), CleanupPID() (unix/windows)

hookutil consolidation

Shared by CLI and GUI β€” moved from scattered locations:

Function Was in Now in
Install/Uninstall pkg/libcrust/hooks.go internal/hookutil
FormatResponse pkg/libcrust/hook.go internal/hookutil
IsInstalled internal/agentdetect/detect.go internal/hookutil
CleanupStaleFile pkg/libcrust/hooks.go internal/hookutil

Platform test fixes

  • FreeBSD: skip TestWriteFileWithLock_ReadOnlyDir when root
  • Windows MSYS2: use pathutil.ToSlash in TestAudit_GitConfigBypass

Test plan

  • go test ./... β€” zero failures
  • All pre-commit hooks pass (golangci-lint, nilaway, govulncheck)
  • hookutil tests β€” FormatResponse block/allow/invalid/empty

@cyyever cyyever force-pushed the fix/cleanup-hooks-on-stop branch 8 times, most recently from ed89a0a to e9f12e2 Compare March 23, 2026 14:37
@cyyever cyyever changed the title fix: clean up Claude Code hooks on SIGKILL recovery refactor: unified protect lifecycle with hookutil, UninstallAll, and platform test fixes Mar 23, 2026
@cyyever cyyever force-pushed the fix/cleanup-hooks-on-stop branch 2 times, most recently from 4a4dec5 to 8560ad3 Compare March 23, 2026 15:18
Register Claude Code hooks as a registry target so all protection
mechanisms (HTTP proxy, MCP wrapping, hooks) use the same PatchAll/
RestoreAll lifecycle. Remove HookInstaller interface and InstallHooks
config β€” hooks are now managed alongside other agents.

- Add "Claude Code (hooks)" FuncTarget in registry/builtin.go
- protect.UninstallAll() β†’ registry.Default.RestoreAll() (single call)
- Remove HookInstaller, claudeHookInstaller, InstallHooks from Config
- Simplify EnableAgent/DisableAgent (no special hook handling)
- Consolidate hookutil: Install/Uninstall/FormatResponse/IsInstalled/
  CleanupStaleFile shared by daemon + libcrust
- Fix FreeBSD test (skip root), Windows MSYS2 test (pathutil.ToSlash)
- Update lifecycle docs in how-it-works.md and protect.go
@cyyever cyyever force-pushed the fix/cleanup-hooks-on-stop branch from 8560ad3 to 5f0ee26 Compare March 23, 2026 15:20
@cyyever cyyever changed the title refactor: unified protect lifecycle with hookutil, UninstallAll, and platform test fixes refactor: unified protect lifecycle via registry, consolidate hookutil Mar 23, 2026
@cyyever cyyever merged commit 8b92c7c into main Mar 23, 2026
16 checks passed
@cyyever cyyever deleted the fix/cleanup-hooks-on-stop branch March 23, 2026 15:43
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