Repository navigation
fix(claude): register a short PostCompact hook command - #25211
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full PR (1 commit, 7 files): replacing the ~3 KB portable wrapper on PostCompact with a short POSIX-only form so a manual /compact no longer re-inflates the context it just freed.
- POSIX branch extracted (
runtime-home-hook-command.ts):buildPosixBranch+wrapRuntimeHomePosixHookCommandemit just the[ -f ] && [ -r ] && [ -x ]branch with the stdin-drain fallback; the full wrapper now builds its POSIX arm through the same helper, so the two cannot drift. - Per-event hook selection (
hook-settings.ts):getManagedEventHookreturns the Windows launcher on win32 andbuildManagedCommandHook(getRemoteManagedEventCommand(...))on POSIX; for every event exceptPostCompactthat resolves to exactly the oldgetManagedLifecycleHookvalue (pinned by a test), so only the echoed event changes. - Install/status threading (
hook-service.ts):applyManagedHookstakeshookForEvent(eventName), and local install, remote SFTP install, and the installed-status check all route through the new helpers. - Tests: new
post-compact-hook-command.test.tscovers length < 400, other events/Windows unchanged, remote POSIX from every client platform, real/bin/shexecution withORCA_HOOK_AGENT_PIDcapture, silent 1 MB stdin drain with a missing script/HOME, local install replacing an old full-wrapper entry, and remote install shape; the command-contract ratchet now scans the short form too.
Technical details
# Verification notes (no action requested)
## What I checked
- `applyManagedHooks` signature change: every caller updated (`hook-service.ts` ×2, the two
`claude`/`compact` tests). Grep found no stale single-hook call sites.
- Equivalence: on POSIX, `getManagedEventHook` for non-`PostCompact` events equals
`getManagedLifecycleHook` because `getRemoteManagedCommand` already passes
`{ neutralJsonWhenMissing: true }`. Confirmed by `hook-service`/contract suites, not just by reading.
- Migration: a pre-existing full-wrapper `PostCompact` is swept by the shared file-name matcher and
replaced on the next startup reconcile (`installManagedAgentHooks` in `main-process-ready-runtime.ts`),
so a transient `getStatus() === 'partial'` before that reconcile is expected and self-heals.
- Cross-platform: win32 install/status both still use the launcher; remote is always POSIX regardless of
client OS. The short form keeps the `ORCA_HOOK_AGENT_PID` capture for `claude-hook`/`openclaude-hook`.
## Commands run
- `pnpm exec vitest run --config config/vitest.config.ts` on the five touched suites → 225 passed / 5 skipped.
- Same on `src/main/agent-hooks`, `src/main/qoder`, `src/main/openclaude` → 1169 passed / 12 skipped.deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The shorter PostCompact command is recognized during installation and removal, and no issue requiring a pre-merge fix was established. Security Architecture Review
Pre-merge checks |
|
…5211) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude Code echoes every PostCompact hook's full command into the post-compact transcript, so Orca's ~3KB portable wrapper landed in the model's context after every /compact. On POSIX hosts (local macOS/Linux and SSH remotes) PostCompact now gets only the POSIX branch of the wrapper; every other event, and Windows, keep the full wrapper. Fixes stablyai#25209
e452010 to
f7f642f
Compare

ELI5
After you compact a Claude conversation, Claude Code shows Orca's hook command to the model. That command was about 3 KB of shell code. This PR makes the command for that one hook short, so compacting no longer refills the context with it.
What Changed
Before: Orca registers a
PostCompacthook so a manual/compactcan clear the pane's "working" status. Its command is the same portable wrapper every event uses, about 3 KB, because it covers Windows Git Bash, PowerShell, a missingHOME, a missing script and so on. Claude Code prints everyPostCompacthook's full command into the post-compact transcript, which the model reads. So each/compactadded about 3 KB of shell to the context it had just freed.After: on POSIX hosts (local macOS/Linux and SSH remotes),
PostCompactgets a 371-byte POSIX command. WhenHOMEis set and nonempty and the managed script is readable and executable, it runs the script with the agent's parent PID captured. Otherwise it drains stdin silently. An unset or emptyHOMEskips script lookup entirely. Every other event, and Windows, keep the full wrapper, unchanged.How:
runtime-home-hook-command.tsexposes the POSIX branch on its own (wrapRuntimeHomePosixHookCommand). The full wrapper builds the same branch through a shared helper.hook-settings.tsaddsgetManagedEventHook/getRemoteManagedEventCommand, which pick the hook per event.applyManagedHookstakes a per-event hook function instead of one hook for all events.ClaudeHookServiceuses it for local install, remote install and the installed-status check. An existing full-wrapperPostCompactentry is replaced, and isn't reported as a partial install.Why
Making the shared wrapper shorter wasn't an option: it is deliberately portable, so one
settings.jsonworks on any OS. Only the echoed event pays for that size, so only the echoed event changes.The short form gives up two things, and
PostCompactneeds neither:{}reply when the script is missing.Windows keeps its launcher, because the short form can't run there.
The change applies to Claude, OpenClaude, Qoder and Qoder China, whose managed event lists include
PostCompact.Linked Issue
Fixes #25209
Visual Proof
N/A. No UI change; the only visible difference is the shorter hook line in Claude's post-compact output.
Testing
New
post-compact-hook-command.test.tscovers:/bin/shcaptures the exact parent PID, and drains 1 MB of stdin silently when the script is missing orHOMEis unset or empty;HOMEperforms no script lookup;PostCompactand the full wrapper elsewhere.The managed-hook command contract test now covers the
PostCompactcommand forclaudeandopenclaudeon every platform.pnpm tcandpnpm run check:code-quality:changed origin/mainpass. Insrc/main/claude,src/main/agent-hooks,src/main/qoder,src/main/openclaude,src/main/qwen-codeandsrc/main/codebuddy, 3,259 tests pass (44 skipped).The contributor manually tested
/compacton Linux. On macOS, Claude Code 2.1.296 was also exercised through a real PTY with a local model-response stub because the saved login had expired: the original 3,027-byte command was saved in the transcript and included in the next model request; the short command completed successfully and replaced it in the next request.AI Disclosure
Written with Claude Code (Claude Opus 5.5), reviewed and tested by hand.
Review
Checked migration, repeated installation, removal, user-hook preservation, platform selection, shell quoting, stdin draining, and process identity. Eight comparisons confirmed that extracting the POSIX branch leaves the full wrapper byte-identical.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
PostCompactentry, and the status check treats the old entry as outdated.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)