Repository navigation
feat: opt-in per-session context export - #16
Merged
Merged
Conversation
STATUSLINE_CTX_EXPORT=1 makes each render write one private JSON record
per session to ${XDG_STATE_HOME:-~/.local/state}/cc-statusline/ctx/<sid>.json
so other local tools (a coordinator skill) can read a session's context
fill without parsing transcripts.
The record carries the displayed used_pct plus a source field computed in
jq before any bash default or clamp (native, tokens, held, unknown), so a
consumer never mistakes the 0% / 200k display fallback or a GPT held value
for a fresh measurement. used_tokens and context_window_size are null when
not measured. ts is publication time and advances on idle redraws.
Writes are synchronous and local: one subshell under umask 077, printf to
a temp file, atomic mv; every failure is silent and keeps the previous
record. Measured on macOS: about 5 ms per render. A best-effort sweep,
throttled by a .gc stamp to about once a day, deletes records not
rewritten for at least seven days (about 10 ms over 300 files).
Tests cover off-by-default, schema, modes, ts advance, relative
XDG_STATE_HOME, unknown shapes, gated strings, unsafe session ids, a
file in place of the directory, failed publication, a torn-read race,
the GPT hold path, and the sweep and its throttle.
An empty, null, partial, negative, fractional or oversized current_usage, or a fractional or oversized window size, was exported as a tokens measurement although the displayed value was a default. Require the same bounded-integer shape CTX_USAGE validates; anything else is unknown. Display is unchanged.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Opt-in context export for other local tools (first consumer: a coordinator skill that reads each session's context fill).
STATUSLINE_CTX_EXPORT=1(default off): every render writes one JSON line to${XDG_STATE_HOME:-~/.local/state}/cc-statusline/ctx/<session_id>.json(dir mode 700, file mode 600, temp file plus atomic rename). Override the directory withCC_STATUSLINE_CTX_EXPORT_DIR.v,session_id,used_pct(as displayed),used_tokens,context_window_size,source(native,tokens,held,unknown),stale,ts(publication time),model_id,effective_model_id,cc_version.sourceis computed before any display default or clamp, so a 0% / 200k fallback or a GPT held value is never presented as a fresh measurement. Documented in the README with the consumer contract (exact only fornative/tokensand0 <= now - ts < 180; ignore unknown fields)..gcepoch stamp), a foreground sweep deletes records not rewritten for at least seven days and stale temporaries; the sweeping session publishes its own record first and never sweeps it.Design notes
umask 077,printf,mv), failures silent and the previous record kept. Measured on macOS: about 5 ms per render; a sweep over 300 files about 10 ms.printf, so no JSON escaping is needed; a value failing its gate is""ornull.Validation
task cigreen locally in both locales (1266 render, 75 fetch, 3 installer tests).XDG_STATE_HOME, unknown/malformed context shapes, gated strings, unsafe session ids, a file in place of the directory, failed publication keeps the old record, a parallel-writer torn-read race, the GPT hold path, and the GC sweep, throttle, future/malformed stamps and symlinks.🤖 Generated with Claude Code