fix(agent-setup): load Claude hooks for exported config directories

Closed
VI
8d ago
+173-3

Withdrawn to avoid overlapping an earlier contributor claim. The tested implementation and evidence remain available on this branch.

What & why

Fixes #9724.

A CLAUDE_CONFIG_DIR exported outside the Usage tab never receives Paradev's lifecycle hooks. The wrapper still reports Attached, but Claude's completed turn never reports Stop, so the agent remains starting and agents wait cannot settle.

Generate a hooks-only settings file under Paradev's own hooks directory from the existing Claude hook specification, and prepend --settings <file> in managed terminal launches. The selected profile's settings are not rewritten or provisioned from the default account. A caller-supplied --settings remains later in the argument list and takes precedence. Disabling the Claude integration removes the generated file; a missing file leaves the wrapper usable.

#5875 was closed in favor of Usage-account provisioning in #6585. This addresses the manually exported directory case reported in #9724, which that provisioning path does not reach.

Claude documents that identical handlers in multiple settings files run once (hooks reference). I also checked that behavior with the real CLI before using this approach.

How I tested it

  • Regression test executes the generated Bash wrapper against an isolated fake Claude binary. Before the fix its arguments begin with -p; after the fix they begin with the hooks-only --settings file. The alternate profile's settings stay byte-for-byte unchanged.
  • bun test src/claude-wrapper.test.ts src/agent-wrappers.test.ts: 101 pass, 0 fail. Includes paths with spaces, both explicit-settings forms, prompt text after --, launches outside Paradev, missing generated settings, and teardown.
  • bun run lint:fix, then bun run lint: pass, 13,602 files.
  • bun run typecheck: 42/42 tasks pass.
  • TERM=xterm-256color bun run test --continue=always: 27/30 tasks pass. Desktop: 9,651 pass, 0 fail; host-service: 2,913 pass, 0 fail; agent-setup: 479 pass, 2 existing shell-wrapper failures. Shared has the known macOS date-format failure (#9658); workspace-fs has two watcher timing failures. These failures are in unchanged tests and the affected packages were already failing in the preceding baseline runs. No CI changes are included.

Real CLI and dev-app verification

Used Claude Code 2.1.236 with a local fake Messages API returning PONG, not paid model inference. Native hook execution, the generated Paradev wrapper, notification delivery, and the host's agent state are real. Stream-JSON input stays open after the reply, so this checks an agent that is still running.

In the isolated dev app (http://localhost:3045/, CDP 9239), the original runtime stays starting / Attached four minutes after PONG. With the fix, the same exported profile and prompt produce idle / Stop, and agents wait --until settled succeeds. The profile settings hash is identical before and after, and both API requests use its configured Haiku model.

A separate real-CLI probe loads the same hooks from both the profile and the overlay: SessionStart, UserPromptSubmit, Stop, and SessionEnd each run once. It also confirms that an explicit later --settings takes priority.

Before: completed reply, still startingAfter: turn completion reaches Paradev
Before: starting and AttachedAfter: idle and Stop

Captured states, profile hashes, and native-CLI probe results.

The local dev database used PostgreSQL 18 and the Bun SQL migration driver for the existing setup issues; these environment workarounds are outside the patch. Implementation, diff inspection, tests, and UI automation were performed with Codex. No human review or manual testing is claimed.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs
  • I have signed the CLA (confirmed on #9744 and #9771)

Summary by cubic

Fixes agents that stay stuck in starting when a CLAUDE_CONFIG_DIR is exported outside the Usage tab: the wrapper now loads Paradev's managed lifecycle hooks from a hooks-only settings file instead of relying on the profile's settings.

  • In managed terminal launches, the wrapper prepends --settings $SUPERSET_HOME_DIR/hooks/claude-settings.json; the selected profile's settings are never rewritten, and a caller-supplied --settings later in the argument list wins.
  • Teardown removes the generated file, and a missing file leaves the wrapper and non-Paradev launches unchanged.