claude-code - 💡(How to fix) Fix [Feature] Expose current model name and context window size in session metadata

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Use case: I'm building puppet-mcp, a tmux-based multi-session orchestrator. It needs to monitor context budget across 10+ concurrent sessions and warn before hitting the wall. Without knowing whether a session is on 200k or 1M, the warning thresholds are wrong.

Code Example

{
  "pid": 12345,
  "sessionId": "abc-def-...",
  "agent": "haak",
  "model": "claude-opus-4-6",
  "modelAlias": "opus[1m]",
  "contextWindow": 1000000,
  ...
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

There is no programmatic way to query a running Claude Code session's current model name and context window size (200k vs 1M).

What I've tried:

  • ~/.claude/sessions/*.json — has sessionId, pid, agent, cwd, version but no model or contextWindow fields
  • JSONL assistant message model field — says claude-opus-4-6 for both 200k and 1M (doesn't encode context size)
  • Scrollback scanning for "1M context" text from /model output — unreliable, scrolls off in long sessions
  • Token count heuristic (if >195k tokens, must be 1M) — works but is a hack

Use case: I'm building puppet-mcp, a tmux-based multi-session orchestrator. It needs to monitor context budget across 10+ concurrent sessions and warn before hitting the wall. Without knowing whether a session is on 200k or 1M, the warning thresholds are wrong.

Related: #51382 (expose session metadata), #45169 (subagent strips [1m] suffix)

Proposed Solution

Add model and contextWindow fields to ~/.claude/sessions/{PID}.json:

{
  "pid": 12345,
  "sessionId": "abc-def-...",
  "agent": "haak",
  "model": "claude-opus-4-6",
  "modelAlias": "opus[1m]",
  "contextWindow": 1000000,
  ...
}

contextWindow is the effective context window in tokens. modelAlias is the alias as specified (preserving the [1m] suffix). These should update when the user changes model via /model.

Alternative: expose via the statusLine hook data or a local API endpoint. Any machine-readable source would work.

Environment

  • Claude Code version: 2.1.142
  • OS: macOS
  • Terminal: tmux (orchestrating multiple sessions)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING