Expand description
Harness transcript token and context-window policy.
This module owns the pure half of pre-emptive context clearing: parse token usage from harness transcript content, map model names to context windows, compute context percentage, and decide whether an opted-in caller should request a destructive context clear. Filesystem transcript discovery and reads stay in orchestration adapters.
Structs§
- Clear
Decision - Outcome of the dispatch-time pre-emptive clear gate.
- Transcript
Context Pct - Pure transcript context-% policy result.
- Used
Tokens - Cumulative token usage read from a harness session transcript.
Enums§
- Harness
- Harness whose session transcript token usage can be interpreted.
- Transcript
Context PctDiagnostic - Diagnostic reason for a transcript context-% miss.
Constants§
- CLAUDE_
CONTEXT_ WINDOW - Default context window in tokens for the current Claude model family.
Functions§
- claude_
project_ hash - Claude Code encodes a project directory into its transcript project
subdirectory by replacing every
/and.with-. - claude_
projects_ subdir - Compose the
~/.claude/projects/<project-hash>/transcript directory. - claude_
transcript_ path - Locate a Claude Code session transcript by known session id.
- clear_
decision - Decide whether an opted-in caller should pre-emptively clear context before dispatching a queue head.
- context_
pct - Compute context-usage percentage for
usedtokens againstmodel’s window, clamped to[0, 100]. - context_
window_ for_ model - Map a resolved model id to its context window in tokens.
- parse_
claude_ jsonl_ used_ tokens - Parse cumulative token usage from Claude Code JSONL transcript content.
- parse_
codex_ jsonl_ context_ pct - Parse Codex TUI session JSONL and compute context usage from the latest
token_countevent. - parse_
codex_ jsonl_ session_ meta_ cwd - Parse the
payload.cwdfrom a Codex TUIsession_metarecord. - transcript_
context_ pct_ from_ content - Parse transcript content and compute context-usage percentage for a harness.