Feature Request: Context data access in statusline hooks

Resolved 💬 8 comments Opened Aug 26, 2025 by mishaal79 Closed Jan 9, 2026

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 /context command provides comprehensive context information
  • External statusline scripts have no way to access this same data
  • Users must manually run /context to monitor session state

Requested Feature

Add built-in support for exposing context data to statusline hooks, enabling:

  1. Real-time token usage - Show current/max tokens (e.g., "33k/200k tokens")
  2. Context percentage - Visual progress indicator (e.g., "17%")
  3. Memory breakdown - Show system/tools/memory allocation
  4. Context progress bar - Visual representation similar to /context command

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=7000

Option 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:

  1. ❌ Transcript file parsing - unreliable due to format variations
  2. ❌ External command invocation - /context is session-internal only
  3. ❌ Environment variable detection - Claude Code doesn't currently expose these
  4. 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.

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗