Skip to content
On this page

    Custom Status Line for Claude Code

    2 min read

    Today I discovered Claude Code supports custom status lines through a simple bash script.

    After squinting at the default status bar one too many times, I built one that shows everything I actually care about - git context and token burn rate - in a single glanceable line.

    The Problem

    Claude Code’s default status line is functional but minimal.

    When you’re deep in a refactoring session, you want to know:

    • What branch am I on?
    • How many lines have I changed?
    • How much context window do I have left?
    • Am I burning through tokens?

    The Solution

    Claude Code pipes JSON to your status line script via stdin. You parse it with jq, grab git info, calculate padding, and output a single line with left/right alignment.

    #!/bin/bash
    input=$(cat)
    
    # Parse JSON from Claude Code
    dir=$(echo "$input" | jq -r '.workspace.current_dir')
    model=$(echo "$input" | jq -r '.model.display_name // .model.id')
    total_input=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0')
    
    # Git info
    branch=$(git -c core.useBuiltinFSMonitor=false branch --show-current 2>/dev/null)
    diff_stats=$(git diff --shortstat 2>/dev/null)
    
    # Terminal width for right-alignment
    term_width=${COLUMNS:-$(stty size 2>/dev/null | cut -d' ' -f2)}
    [ -z "$term_width" ] && term_width=120
    
    # Calculate padding between left and right sections
    padding=$((term_width - left_len - right_len))
    printf '%b%*s%b' "$left" "$padding" "" "$right"

    The full script handles context window percentage (color-coded: green >50%, yellow >20%, red otherwise), session duration, and token formatting with k suffixes.

    Full script on GitHub Gist

    Configuration

    Add to ~/.claude/settings.json:

    {
      "statusLine": {
        "type": "command",
        "command": "/Users/<you>/.claude/statusline-command.sh"
      }
    }

    What It Shows

    Left SideRight Side
    Directory nameModel name
    Git branchSession duration
    Lines added/removedContext window % left
    Token in/out counts

    The output adapts to terminal width:

    Custom status line showing git branch on the left, model and token metrics on the right

    What I Learned

    • Claude Code exposes rich JSON data to status line scripts: workspace, model, tokens, context window usage
    • tput cols doesn’t work in piped contexts - use $COLUMNS or stty size instead
    • Unicode characters (, ) break ${#var} length calculations - use wc -m for visible width
    • The core.useBuiltinFSMonitor=false flag prevents git from hanging on optional locks

    References


    Customizing your Claude Code setup? I’d love to see what status lines others have built. Reach out on LinkedIn.