Skip to content

context-economy 2.0.0: the compaction is the handoff, built on function hooks - #81

Merged
jasperboerhof merged 7 commits into
mainfrom
feat/context-economy-v2-mods
Oct 5, 2026
Merged

jasperboerhof merged 7 commits into
mainfrom
feat/context-economy-v2-mods

Conversation

@bjvle

@bjvle bjvle commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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.ts answers session.compact:

    1. A $.model.fork over the live session writes the handoff (~99.7% served from the prompt cache).
    2. The gate checks the draft, and a failed draft gets one corrected retry.
    3. The gated document replaces core's summary.

    A malformed draft never overwrites the stored handoff, and core's summary is the fallback.

  • /clear handover in-band. On session.end (clear), a marker is stored in $.store under
    lastClear:<processKey>. The key is a random id minted per process in session.start and kept in
    CONTEXT_ECONOMY_PROCESS_KEY, which outlives both a /clear and a hot reload. ($.state is per
    session and does not survive a /clear: finding shepard: leave the code simpler, and think the fix through before pushing #45.) The next prompt.submit then carries the
    handoff the cleared session wrote, with its GATE: line. If no handoff covers that session, it
    carries a note saying so, with the claude --resume line. Either way it writes a debug line.
    session.end drops 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/main slot, was gated against the wrong tree, and
    replaced core's summary. The checkout is now:

    1. CONTEXT_ECONOMY_CHECKOUT, set by the launcher; the fork is told to copy it.
    2. Else the checkout the fork names, once orienting from it succeeds.
    3. Else the session's cwd.

    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 /clear marker
    records where the last compaction wrote, with the cwd as fallback. The skill's Step 1 takes the
    variable as its TARGET and prints target-from=, so a run's manual and automatic handoffs
    share one slot.

  • Windows bash. $.process.run takes no shell, and from PowerShell a bare bash resolves to
    System32's WSL launcher. The lib scripts now run under Git for Windows' own bash.exe, and
    orient() 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. /autocompact decides when it happens.

  • Removed (breaking):

    • The three v1 shell hooks and their suites.
    • The detached writer's skeleton, lock and liveness machinery.
    • The store helpers and threshold constants that only those hooks used.
  • CI: the claude CLI 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 /clear marker), each followed by the measurement that
found 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

  • If a resumed process compacts before its first response, there is nothing to fork, so core's
    summary is used.
  • A hot reload between a /clear and the next prompt mints a new process key, so that prompt gets
    no handoff. The orphaned marker is pruned a day later.
  • After a /clear, a handoff the skill wrote by hand to a sibling checkout is looked for in the cwd
    if the session neither compacted nor had CONTEXT_ECONOMY_CHECKOUT set.
  • Not yet measured live: the precompute veto, and the checkout resolution (D34).

Test plan

🤖 Generated with Claude Code

bjvle and others added 7 commits October 2, 2026 12:21
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
jasperboerhof merged commit 9c52d2d into main Oct 5, 2026
3 checks passed
@jasperboerhof
jasperboerhof deleted the feat/context-economy-v2-mods branch October 5, 2026 18:49
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.

2 participants