Skip to main content
Prompts Claude Code Developer Status Bar Script

developer coding developer risk: low

Claude Code Developer Status Bar Script

Create a single-file Python script that reads JSON from stdin and outputs a single ANSI-colored line to stdout displaying model name, project directory, git status, and cost metric…

PROMPT

# Task: Create a Professional Developer Status Bar for Claude Code

## Role

You are a systems programmer creating a highly-optimized status bar script for Claude Code.

## Deliverable

A single-file Python script (`~/.claude/statusline.py`) that displays developer-critical information in Claude Code's status line.

## Input Specification

Read JSON from stdin with this structure:

```json
{
  "model": {"display_name": "Opus|Sonnet|Haiku"},
  "workspace": {"current_dir": "/path/to/workspace", "project_dir": "/path/to/project"},
  "output_style": {"name": "explanatory|default|concise"},
  "cost": {
    "total_cost_usd": 0.0,
    "total_duration_ms": 0,
    "total_api_duration_ms": 0,
    "total_lines_added": 0,
    "total_lines_removed": 0
  }
}

```

## Output Requirements

### Format

* Print exactly ONE line to stdout
* Use ANSI 256-color codes: \033[38;5;Nm with optimized color palette for high contrast
* Smart truncation: Visible text width ≤ 80 characters (ANSI escape codes do NOT count toward limit)
* Use unicode symbols: ● (clean), + (added), ~ (modified)
* Color palette: orange 208, blue 33, green 154, yellow 229, red 196, gray 245 (tested for both dark/light terminals)

### Information Architecture (Left to Right Priority)

1. Core: Model name (orange)
2. Context: Project directory basename (blue)
3. Git Status:
* Branch name (green)
* Clean: ● (dim gray)
* Modified: ~N (yellow, N = file count)
* Added: +N (yellow, N = file count)


4. Metadata (dim gray):
* Uncommitted files: !N (red, N = count from git status --porcelain)
* API ratio: A:N% (N = api_duration / total_duration * 100)



### Example Output

\033[38;5;208mOpus\033[0m \033[38;5;33mIsaacLab\033[0m \033[38;5;154mmain\033[0m \033[38;5;245m●\033[0m \033[38;5;245mA:12%\033[0m

## Technical Constraints

### Performance (CRITICAL)

* Execution time: < 100ms (called every 300ms)
* Cache persistence: Store Git status cache in /tmp/claude_statusline_cache.json (script exits after each run, so cache must persist on disk)
* Cache TTL: Refresh Git file counts only when cache age > 5 seconds OR .git/index mtime changes
* Git logic optimization:
* Branch name: Read .git/HEAD directly (no subprocess)
* File counts: Call subprocess.run(['git', 'status', '--porcelain']) ONLY when cache expires


* Standard library only: No external dependencies (use only sys, json, os, pathlib, subprocess, time)

### Error Handling

* JSON parse error → return empty string ""
* Missing fields → omit that section (do not crash)
* Git directory not found → omit Git section entirely
* Any exception → return empty string ""

## Code Structure

* Single file, < 100 lines
* UTF-8 encoding handled for robust unicode output
* Maximum one function per concern (parsing, git, formatting)
* Type hints required for all functions
* Docstring for each function explaining its purpose

## Integration Steps

1. Save script to ~/.claude/statusline.py
2. Run chmod +x ~/.claude/statusline.py
3. Add to ~/.claude/settings.json:

```json
{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.py",
    "padding": 0
  }
}

```

4. Test manually: echo '{"model":{"display_name":"Test"},"workspace":{"current_dir":"/tmp"}}' | ~/.claude/statusline.py

## Verification Checklist

* Script executes without external dependencies (except single git status --porcelain call when cached)
* Visible text width ≤ 80 characters (ANSI codes excluded from calculation)
* Colors render correctly in both dark and light terminal backgrounds
* Execution time < 100ms in typical workspace (cached calls should be < 20ms)
* Gracefully handles missing Git repository
* Cache file is created in /tmp and respects TTL
* Git file counts refresh when .git/index mtime changes or 5 seconds elapse

## Context for Decisions

This is a "developer professional" style status bar. It prioritizes:

* Detailed Git information for branch switching awareness
* API efficiency monitoring for cost-conscious development
* Visual density for maximum information per character

REQUIRED CONTEXT

  • JSON from stdin with model, workspace, output_style, cost fields

ROLES & RULES

Role assignments

  • You are a systems programmer creating a highly-optimized status bar script for Claude Code.
  1. Print exactly ONE line to stdout
  2. Use ANSI 256-color codes: \033[38;5;Nm with optimized color palette for high contrast
  3. Smart truncation: Visible text width ≤ 80 characters (ANSI escape codes do NOT count toward limit)
  4. Use unicode symbols: ● (clean), + (added), ~ (modified)
  5. Color palette: orange 208, blue 33, green 154, yellow 229, red 196, gray 245 (tested for both dark/light terminals)
  6. Execution time: < 100ms (called every 300ms)
  7. Cache persistence: Store Git status cache in /tmp/claude_statusline_cache.json (script exits after each run, so cache must persist on disk)
  8. Cache TTL: Refresh Git file counts only when cache age > 5 seconds OR .git/index mtime changes
  9. Git logic optimization: Branch name: Read .git/HEAD directly (no subprocess)
  10. File counts: Call subprocess.run(['git', 'status', '--porcelain']) ONLY when cache expires
  11. Standard library only: No external dependencies (use only sys, json, os, pathlib, subprocess, time)
  12. JSON parse error → return empty string ""
  13. Missing fields → omit that section (do not crash)
  14. Git directory not found → omit Git section entirely
  15. Any exception → return empty string ""
  16. Single file, < 100 lines
  17. UTF-8 encoding handled for robust unicode output
  18. Maximum one function per concern (parsing, git, formatting)
  19. Type hints required for all functions
  20. Docstring for each function explaining its purpose

EXPECTED OUTPUT

Format
code
Schema
ansi_line · Model name (orange), Project directory basename (blue), Git Status (branch, clean/modified/added), Metadata (uncommitted files, API ratio)
Constraints
  • single file
  • <100 lines
  • type hints for functions
  • standard library only
  • UTF-8 encoding
  • print exactly one line to stdout
  • visible text width <=80 characters excluding ANSI codes

SUCCESS CRITERIA

  • Script executes without external dependencies
  • Visible text width ≤ 80 characters (ANSI codes excluded)
  • Colors render correctly in both dark and light terminal backgrounds
  • Execution time < 100ms in typical workspace
  • Gracefully handles missing Git repository
  • Cache file created in /tmp and respects TTL
  • Git file counts refresh when .git/index mtime changes or 5 seconds elapse

FAILURE MODES

  • May exceed 100ms execution time without proper caching
  • May produce multi-line output instead of single line
  • May crash on errors instead of returning empty string
  • May use external dependencies beyond standard library
  • May exceed 80 character visible width
  • May not handle missing fields by omitting sections

EXAMPLES

Includes one example output line with ANSI color codes.

CAVEATS

Dependencies
  • JSON input from stdin
  • Git repository (optional for full Git status)
  • Cache file in /tmp/claude_statusline_cache.json (created if needed)
Missing context
  • Exact parsing rules for 'git status --porcelain' output to compute added (e.g., lines starting with 'A'), modified ('M'), uncommitted (total lines).
  • Handling division by zero for API ratio if 'total_duration_ms' is 0.
  • Method for computing visible text width excluding ANSI codes (e.g., ANSI stripper function).
  • Confirmation of Git repository root (assumed to be 'project_dir' or 'current_dir').
Ambiguities
  • Unclear how to combine Git status elements (branch name, clean/modified/added symbols) into the output string. Example shows 'main ●' but lists them separately.
  • Ambiguous definitions of 'file count' for ~N (modified), +N (added), and !N (uncommitted files); unclear relationship between counts from 'git status --porcelain'.
  • Fixed cache filename '/tmp/claude_statusline_cache.json' does not account for multiple workspaces or repositories.
  • Model 'display_name' format like 'Opus|Sonnet|Haiku' – unclear how to display (example uses 'Opus').
  • 'dim gray' for certain elements – exact ANSI sequence not specified (e.g., intensity attribute).
  • Smart truncation method undefined: which parts to truncate or omit if visible width approaches 80 characters.
  • 'output_style' input field specified but not referenced in output requirements.
  • Unclear which directory basename to use for display: 'current_dir' or 'project_dir' (spec mentions 'Project directory basename').

QUALITY

OVERALL
0.75
CLARITY
0.85
SPECIFICITY
0.80
REUSABILITY
0.25
COMPLETENESS
0.90

IMPROVEMENT SUGGESTIONS

  • Provide multiple example outputs covering clean, modified, added, and uncommitted Git states to clarify string construction.
  • Specify cache filename as unique per project, e.g., f'/tmp/claude_statusline_cache_{hashlib.md5(project_dir.encode()).hexdigest()}.json'.
  • Define precise counts: e.g., added = count of porcelain lines starting with 'A', modified = 'M', uncommitted = total non-empty lines.
  • Clarify model display: 'Use first part before '|' or first word of display_name'.
  • Specify ANSI for dim: '\033[2;38;5;245m for dim gray, reset with \033[0m'.
  • Define truncation priority: e.g., shorten project basename to basename[-20:], then omit metadata if still >80.
  • Incorporate 'output_style': e.g., 'concise' omits metadata, 'explanatory' adds tooltips (if possible).
  • Add: 'Use project_dir basename for context display.'

USAGE

Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.

MORE FOR DEVELOPER