Skip to main content

Module context_usage

Module context_usage 

Source
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§

ClearDecision
Outcome of the dispatch-time pre-emptive clear gate.
TranscriptContextPct
Pure transcript context-% policy result.
UsedTokens
Cumulative token usage read from a harness session transcript.

Enums§

Harness
Harness whose session transcript token usage can be interpreted.
TranscriptContextPctDiagnostic
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 used tokens against model’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_count event.
parse_codex_jsonl_session_meta_cwd
Parse the payload.cwd from a Codex TUI session_meta record.
transcript_context_pct_from_content
Parse transcript content and compute context-usage percentage for a harness.