Example

Account for the context you did not type

Run the context inspector over a captured invocation and see the bytes and tokens the context actually cost, reconciled against the captured input.

Most of what reaches a model is not what you typed. The chapter’s claim is that a context window has to be accounted for before anything else can be said about it, and the research harness can do that accounting from a captured invocation: the same capture that produced the model call produces the report.

Run it

git clone https://github.com/ernanhughes/project-context.git
cd project-context
git checkout b4e84a35bce27eff15584750e59131da49b1c049
python -m venv .venv
.venv/Scripts/pip install -e .
.venv/Scripts/contextlab debug panel fixtures/opencode-capture-v2/spool/captures.jsonl --output panel.html --svg-output panel.svg --json-output report.json

Python 3.11 or later. The command is read-only over the fixture and writes only the three output files you named. No model is called and nothing leaves the machine.

Expected outcome

Context inspector generated locally (HTML; optional SVG and structural JSON).
1,854 canonical bytes; ~463.5 tokens.
Token provenance: approximation. Category shares reconcile to captured input.

Two things are being claimed, and they are different claims. The byte count is exact. The token count is an approximation, and the harness says so rather than presenting it as a measurement. And the category shares reconcile against the captured input: the accounting adds up to what was actually sent, which is the property that makes the report worth reading.

Where the accounting comes from

The panel is not a rendering of a model call; it is a structural report over a capture, and the harness refuses to publish it unless the parts add up. The reconciliation is a check, not a comment:

def validate_panel(report: dict[str, Any]) -> None:
    """Validate stored report reconciliation, including after a JSON round-trip."""
    if report["schema"] != PANEL_SCHEMA:
        raise ValueError("unsupported panel schema")
    if sum(row["bytes"] for row in report["categories"]) != report["total_bytes"]:
        raise ValueError("category bytes do not reconcile")
    for row in report["categories"]:
        if row["bytes"] != sum(item["bytes"] for item in row["items"]):
            raise ValueError("item bytes do not reconcile")
        if row["estimated_tokens"] != row["bytes"] / 4:
            raise ValueError("incorrect estimate")
    if report["estimated_tokens"] != report["total_bytes"] / 4:
        raise ValueError("incorrect total estimate")

The token estimate is four bytes per token, and the report says so. The byte count is exact; the token count is an approximation the panel labels as one.

Mechanism and limitations

Documented: the panel schema, the reconciliation rules and the allow-listed publishable derivative are in src/project_context/debugger/panel.py; the capture the run reads is fixtures/opencode-capture-v2/spool/captures.jsonl.

Observed: the run above. The report counted 1,854 canonical bytes and about 463.5 tokens, labelled the token figure an approximation, and reported that the category shares reconcile against the captured input.

Not shown. The token count is bytes divided by four, which is a declared approximation and not a tokenizer’s answer; a different tokenizer would report a different number for the same capture. The accounting covers what was captured, not what the model received: a capture that missed a part of the request would reconcile perfectly over the wrong total. Nothing here shows that the accounting changed a decision, or that the context it measured was good context. The published inspector example in the repository’s evidence tree has drifted from its own manifest, so it is not cited here as verified.

Canonical source and the panel module .

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.