In the world of AI-assisted development, context is everything. Claude Code—Anthropic's CLI provides an incredible "Status Line" feature that serves as the bridge between your local environment and the AI's internal state.
In this post today, I demonstrate how to move beyond the default setup. Using my favorite "theory meets practice" approach, you will explore how to pipe Claude's internal JSON data into a custom Bash script to build a high-density information HUD (Heads-Up Display).
The Theory: How Claude Code Talks to You
Claude Code doesn't just show a static bar; it executes a script (or command) and passes a JSON object into stdin. This object contains the "DNA" of your current session:
- Environment Data: Current working directory and file paths.
- Model Metadata: Which version of Claude is active.
- Context Utilization: How much of the context window is consumed—crucial for managing costs and performance.
By capturing this JSON, parsing it with jq, and mixing it with local git commands, we create a unified view of our project's health.
The Practice: Implementing a Dynamic Status Line
The following script transforms raw JSON data into a colorful, informative status bar. It focuses on three key pillars -- Location, Git State, and AI Awareness.
The Implementation Script
-- --
You can save this script as statusline.sh in your .claude directory of your project. And then, configure it in .claude/settings.json file as below:
-- --
-- --
Deep Dive: What’s Happening Under the Hood?
1. The Data Extraction
The script begins by swallowing the JSON input:
--
--
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
CUP_PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
--
Monitoring the used_percentage in real-time tells you when you're approaching the "forgetful" limit of the context window or when CC's slash command - `/compact` might be necessary.
2. The Git Intelligence
Standard status lines often just show the branch. This script goes further by calculating additions, modifications, and deletions:
--
--
all_stats=$(printf "%s\n%s" "$working_stats" "$staged_stats" | awk '...')
--
By differentiating between +added, ~modified, and -removed, you get a visual weight of your changes before you even ask Claude to commit them. Coming from the habit of coding stuff on Ubuntu OS leveraging Oh My Zsh, I badly wanted this on Claude Code terminal.
3. Visual Hierarchy with ANSI Colors
The script defines a palette (RED, GREEN, YELLOW, etc.) to ensure that critical information (like high context usage or many deletions) pops out immediately.
The Resulting HUD
Once active, your terminal will display a multi-line, emoji-rich summary:
- 📁 Directory Path: Always know exactly where the AI is operating.
- 🔀 Git Status: Real-time diff counts (e.g., 5 files changed +12 ~4 -2).
- 🤖 Model Info: Confirmation of whether you're on Sonnet, Opus, or Haiku.
- 🪣 Context Bucket: A percentage meter for your context window.
