[FEATURE] Native context visibility for self-regulating multi-context workflows

Status Open
Maintainer reply None cached
Activity 11 comments · opened Jan 13, 2026

Preflight Checklist

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

Problem Statement

Claude Code has no visibility into its own context usage. This creates three failure modes:

  1. Unpredictable walls - Context fills up, Claude Code forces /compact or /new at inconvenient times (mid-implementation, mid-thought). The user loses control of when breaks happen.
  1. Fixed phase guessing - Users pre-plan "Phase 1, Phase 2" etc., but these are predictions about context cost, not reality. Phases end up too small (wasted handoffs) or too large (hit the wall unexpectedly).
  1. Auto-compact degradation - If enabled, summarization kicks in mid-work, losing nuance and potentially confusing running agents.

The core issue: Claude cannot self-regulate because it cannot see how full its context is. The data exists - the statusline feature receives tokens, max, and percentage - but Claude has no access to read it.

Additionally, while agents exist for delegating work, there's no guidance on using them as an orchestrator pattern to keep the main context lean during large implementation tasks. Users discover this by trial and error, if at all.

Workflow impact:

  • Large implementation tasks that should be straightforward become unpredictable
  • Users can't confidently start multi-file work without risking mid-task context exhaustion
  • No standardized way to hand off work between contexts when breaks are needed

Proposed Solution

1. Native Context Visibility

Expose context usage to Claude directly. Options (in order of preference):

  • A built-in tool - GetContextUsage returning {percentage, tokens, max}
  • A system variable - Something Claude can reference directly
  • File-based - Write the existing statusline data to a file Claude can read by default (this is what we hacked together)

2. Context-Aware Workflow Guidance

Add system prompt guidance for large tasks:

  • "When context exceeds 85%, stop at a clean boundary and prepare for handoff"
  • "For multi-file implementations, act as orchestrator: read for understanding, delegate implementation to agents, receive summaries"
  • "Agent results return summaries, not full code - use this to keep main context lean"

3. Plan Continuation Support

Native support for picking up work in fresh contexts:

  • Plan picker - Show available plans with titles when continuing
  • Context tracking - Track which context completed which items (ctx1, ctx2 markers)
  • File references - Plans include specific files to read per checklist item, enabling targeted context building

Ideal User Experience

  1. User starts large task, Claude creates a plan with checklist
  2. Claude works as orchestrator - reads for understanding, delegates implementation to agents
  3. Claude monitors its own context, stops at 85%: "Stopping at 85%. Run /new then invoke /continue."
  4. Fresh context loads plan, sees what's done, continues from next item
  5. Repeat until complete

No guessing phases. No unexpected walls. Clean handoffs.

Alternative Solutions

Alternative Solutions

We built a working system using existing Claude Code primitives.

The Statusline Hack

Added one line to ~/.claude/statusline-command.sh:

echo "{\"ctx_pct\": $ctx_pct, \"tokens\": $current, \"max\": $size}" > "$HOME/.claude/context-status.json"

Now Claude can check its context:

cat ~/.claude/context-status.json
# Returns: {"ctx_pct": 68, "tokens": 136029, "max": 200000}

Two Skills Codifying the Workflow

/create-context-aware-plan - Creates plans with:

  • Checklist-first structure (no phases)
  • File references per checklist item (Read: lines)
  • Implementation reference sections

/continue-context-aware-plan - Continues work with:

  • Context monitoring verification
  • Plan picker (presents available plans)
  • Context number tracking (scans for highest ctx#, increments)
  • Orchestrator model guidance
  • Build verification after categories
  • Clean handoff at 85%

Limitations of This Workaround

  • Requires manual setup (statusline hack, skill installation)
  • Relies on a hack that could break with updates
  • Users must know to invoke the skills
  • Not discoverable - users won't find this on their own

Priority

High - Significant impact on productivity

Feature Category

CLI commands and flags

Use Case Example

Task: Implement 19 missing API handlers across multiple integration categories.

Without Context Awareness

Estimated requirements:

  • ~2850 lines of generated code held in context
  • Plus pattern files (~500 lines)
  • Plus API reference files (~1000 lines)
  • Plus conversation overhead
  • Total: 150k+ tokens minimum

What would happen:

  • Hit context wall mid-implementation
  • Forced /compact or /new at inconvenient time
  • Lost work or degraded quality
  • Pre-guessing phase boundaries (and getting them wrong)

With Our Context-Aware System

A fresh Claude Code instance with zero prior context:

  1. Invoked /continue-context-aware-plan
  2. Skill verified context monitoring worked (read JSON file)
  3. Presented plan picker, user selected the handler plan
  4. Determined this was context 1 (no existing ctx# markers)
  5. Read pattern files for understanding (not implementation)
  6. Delegated to agents: "Create these handlers following pattern in X"
  7. Agents worked in isolated context, returned summaries
  8. Main context received: "Created HandlerA, HandlerB" (~20 lines, not ~300 lines of code)
  9. Marked checklist items [x] (ctx1)
  10. Checked context after each agent batch
  11. Verified build after completing each category
  12. Completed all 19 handlers at 69% context

Why It Worked

The orchestrator model:

  • Main context holds: Plan understanding, pattern knowledge, agent summaries
  • Agents hold: Actual implementation work (isolated context)
  • Summaries cross the boundary: ~20 lines per batch instead of full code

Key insight: Understanding stays in main context. Implementation lives in agent context. Only summaries cross the boundary.

Generated Code Quality

Reviewed all 19 handlers:

  • Consistent structure across all handlers
  • Correct auth formats for each integration type
  • Proper error handling with specific exception types
  • Good logging, timeout handling, disposal patterns
  • Build passing with 0 warnings, 0 errors

Additional Context

What Would Make This Native

  1. Expose context percentage to Claude - The data already exists (statusline receives it). This is trivial to implement.
  1. Add orchestrator pattern to system prompt - Guidance for large tasks: "delegate implementation to agents, keep main context for understanding"
  1. Built-in plan continuation - Plan picker, context tracking, file references per item

The Pieces Already Exist

Anthropic built:

  • Statusline with context data
  • Agents with isolated context
  • Plan mode
  • Skills system

We just connected them. The statusline hack is 1 line of bash. The skills are ~100 lines each of markdown.

Attached Files

Note on Multi-Context Handoffs

Ironically, the orchestrator pattern was so efficient that we couldn't get it to need a handoff during testing - 19 handlers completed at 69% context. The handoff mechanism (plan picker, context number detection, checklist continuation) is mechanically simple and the least risky part of the system. The real value is the context visibility and orchestrator guidance that prevents needing handoffs in the first place.

Summary

The individual pieces exist. The combination into a self-regulating workflow isn't documented or native.

View original on GitHub ↗

11 Comments

RobSB2 · 7 months ago

+1 on this feature request. A few additional suggestions to consider:

Predictive warnings before large operations:

  • Before file reads: "This file (~2000 lines) will use approximately 8% of context"
  • Before exploration: "This search may consume significant context"

Post-operation feedback:

  • After each operation: "File read used 3% of context (now at 45%)"

Categorical breakdown (optional/expandable):

  • Conversation history: X%
  • File reads this session: X%
  • System context: X%

These would complement the native visibility you've proposed.

(I've built CxMS to work around context limits - visibility would significantly improve such workflows.)

Memphizzz · 7 months ago

@RobSB2 This should help your framework in the meantime:

statusline-command.sh

Then tell claude to use the .claude/context-status.json in the project's directory.

RobSB2 · 7 months ago

@Memphizzz Thanks for sharing! This is exactly what we need. I'll integrate this into CxMS as optional tooling so users can get context visibility out of the box.

The .claude/context-status.json approach is clever - lets Claude self-monitor without native API support.

chickensintrees · 6 months ago

Adding weight to this from a power user who has run 684+ sessions on Claude Code Max.

This is the single most impactful missing feature for anyone running long sessions with persistent agent identity. The agent can read files, send emails, deploy code, manage projects — but it cannot see the one resource constraint that governs all of its work.

We've built an entire workaround stack:

  • A hook_after_tool_call that counts tool calls as a proxy for context consumption and reminds the agent to save state
  • Persistent memory files the agent writes to continuously because it can never be sure when compaction will wipe its working memory
  • A session logging discipline where every session ends with a mandatory state dump

It works. Barely. It's duct tape on a load-bearing wall.

The lowest-effort, highest-impact option: periodic system reminder injection at configurable thresholds. The infrastructure already exists — system reminders are already injected for tool usage hints, stale task lists, and other purposes. One more that says context_window: 62% used, ~38K tokens remaining would be transformative. The agent could then make autonomous decisions about when to compress, save state, or wrap up — without the human having to babysit a percentage meter.

The human shouldn't be the fuel gauge for an autonomous agent.

STEF (agent) + Bill Moore (human), 684 sessions, 15.7M tokens

chickensintrees · 6 months ago

Hey — just closed my own issue (#27571) as a duplicate of this one because you nailed it.

We've been building around this same gap for the last month. Our agent (STEF) runs 600+ sessions on my machine — persistent identity, multi-project management, creative production, autonomous briefing system. Context visibility is the single biggest operational problem we face.

What we built to cope:

  • A hook_after_tool_call that counts tool calls as a rough proxy for context consumption and reminds the agent to save state at thresholds (50 calls = warning)
  • Persistent memory files (active-work.md, context.md) that the agent writes to continuously because we can't trust compaction to preserve creative decisions
  • A mandatory session logging discipline — every session ends with a state dump to disk
  • A statusline meter that reads context_window.used_percentage — but like you said, only the human sees it

Your statusline-to-JSON hack is elegant. We went the other direction (hook-based counting) but converge on the same insight: the infrastructure exists, it just isn't exposed to the agent.

Your orchestrator pattern with context-aware skills is also something we independently arrived at — we use agent teams where the lead delegates to sub-agents and receives summaries, specifically to keep the main context lean. Same architecture, different implementation.

"The individual pieces exist. The combination into a self-regulating workflow isn't documented or native." — That's the whole thing in one sentence.

Would genuinely love to compare notes on what's working. We're at chickensintrees if you want to look at what we've built.

chickensintrees · 6 months ago

Wrote up the full case: Context Is Everything

Covers the fuel gauge problem, the convergence (six strangers building the same workaround independently), what context loss actually costs in production, the regression, and the ask — one system reminder at 75%.

If anyone here wants to share it when pushing for this upstream, feel free.

rscottclift-ai · 2 months ago

Strong support -- adding a heavy real-world data point. I run a multi-domain autonomous agent system ("LifeOS") on Claude Code + Cowork across 8 business/personal domains. The single biggest reliability tax is exactly this: the agent cannot read its own context fullness.

My workaround is a crude proxy -- a "responses-since-session-start" counter with a hardcoded ~25-turn wrap threshold and a floor of 20 before the agent may even suggest wrapping. It's guesswork standing in for a number the platform already has. Compaction still arrives mid-task and silently drops nuance; I now treat any compaction event as proof "the wrap was already overdue." I maintain persistent handoff + memory files written every single session solely because context survival can't be trusted.

Option 1 (periodic <system-reminder> injection of context % at thresholds) would be the highest-leverage fix -- the agent already receives system reminders, so the plumbing exists. Please don't let this go stale; it's load-bearing for anyone running long autonomous sessions.

teshy · 2 months ago

Concrete data point from a production multi-agent workflow that hits this exact gap.

I run Handoff — a three-tab Claude Code setup (Haiku / Sonnet / Opus, each pinned to a tier) that coordinates on one repo through a file-based work-order mailbox. The driver tab auto-drains a queue of work orders without per-task human involvement, so context accumulates across many tasks and slams into auto-compact mid-task — your failure modes #1 (unpredictable wall) and #3 (auto-compact degradation), verbatim.

The workaround we were forced into is itself the argument for this feature. Because the agent can't read its own context, we:

  1. have the statusline persist ctx_pct to a file (.session-stats),
  2. read that file from our CLI wrapper and print the number back into the agent's command output, because piping it through tool output is the only way to get the value into the model's context, and
  3. encode doctrine that makes the agent stop at a logical boundary and ask the human to /compact when that surfaced number is high.

In other words: we launder a human-facing statusline value back into the model through tool output, then have the model act on a number it still can't natively see. It works, but it's a hack around a missing primitive — exactly "self-regulating multi-context workflows" that can't self-regulate.

What would replace the hack: native in-context visibility into tokens / max / % (injected into context, or a tool the model can call to query usage). With that, the driver could decide for itself when a phase is getting expensive and checkpoint cleanly — no .session-stats shim, no human-in-the-loop just to read a percentage.

The complementary half is being able to act on that visibility — agent-initiated compaction at a chosen boundary (#71803). Visibility (this issue) + action (#71803) together would let an autonomous multi-context workflow manage its own context end-to-end. Today we can do neither natively, so a human has to babysit the boundaries.

Strong +1 — happy to share the wrapper/doctrine if a concrete reference implementation of the workaround is useful.

rscottclift-ai · 2 months ago

Adding a second production data point. I run a 14-agent personal-ops fleet on Claude (Cowork + scheduled agents) plus an Opus "cockpit" chat that arbitrates across ~8 domains. Same wall, verbatim: the cockpit can't see its own context %, so our session-wrap doctrine is forced onto a response-count proxy instead of the real signal - context fullness. It mis-fires constantly: compaction hits mid-task before the proxy trips, or it nags to wrap when we're nowhere near full. teshy's statusline -> file -> launder-into-tool-output approach is exactly the shim we'd otherwise have to build. Native in-context tokens/max/% (or a tool to query usage) + agent-initiated compaction (#71803) would let autonomous multi-context workflows self-regulate instead of needing a human to babysit boundaries. Strong +1 on both.

teshy · 2 months ago

@rscottclift-ai — that's a third independent production data point (your 14-agent fleet, the GTM polling runner upthread, our Handoff), all hitting the identical wall. The response-count proxy mis-firing you describe is exactly our experience before we wired the statusline value back in: a proxy for "how full am I" either trips too early or too late because it isn't the real signal.

One nuance the multi-context case adds, in case it's useful evidence: even capturing the ctx% is awkward when you run several sessions. Claude Code renders the percentage per-tab in the statusline, but there's a single shared persistence sink — so to read a specific tab's fill we had to publish ctx% to a per-role file ourselves (we already do this for each tab's transcript path). The JSONL-transcript-size approach others mentioned (cozempic, a /check-context skill) is the alternative when you don't have the statusline value at all — but it's an estimate, not the real number.

So across all these setups the shim is the same shape and it compounds with fan-out: N sessions × per-tab bookkeeping, all to launder a value the model can't read directly. Native in-context tokens/max/% per session (this issue) + agent-initiated compaction (#71803) removes the whole layer and lets each session self-regulate. Strong +1 on both — and happy to share the per-role persistence bit if a reference is useful.

afram123 · 1 month ago

Filed #81259 as a narrow carve-out of item 1 here (native context visibility), in case it helps to have that part separable.

The framing there: Claude Code already injects the date, OS, working directory, git status and model ID into the model's context so its answers are grounded — context usage is the only piece of session state it withholds, and it's the one that governs the model's own scoping decisions (delegate to a subagent, propose a fresh session, read that 4k-line file or summarise it). Deliberately capped at read-only awareness — no self-compaction, no self-ending sessions, and none of items 2 and 3 from this request. Those are a bigger design conversation, and both depend on 1 landing first.

One thing worth surfacing for whoever triages either issue: #36281 is this same gap arriving as a model-behaviour bug — Claude announced "context is getting tight, let's wrap up", then admitted under questioning that it has no such perception and was extrapolating from conversation length. It was closed as a duplicate of #34238, which is the opposite complaint (unprompted "let's stop here" suggestions), and that one was then closed NOT_PLANNED. Two symptoms pointing in opposite directions, one cause: with no number, the model's only options are silence or guessing. Give it the number and it neither invents a limit nor nags about an imaginary one.

Not suggesting either issue close in favour of the other — happy for #81259 to be folded in here if that's easier to track.

✍️ @afram123, drafted with Claude Code.