Skip to content
Mia Automation
NLEN Sign in Put Mia to workGet started

A Claude Code Status Line That Shows Cost, Context and Git Branch

The Claude Code status line is a row at the bottom of the terminal that shows whatever a script of yours prints. Claude Code sends that script the session data as JSON. With about 40 lines of Python you can show the model, the folder and the git branch, plus how full the context window is and what the session has cost so far. Below is the script we tested in a live Claude Code 2.1.321 session on Linux and on a Windows 10 PC, the two lines of settings that turn it on, and the fields you can add.

Claude in practiceUpdated 5 min read

Tested by us on 11 November 2026.

How the status line works

Each time the conversation changes, Claude Code runs your command and passes a JSON object on standard input. Whatever your script prints becomes the status line. According to the docs, updates are batched every 300 ms, and you can add a refreshInterval in seconds if you show something time-based, like a clock. Colors work through ANSI escape codes, as long as your terminal supports them.

Diagram: five JSON fields from Claude Code flow into statusline.py, which prints one line; the context bar fills from 2 to 63 to 85 percent and turns green, yellow and red
Five fields go in, one line comes out. The bar changes color at 50% and 80% of the context window.

What you need

  • Claude Code. We tested with version 2.1.321.
  • Python 3. The script uses only the standard library, so you don't need jq, which many examples online depend on and which Windows doesn't ship with.
  • Git, if you want the branch name. Without it the script leaves that part out.

Set it up in three steps

  1. Save the script

    Save this as statusline.py in your .claude folder: ~/.claude/statusline.py on macOS and Linux, C:\Users\<you>\.claude\statusline.py on Windows.

    python
    #!/usr/bin/env python3
    """Claude Code status line: model | folder | git branch | context bar | cost | 5-hour limit.
    Reads the session JSON that Claude Code sends on stdin. Standard library only.
    Tested with Claude Code 2.1.321 on Ubuntu and with Python 3 on Windows 10, 2026-11-11."""
    import json, os, subprocess, sys
    
    data = json.load(sys.stdin)
    get = lambda path, default=None: (lambda d: d if d is not None else default)(
        __import__("functools").reduce(lambda d, k: d.get(k) if isinstance(d, dict) else None, path.split("."), data))
    
    GREEN, YELLOW, RED, DIM, RESET = "\033[32m", "\033[33m", "\033[31m", "\033[2m", "\033[0m"
    
    def color(pct):
        return GREEN if pct < 50 else YELLOW if pct < 80 else RED
    
    model = get("model.display_name", "?")
    folder = os.path.basename(get("workspace.current_dir", "") or "") or "?"
    
    branch = ""
    try:
        branch = subprocess.run(["git", "branch", "--show-current"], cwd=get("workspace.current_dir") or ".",
                                capture_output=True, text=True, timeout=1).stdout.strip()
    except Exception:
        pass  # no git, or not a repository: show nothing
    
    pct = int(get("context_window.used_percentage", 0) or 0)
    bar = "#" * (pct // 10) + "-" * (10 - pct // 10)
    cost = get("cost.total_cost_usd", 0) or 0
    
    parts = [f"[{model}]", folder]
    if branch:
        parts.append(f"git:{branch}")
    parts.append(f"{color(pct)}{bar} {pct}%{RESET}")
    parts.append(f"${cost:.2f}")
    five = get("rate_limits.five_hour.used_percentage")
    if five is not None:
        parts.append(f"{color(five)}5h {five:.0f}%{RESET}")
    
    print(f" {DIM}|{RESET} ".join(parts))
  2. Point Claude Code at it

    Add a statusLine entry to ~/.claude/settings.json. Starting the script through python3 means it doesn't need to be executable, a common reason for a blank status line. On Windows, write python instead of python3 and use the full path to the script.

    json
    {
      "statusLine": {
        "type": "command",
        "command": "python3 ~/.claude/statusline.py"
      }
    }
  3. Start a session and check the bottom row

    Start claude in a project folder. The line appears below the input box after the first update. If nothing shows, run the script by hand with sample input, as in the test below, and read the error.

Claude Code terminal session after a short question, with the status line at the bottom reading Sonnet 5.5, demo, git offerte-module, an empty context bar at 2 percent and 0.05 dollars (opens at full size)
Our live test session. The bottom line comes from the script above: model, folder, branch, context at 2% and $0.05 so far.

How we tested it

November 11, 2026.
TestWhereResult
Sample JSON with all fieldsUbuntu, Python 3.11All six parts shown; context 63% in yellow, 5-hour limit 24% in green
Empty JSON {}Ubuntu[?] | ? | 0% | $0.00, no crash
Same sample, folder with a git branchWindows 10, Python 3.14, Git 2.52Same line, including the branch name; test files removed afterwards
Live interactive sessionClaude Code 2.1.321 in a terminal on UbuntuLine updated after each answer, from $0.03 to $0.05; no 5-hour segment, because the session didn't send rate_limits

That last row matters if you copy examples from elsewhere. Not every field is present in every session, so read each one with a default, as the get() helper does. A script that crashes on a missing field shows nothing at all.

Fields you can add

A selection from the Claude Code status line documentation, checked November 11, 2026.
FieldWhat it holds
model.display_nameThe model name, as shown in the interface
workspace.current_dir, workspace.project_dirThe current folder and the folder where you started Claude Code
context_window.used_percentageHow full the context window is, already calculated
cost.total_cost_usdEstimated session cost at list price. It may differ from your bill
cost.total_lines_added, cost.total_lines_removedLines of code changed in the session
rate_limits.five_hour.used_percentage, rate_limits.seven_day.used_percentageHow much of your 5-hour and 7-day limit you've used, when present
pr.number, pr.review_stateThe open pull request for the current branch, when there is one

Let Claude Code write one for you

You can also type /statusline followed by what you want, for example /statusline show model name and context percentage with a progress bar. Claude Code writes a script in ~/.claude/ and updates your settings. /statusline delete removes it again. We prefer keeping our own script in version control, so the line looks the same on every machine we work on.

Why we watch cost and context

The two numbers that change how we work are the context percentage and the session cost. When the bar turns red, the session is carrying a lot of old conversation, and a fresh session with a short summary usually works better than pushing on. The cost figure keeps long agent runs honest: it's an estimate, but it shows quickly when a task is using far more than it should. For rules that keep agents from doing damage, see permissions and hooks.

Questions

Where do I configure the Claude Code status line?

In the statusLine object of your settings file, usually ~/.claude/settings.json, with "type": "command" and the command that runs your script.

Does the status line work on Windows?

Yes. We ran the script above with Python 3.14 on Windows 10. Use python and the full path to the script in the command.

Is the cost in the status line what I pay?

It's an estimate at list price, calculated by Claude Code itself. The docs note it can differ from your bill, and on a subscription you pay a flat fee.

Why doesn't my status line show the 5-hour limit?

The rate_limits field isn't sent in every session. In our test it was missing, so the script skips that part when the field is absent.

Sources