Repository navigation
context-economy 2.0.0: the compaction is the handoff, built on function hooks - #81
Merged
Merged
Conversation
The three v1 command hooks (PreCompact fork-write, SessionStart inject, SessionEnd marker) are replaced by one hooks module, hooks/register.ts: - session.compact: a $.model.fork over the live session writes the handoff, the gate checks the draft (one corrected retry), and the gated document is returned as the compaction itself. A malformed draft never overwrites the stored handoff; core's summary is the fallback. - session.end (clear) + prompt.submit: a $.state marker hands the first prompt after /clear the handoff the cleared session wrote, or says none covers it and how to resume. No plugin-side trigger: /autocompact's threshold is the trigger (design D29-D33). The detached writer, its skeleton/lock/liveness machinery, and the store helpers and constants only it used are removed. lib/handoff-orient.sh gives the module the store path from the shell library's single copy. Probe findings #37-#42 are in docs/measured.md; CI no longer stubs the claude CLI, which only the fork-write suite needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on function hooks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rientation failed $.process.run takes no shell, so a bare `bash` is PATH's first. From PowerShell on Windows that is System32's WSL launcher, which exits 1. v2 then fell back to core on every compaction, and its toast said "not inside a git checkout". Use Git for Windows' own bash.exe (found via `git --exec-path`, else the default install), probed once per load. orient() now returns its failure reason. Finding #43. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Finding #43 gains the retest after d508795: a manual /compact answered end to end under the resolved Git bash. Finding #44 records the first trigger:'auto' compaction answered by the module, with core never run, and the fork's cost at ~158K cache-read tokens. design.md narrows the "Still unmeasured" list accordingly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
$.state is the session's, and a /clear starts a new session, so the marker session.end wrote was gone at the next prompt: the first live /clear delivered nothing (finding #45). The marker now lives in $.store under a random key each fresh process mints in session.start and keeps in its own environment, which outlasts a /clear and a hot reload. $.state tells a fresh process (a child claude inherits the env) from a reload. prompt.submit now writes a debug line either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arker The handoff reached the first prompt after a live /clear: session.end stored lastClear:<key>, prompt.submit delivered it with a GATE line, and the handoff is now consumed. Finding #45 gets the retest, D32 and the CHANGELOG drop it from the unmeasured list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mission_control run's cwd is mission_control while its work is in a sibling worktree. Keyed to cwd, its compaction handoff landed in the shared mission_control/main slot, was gated against the wrong tree, and replaced core's summary. The checkout is now CONTEXT_ECONOMY_CHECKOUT, else the one the fork names once it orients, else the cwd. A source that does not orient falls through, and the toast and debug log name the source that chose, so a stale override shows. The /clear marker records where the last compaction wrote, with the cwd as fallback, and the skill's Step 1 takes the variable as its TARGET so a run's manual and automatic handoffs share one slot. D34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jasperboerhof
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports context-economy's automatic handoff path from command hooks to Claude Code's function hooks
("mods") and releases it as 2.0.0. Design:
docs/design.md§v2 (D29–D34). Measurements:docs/measured.md#37–#45.Compaction = handoff.
hooks/register.tsanswerssession.compact:$.model.forkover the live session writes the handoff (~99.7% served from the prompt cache).A malformed draft never overwrites the stored handoff, and core's summary is the fallback.
/clearhandover in-band. Onsession.end(clear), a marker is stored in$.storeunderlastClear:<processKey>. The key is a random id minted per process insession.startand kept inCONTEXT_ECONOMY_PROCESS_KEY, which outlives both a/clearand a hot reload. ($.stateis persession and does not survive a
/clear: finding shepard: leave the code simpler, and think the fix through before pushing #45.) The nextprompt.submitthen carries thehandoff the cleared session wrote, with its
GATE:line. If no handoff covers that session, itcarries a note saying so, with the
claude --resumeline. Either way it writes a debug line.session.enddrops the process's marker on any other reason and prunes markers older than a day.The handoff goes to the work's checkout, not always the cwd (D34). A mission_control run's
cwd is mission_control while its work is in a sibling worktree. Keyed to cwd, its compaction
handoff landed in the shared mission_control/
mainslot, was gated against the wrong tree, andreplaced core's summary. The checkout is now:
CONTEXT_ECONOMY_CHECKOUT, set by the launcher; the fork is told to copy it.A source that does not orient falls through to the next. The toast and the debug log always name
the checkout and the source that chose it, so a stale override shows. The
/clearmarkerrecords where the last compaction wrote, with the cwd as fallback. The skill's Step 1 takes the
variable as its
TARGETand printstarget-from=, so a run's manual and automatic handoffsshare one slot.
Windows bash.
$.process.runtakes no shell, and from PowerShell a barebashresolves toSystem32's WSL launcher. The lib scripts now run under Git for Windows' own
bash.exe, andorient()reports why it failed (finding Realign the catalog with kendo's 2026-09-05 review and plan work #43).No trigger of the plugin's own.
/autocompactdecides when it happens.Removed (breaking):
CI: the
claudeCLI stub is gone, since only the fork-write suite needed it.Commits: the implementation and the release commit (version bump + CHANGELOG), then fixes from the
live tests (Windows bash, the process-keyed
/clearmarker), each followed by the measurement thatfound or confirmed it, then the checkout resolution from mission_control's read-through. The 2.0.0 CHANGELOG entry was amended in place rather than bumped.
Known gaps
summary is used.
/clearand the next prompt mints a new process key, so that prompt getsno handoff. The orphaned marker is pruned a day later.
/clear, a handoff the skill wrote by hand to a sibling checkout is looked for in the cwdif the session neither compacted nor had
CONTEXT_ECONOMY_CHECKOUTset.precomputeveto, and the checkout resolution (D34).Test plan
bash plugins/context-economy/tests/gate.sh --run: 38 checks OKclaude plugin test plugins/context-economy: 28 passclaude plugin validate plugins/context-economy: passed/compactin a live session (finding agents: delete the five retired reviewers, close the catalog resync #42): fork 6.1 s, gate exit 0 first try/clearretest: handoff andGATE:line delivered to the next prompt, handoff markedconsumed(finding shepard: leave the code simpler, and think the fix through before pushing #45)CONTEXT_ECONOMY_CHECKOUTset by its launcherclaude plugin tag plugins/context-economy --push🤖 Generated with Claude Code