Skip to content

docs(context-guard): record the cloud/headless capture verdict and make the gap legible - #3074

Merged
kyle-sexton merged 11 commits into
mainfrom
claude/pocock-steering-course-00zkvd
Aug 21, 2026
Merged

kyle-sexton merged 11 commits into
mainfrom
claude/pocock-steering-course-00zkvd

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #2957

Summary

context-guard's context-zone snapshot is written by a statusline tee. In a session with no
configured statusLine — cloud and headless sessions by default — nothing writes the snapshot,
context-zone.sh resolves unknown, and every zone consumer silently takes its conservative path.
The instrument-driven handoff trigger is structurally silent exactly where sessions are most
disposable.

Verdict: no documented channel delivers per-session context-window occupancy to a local writer
the way the status line does.
No capture path is shipped. What ships instead is the channel
inventory behind that verdict, plus the changes that make the resulting unknown legible as
structural rather than broken.

One correction to the issue's own premise, and the rest rests on it: ~/.claude/context-guard/
does exist in cloud — the PostCompact hook creates it. Plugin hooks run fine there; only the
statusline writer is silent. That is why hook stdin was the first channel checked, and it makes the
hooks-reference negative a measured result rather than an assumption.

Fix

reference/cloud-headless-capture.md (new) — every channel checked, each with the URL read and
the date, what it does and does not carry, and what would have to change upstream. The two that
came closest are documented as near-misses with the reason each fails:

  • OpenTelemetry. The claude_code.api_request log event does carry live per-session token
    occupancy — input_tokens + cache_read_tokens + cache_creation_tokens, session.id,
    query_source: "repl_main_thread" — the same addends the statusline page uses. It is rejected
    because it carries no denominator: no context_window_size and no percentage, and both
    resolver shapes need one. Measured ablation, included in the doc: a snapshot with real tokens and
    used_percentage: null resolves acceptable when context_window_size is present and unknown
    when it is absent. A writer would have to invent a per-model window map. It also needs an
    out-of-process OTLP receiver, and OTEL_* variables are not passed to hooks or Bash subprocesses,
    so nothing hook-local can even discover where the telemetry goes.
  • The session transcript. Reachable from every hook via transcript_path and carrying exactly
    the right numbers. A shape-validating reader would degrade to unknown rather than to a wrong
    zone, so the "it would break" argument alone does not carry. It is declined on the ground that
    does survive: silent semantic drift — field names surviving while ceasing to mean
    full-context occupancy, which no shape check detects — against a format the docs mark internal and
    version-unstable, plus an unbounded re-verification obligation.

reference/reader-contract.md — new cloud/headless section: unknown there is structural and
permanent, reported as "no instrument in this environment" and never as a defect; no zone may be
synthesized from another source; and because unknown carries no direction, a fork or handoff
trigger in such a session must come from elsewhere and must not be presented as instrument-backed.

A four-branch discriminator, because both a broken install and a structurally-absent instrument
print unknown. It now includes the state that was missing: a statusLine configured but the
status line disabled
— disableAllHooks, allowManagedHooksOnly narrowing with no managed value
deployed, or an untrusted workspace. Claude Code skips the value without warning, so that state
prints unknown with a statusLine present and would otherwise land on the "real defect" branch.
The scope list now spans user / launcher / remote / policy-limits / project / local / managed, and
managed outranks all others.

skills/setup/SKILL.md — check no longer contradicts itself. Its new INFO branch is gated on
the same condition step 3 uses: terminal-less → structural, unknown is correct and permanent;
otherwise → the ordinary not-yet-wired state, remediated by the wiring step 3 prints. Previously an
ordinary local install that simply had not wired the statusline was told nothing was broken.

Verification

The cloud question was settled empirically rather than inferred. A statusLine was wired into
this live cloud session's own settings pointing at a probe that logs stdin before teeing, and
exercised for ~7 minutes: never invoked once, no snapshot written. The probe was proven working by
hand-feeding it a payload. The same experiment under a scratch HOME with
claude -p … --output-format json gave the same result. Settings were restored byte-identical
afterwards, verified with diff. Other non-terminal environments (self-hosted runners) are labelled
as expected-but-not-measured rather than asserted.

Reader-side health confirmed in the same container: one synthetic statusline payload through the tee
produced a snapshot and resolved acceptable, while the real session id resolved unknown moments
earlier. Nothing in the resolver, tee, jq, or contract path is broken — there is simply nothing
calling the tee.

Gate Result
validate-plugins.sh, both generator --checks exit 0
check-changelog-parity.sh × 4 modes exit 0; 0.7.17 inserted above 0.7.16, 41 headings preserved, nothing absorbed
check-changed-skills.sh origin/main exit 0
markdownlint-cli2, typos 0 issues
context-guard suite — context-zone, statusline-tee, statusline-shim, zone-crossing-inject, zone-gate, post-compact-mark exit 0, 260 assertions
plugin-quality/zones-inline-drift.test.sh exit 0

An independent fresh-context audit fetched all cited pages itself rather than trusting the channel
table, reproduced all three container measurements verbatim, and found the original verdict
falsifiable — it had rejected OpenTelemetry on grounds true of its metrics and false of its events.
That, and five smaller defects, are fixed here. The audit's own proposed disqualifier for OTel was
in turn wrong in mechanism, and the correction above is the measured ablation that replaced it.

No behavior changed: zones.json, context-zone.sh, statusline-tee.sh and all hooks are
untouched; the diff is documentation plus one manifest version line and the setup-check wording.

Related

Refs #2994 (AI Hero course journey roadmap)
Refs #2901 (lane 3 — handoff trigger criteria, where this was surfaced)


Generated by Claude Code

@claude

claude Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 12s —— View job


Security review (/review:security-review)

  • Gather context (PR diff via gh pr diff, changed files, CLAUDE.md)
  • Invoke /review:security-review skill and follow its instructions
  • Post findings / summary

Skip gate triggered — no security-relevant surface.

I reviewed the full diff for PR #3074 (gh pr diff 3074, 6 files, +423/-9). Every change is documentation or metadata:

  • plugins/context-guard/.claude-plugin/plugin.json — version bump only (0.7.16 → 0.7.17) plus a description string.
  • plugins/context-guard/CHANGELOG.md — prose changelog entry.
  • plugins/context-guard/README.md — prose description update.
  • plugins/context-guard/reference/cloud-headless-capture.md — new reference doc (channel inventory, no executable content).
  • plugins/context-guard/reference/reader-contract.md — new prose section on how a consumer should report unknown.
  • plugins/context-guard/skills/setup/SKILL.md — updated natural-language diagnostic instructions for the check step of a setup skill (no shell/code blocks changed).

No shell scripts, hooks, GitHub Actions workflows, or executable logic are touched — zones.json, context-zone.sh, statusline-tee.sh, and all hooks are unchanged, consistent with the PR description's own claim. There's no injection surface, no auth/access-control logic, no secret/token handling, and no workflow permission changes in this diff.

Per the skip gate in /review:security-review ("Change has no security-relevant surface after reading the diff"), stopping here with no findings.

@claude

claude Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 4m 41s —— View job


Code review complete

  • Gather context (PR body, CLAUDE.md/AGENTS.md, REVIEW.md criteria)
  • Check skip gate — PR is open, non-trivial doc change, no prior review on this head; proceeded
  • Review diff (origin/main...HEAD) against code-review lane scope
  • Post inline findings and summary

This repo carries a claude-security-review.yml workflow, so this lane scoped out security findings entirely — none were found or expected in this documentation-only PR.

Finding (1, Important) — posted inline

The structural-vs-defect discriminator is missing a branch for the exact case this PR measured: a correctly-wired statusline in a terminal-less session.

reference/cloud-headless-capture.md's new "Distinguishing structural absence from breakage" section (and the near-identical section this PR adds to reference/reader-contract.md, and the check logic this PR revises in skills/setup/SKILL.md) all classify a session into: no statusLine anywhere → structural; statusLine configured but disabled by managed policy/workspace trust → structural; statusLine configured, not policy-disabled, no fresh snapshot → real defect.

But the PR's own headline measurement is a fourth case none of the three above actually cover: a statusLine correctly wired into the live cloud session's own user settings, pointing at a working probe, that was simply never invoked over ~7 minutes — not because of disableAllHooks, workspace trust, or allowManagedHooksOnly, but because the status line is a terminal-interface surface and the session has no terminal. cloud-headless-capture.md narrates this measurement as "landing on the structural side" right after its own discriminator, but by the discriminator's literal wording it lands in the "real defect" bucket instead.

The practical consequence is in skills/setup/SKILL.md: the terminal-less exception added at step 3 (lines 84-94) is wired only into the "no statusLine configured" bullet. The PASS bullet (lines 106-108) carries no such caveat, and step 4's FAIL bullet (lines 137-141) only excludes the policy-disabled case, not the terminal-less one. So a correctly-wired shim in a terminal-less environment — plausible via a project-scope statusLine committed for local use and later read in a cloud session on the same repo, not just the test rig — makes check PASS wiring, then FAIL on the missing snapshot and tell the operator to "re-check steps 2 and 3," exactly the self-contradiction this PR's title says it eliminates.

Left inline comments on all three files with the specific line ranges:

Fix this →

Notes

  • The PR's own claimed verification (test gates, live-container measurements) is author-claimed and not independently re-run by this review — I did not execute the context-guard test suite or reproduce the cloud measurements myself.
  • Everything else in the diff (version bump, CHANGELOG, README pointer, the rest of reader-contract.md and cloud-headless-capture.md) reads as internally consistent and well-sourced; no other correctness or maintainability issues found within the code-review lane's scope.

@github-actions

Copy link
Copy Markdown
Contributor

Last security-reviewed head: 16a5d3b07f322e5ed0cd32e18eadcb38d4f5b974. On the next push, the relevance gate compares only the commits since this SHA; delete this comment to force a full re-review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16a5d3b07f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude has reviewed this PR 2 times. The lane skips further automatic reviews after 5; deleting this comment resets the count.

claude and others added 11 commits August 21, 2026 09:06
…2957)

Step 1 of #2957: establish the current state empirically inside a live
Claude Code on the web container rather than reasoning about it.

Confirmed: no statusLine is configured in any settings scope, no
per-session snapshot exists, and context-zone.sh resolves `unknown`.

Corrected: ~/.claude/context-guard/ DOES exist in cloud — created by the
PostCompact hook. Plugin hooks run here; only the statusline writer is
silent. That is the finding the fix will build on.
…urces (#2957)

Step 2 of #2957: check every documented channel against the live docs
(all read 2026-08-21) and record the verdict with per-channel evidence.

Verdict: no documented channel other than the status line carries
per-session context-window telemetry. Hook stdin — the named candidate —
carries session_id, prompt_id, transcript_path, cwd, permission_mode,
effort, hook_event_name and event-specific fields, and no context, token,
usage, or window field on any event.

Also rejected, with the reason recorded: subagentStatusLine (subagent rows
only, and a status-line surface), non-interactive JSON/stream output
(per-invocation, after the fact), OpenTelemetry (cumulative counter, no
occupancy gauge), and the session transcript — reachable from every hook
via the documented transcript_path, but its entry format is documented as
internal and version-unstable, so parsing it would warrant a zone with
nothing. A wrong zone is worse than unknown.
…sumers (#2957)

Step 3 of #2957, no-viable-channel branch. The verdict is shipped; this
makes the resulting degradation readable instead of indistinguishable from
a broken install.

reader-contract.md gains a cloud-and-headless section: a session with no
configured statusLine has no instrument at all, so unknown is structural
and permanent there. Consumers report it as "no instrument in this
environment", never as a defect; never synthesize a zone from another
source; and never read unknown as evidence of a full window. It also gives
the discriminator between structural absence and breakage — read statusLine
from every scope, because both states print unknown.

The setup skill's check stops offering a remediation that cannot work: no
statusLine in a session that refreshes none is INFO with the structural
explanation, not FAIL with wiring instructions.
Bumps context-guard to 0.7.17 with the CHANGELOG entry for the
cloud/headless capture verdict, the reader-contract consumer rule, and the
setup-skill check branch.

The entry is INSERTED above the 0.7.16 heading; 0.7.16 and every earlier
release keep their notes intact.
…OT (#2957)

check-changed-skills.sh resolves a bare `reference/...` citation relative
to the SKILL DIRECTORY, and this plugin's reference/ sits at the plugin
root, so the two new citations read as broken skill-internal refs and
failed the gate. They now use the ${CLAUDE_PLUGIN_ROOT}/reference/ form the
rest of the file already uses.
…2957)

Measured in the same container: one synthetic statusline payload fed to the
tee under a scratch HOME produced a snapshot and resolved `acceptable`,
while the real session id resolved `unknown` moments earlier.

That separates the two explanations a reader could otherwise reach for.
Nothing in the resolver, the tee, jq, or the contract path is broken here —
there is simply nothing calling the tee, because nothing calls a statusline.
…ud empirically (#2957)

The verdict was falsifiable from its own citation. The OpenTelemetry row was
titled "metrics and events" but rejected the channel on the ground that every
documented metric is a cumulative counter — true of the metrics, false of the
events. `claude_code.api_request` is a documented log event carrying
input_tokens, output_tokens, cache_read_tokens and cache_creation_tokens per
request, query_source naming the issuing subsystem, event.sequence for
ordering, and session.id on by default. Filtered to the newest
repl_main_thread event it yields exactly the three input addends the
statusline page names as the used_percentage formula: live per-session
occupancy, for a running interactive session.

The channel now gets its own section and the disqualifiers that actually
hold. It carries no denominator — no context_window_size and no percentage —
and the resolver needs one: measured under a scratch HOME, a snapshot with a
mapped current_usage, both token totals and a cli_version but no
context_window_size resolves `unknown`, while adding one to the identical
file resolves `acceptable`. And it has no local delivery: prometheus is
metrics-only, console writes to Claude Code's own stdout, and Claude Code
strips OTEL_* from every subprocess it spawns including hooks, so nothing
hook-local can even find the receiver.

The headline verdict narrows to what is true: no documented channel other
than the status line *delivers per-session occupancy to a local writer*.

Three more corrections in the same pass.

Hook stdin's "no context, token, usage, or window field on any event" was
false as written: PostToolUse on the Agent tool receives totalTokens and a
usage breakdown in tool_response. It is subagent- and single-request-scoped
so the conclusion is unchanged, but this is the load-bearing sentence of a
document whose whole value is exhaustive channel accounting.

The transcript rejection argued only the weak half of its case. A
shape-validating reader degrades to writing nothing, which is `unknown` —
the same fail-open posture this contract mandates everywhere else — not to a
confident wrong zone. The decision stands on silent semantic drift, which no
shape check detects, plus an unbounded re-verification obligation against a
format its own docs call internal and unsupported.

The structural-vs-broken discriminator missed the state that prints
`unknown` with a statusLine present: the status line is turned off entirely
under a managed disableAllHooks or an untrusted folder, and under
allowManagedHooksOnly narrowing Claude Code runs a managed value if one is
deployed and otherwise skips yours without warning. Managed settings join
the scope list, the measured-facts grep covers the same scopes the rule
names, and the upstream-change bullet that claimed "neither is documented
today" now carries the statusline page as its anchor.

Finally, the cloud half of "no statusline runs here" was inference: the
earlier text verified only that none *is* configured. Measured from the
other side — a statusLine written into the live cloud session's own user
settings with refreshInterval 2, pointing at a probe that logs every
invocation before teeing, exercised ~7 minutes, then restored. The probe was
never invoked once; no log entry, no snapshot. statusLine is not among the
keys documented as read once at session start, and settings reload covers
user scope, so the value was live. The identical wiring under a scratch HOME
exercised with `claude -p` behaved the same. Both rows are now measurements.
…ract (#2957)

The contract restated the capture verdict in the form the capture reference
has just abandoned, so it inherited the same two defects.

"The absence of the only documented surface that carries per-session
context-window telemetry" is not what was measured; the OpenTelemetry
api_request event and the session transcript both carry live occupancy for
the running session. What the status line uniquely does is deliver that
occupancy to a local writer, so the sentence says that instead, and the
"never synthesize a zone" rule now names what each near-substitute would
force a reader to invent or trust rather than asserting a common failure
direction they do not share. Hook stdin's absolute carries the Agent-tool
exception.

The discriminator listed three scopes and two branches. It now lists four
scopes — managed settings carry statusLine too — and separates a configured
statusLine whose status line is *disabled* from a genuine wiring defect.
Under a managed disableAllHooks, an untrusted folder, or allowManagedHooksOnly
narrowing with no managed value deployed, Claude Code skips the configured
value without warning. That state prints `unknown` with a statusLine present,
which the old two-branch rule sent straight to "real defect" and an operator
chasing an install problem that does not exist. Its remediation is policy or
trust, never wiring.

The contract also records that cloud and headless are structural from both
sides now: not merely that no statusLine is configured there, but that one
configured there does not run.
…ocal install (#2957)

Step 3's terminal-less exception is properly gated — it fires only "where you
can tell you are in such a session". Step 4's matching branch was not: an
absent snapshot with no statusLine in any scope reported "INFO, never FAIL …
do not send the operator to fix an install that is not broken", unconditionally.

On an ordinary local terminal machine that installed the plugin and has not
yet wired the statusline — the single most common state this check exists to
diagnose — step 3 printed the wiring instructions and step 4 said nothing was
broken. Same report, opposite instructions, and the wrong one carried "never
FAIL".

Step 4's branch now splits on the same condition step 3 used. Where step 3
took the terminal-less exception the state is structural and `unknown` is
permanent. Otherwise it is the ordinary not-yet-wired state, and the
remediation is the wiring step 3 just printed — reported as such, and not
called structural.

Two related gaps close with it, both from the same missing scope. The
statusLine scope list omitted managed settings, where statusLine is also a
valid key and outranks the other three. And a status line can be turned off
with a statusLine still configured — under a managed disableAllHooks, an
untrusted folder, or allowManagedHooksOnly narrowing with no managed value
deployed, where Claude Code skips the configured value without warning. That
state was falling through to the wiring-defect FAIL; it is now an INFO
naming which condition applies, with policy or trust as the remediation.

Step 3's exception itself stops being an unlabelled inference. The claim that
a non-terminal session refreshes no statusline "no matter what is wired" is
now measured for Claude Code on the web and for a `claude -p` run, and marked
as expected-not-measured for other non-terminal environments.
…2957)

Amends the existing 0.7.17 text in place — no version bump, no new heading.
The entry stated the verdict in the falsifiable form, repeated hook stdin's
absolute without the Agent-tool exception, and rejected the transcript on the
"it would break on a release" argument the reference no longer relies on.

Now recorded: the verdict narrowed to delivery-to-a-local-writer; the
Agent-tool exception on PostToolUse tool_response; the OTel api_request event
as a real occupancy channel disqualified by a missing denominator (with the
measured resolver behavior) and by having no local sink; the transcript
declined on silent semantic drift rather than on shape breakage; managed
settings and the policy- or trust-disabled status line in the discriminator;
the `check` self-contradiction and its gating fix; and the cloud result as a
measurement — a statusLine configured in a live cloud session was never
invoked — rather than an inference from its absence.
…#2957)

The terminal-less exception lived only under "no statusLine configured", so a
correctly-wired shim in cloud or headless — the case this release measured —
was PASS at step 3 and FAIL at step 4. Lift that check orthogonal to all four
wiring states, exclude it from the snapshot-freshness FAIL the same way
policy-disable already is, and make step 7 skip printing wiring those
branches already forbade.

Also: route a managed effective statusLine to the policy administrator
instead of an operator edit; treat a stale leftover snapshot like an absent
one when nothing is configured; and give the reader-contract and
cloud-headless discriminators an explicit configured-but-terminal-less
branch so the measured case no longer matches "real defect".

Co-authored-by: Kyle Sexton <[email protected]>
@cursor
cursor Bot force-pushed the claude/pocock-steering-course-00zkvd branch from 16a5d3b to d8ccf49 Compare August 21, 2026 09:08
@claude

claude Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cursor[bot]'s task in 2m 55s —— View job


Code review complete

  • Gather context (PR diff, CLAUDE.md, prior review comments)
  • Invoke /review:code-review skill and follow its instructions
  • Post inline findings
  • Post summary comment

No blocking findings. This lane scopes security out (the repo carries claude-security-review.yml), and this PR is documentation-only — no scripts, hooks, or workflows changed.

What changed since the last review on this PR

The previous review round (mine and Codex's, on commit 16a5d3b07f) both flagged the same gap: the structural-vs-defect discriminator in skills/setup/SKILL.md, reference/reader-contract.md, and reference/cloud-headless-capture.md had no branch for "statusLine correctly configured, not policy-disabled, but the session is terminal-less" — exactly the case this PR's own cloud measurement exercised. That let a correctly-wired shim in a cloud/headless session land on PASS at step 3 and then FAIL at step 4 (or "real defect" in the two reference docs), the self-contradiction the PR title claims to fix.

Commit b91d3e0 and commit d8ccf49 close it:

  • skills/setup/SKILL.md — the terminal-less check is now its own bullet, orthogonal to all four wiring states (lines 103–119), not nested under "no statusLine configured." Step 4's FAIL branch now explicitly excludes it (lines 148–155), and step 7 no longer prints an ineffective edit when it applies (lines 190–197).
  • Also fixed, matching the four Codex P2 comments from the prior round: managed-scope statusLine now routes to the policy administrator instead of an operator edit (lines 76–81); stale (not just absent) snapshots are classified the same as absent when no statusLine exists (line 135); step 7's "always print" is now conditional.
  • reference/reader-contract.md and reference/cloud-headless-capture.md both gained the same explicit branch (cloud-headless-capture.md's discriminator is now 5-numbered, with branch 4 = "configured, not disabled, terminal-less" and branch 5 = the real-defect case), and the prose asserting the measured cloud case "lands on the structural side" now matches the discriminator's literal wording instead of contradicting it.

I checked all three files against each other for numbering/consistency (the "FOUR wiring states" vs the two orthogonal environment states, and the reader-contract's four discriminator bullets vs cloud-headless-capture's five numbered branches) and didn't find any residual mismatch. CHANGELOG.md and README.md were updated to match, and the version bump to 0.7.17 is consistent throughout.

No new issues found in this round of commits.
· branch claude/pocock-steering-course-00zkvd

@kyle-sexton
kyle-sexton merged commit 7b67537 into main Aug 21, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the claude/pocock-steering-course-00zkvd branch August 21, 2026 09:18
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.

context-guard: zone capture is statusline-teed and silent in cloud/headless sessions

3 participants