Repository navigation
Description
Problem
Currently, the statusline configuration in Claude Code runs as an external bash script that cannot access Claude Code's internal context state. This means users cannot display real-time context usage information (token count, memory breakdown, context percentage) in their status lines.
Current Situation
- The built-in
/contextcommand provides comprehensive context information - External statusline scripts have no way to access this same data
- Users must manually run
/contextto monitor session state
Requested Feature
Add built-in support for exposing context data to statusline hooks, enabling:
- Real-time token usage - Show current/max tokens (e.g., "33k/200k tokens")
- Context percentage - Visual progress indicator (e.g., "17%")
- Memory breakdown - Show system/tools/memory allocation
- Context progress bar - Visual representation similar to
/contextcommand
Proposed Implementation
Option 1: Environment Variables
Expose context data via environment variables when running statusline commands:
CLAUDE_CONTEXT_TOKENS=33000
CLAUDE_CONTEXT_MAX=200000
CLAUDE_CONTEXT_PERCENT=17
CLAUDE_MEMORY_TOKENS=7000Option 2: JSON Input Extension
Extend the existing JSON input to statusline scripts with context data:
{
"workspace": {...},
"model": {...},
"context": {
"tokens_used": 33000,
"tokens_max": 200000,
"percentage": 17,
"breakdown": {
"system": 3000,
"tools": 11900,
"memory": 7000,
"messages": 3600
}
}
}Use Cases
- Developers want to monitor context usage without interrupting their workflow
- Power users need proactive context management to avoid hitting limits
- Teams want consistent context awareness across development sessions
- CI/CD integrations need programmatic access to context state
Technical Analysis
This issue was identified while implementing a Claude Code development environment. We attempted several approaches:
- ❌ Transcript file parsing - unreliable due to format variations
- ❌ External command invocation -
/contextis session-internal only - ❌ Environment variable detection - Claude Code doesn't currently expose these
- ✅ Feature request - requires official Anthropic support
Related Issues
This relates to the broader theme of programmatic access to Claude Code session state for automation and monitoring purposes.
Priority
High - This is essential for effective context management in long-running development sessions.
Activity
github-actions commentedon Aug 26, 2025
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
coygeek commentedon Aug 26, 2025
This is a fantastic idea! I was just trying to build a more informative status line myself and ran into the exact same limitation.
You've nailed the problem description. We have this great
/contextcommand that shows everything we need, but no way to get that data into the status line where it would be most useful for at-a-glance monitoring.I just checked the official
statuslinedocs and the changelog to confirm. You're right, the current JSON input for the status line script includescost,model,workspace, etc., but nothing about the context usage. It looks like they just added thecostobject in v1.0.85 (according to the changelog), so your idea of adding acontextobject feels like a perfect next step.I definitely prefer your Option 2 (JSON Input Extension). It's much cleaner and more scalable. Having a dedicated
contextobject in the JSON payload would be way easier to parse in a script (whether it's bash, Python, or Node) than trying to juggle a bunch of new environment variables.Your proposed
contextobject looks perfect:Having the raw numbers and the pre-calculated percentage would be super useful for building different kinds of displays.
It's funny, the
/contextcommand itself isn't even in the main slash command docs yet (I saw another issue tracking that). Seems like a few of these newer, more powerful features are still waiting to be fully documented.For now, I guess the best we can do is use the
cost.total_cost_usdfield from the existing JSON input as a very rough proxy for token usage, but it's obviously not ideal.Great suggestion, giving this a 👍. Fingers crossed the team sees this and can get it into a future release.
ksavage9 commentedon Sep 24, 2025
Here's an idea: Use the hooks interface to run /context after every prompt and then use the data to populate a custom status line
mishaal79 commentedon Sep 25, 2025
Yes definitely.
I prefer option 2 too.
Token usage is important to know as a codebase keeps growing and adding features. There are aspects of the codebase which become centric or more like anchors for any feature being built.
Having the context on the status like and then being able to do hooks and other strategies to further automate so we give Claude optimised context to implement Todo tasks.
Ideally when we have 1m context sonnet model these issues wouldn't be much persistent.
mishaal79 commentedon Sep 25, 2025
Good workaround haha.
github-actions commentedon Dec 6, 2025
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
github-actions commentedon Jan 9, 2026
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
github-actions commentedon Jan 16, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.