OmniscioGuidesStatus line examplesPython
Claude Code status line in Python
A Claude Code status line is the bar below the prompt: Claude Code runs a shell command and shows its output as one or more rows. Anthropic's pattern examples — the context bar, git status, cost and duration, multi-line, clickable links, rate limits and caching — each exist in Bash, Python and Node.js; Anthropic's Windows setup example is given for PowerShell and for Bash, not Python. This page carries three of those in Python — the context bar, git status and cost — each run by the same settings entry, with the field handling that keeps a row from going blank. If you would rather read Bash, the library page points at the Bash versions and the rest of the set.
Checked on November 26, 2026 against the Claude Code 2.1.332 documentation. By the Omniscio team. Updated .
Why Python
The documented Bash examples call jq to read JSON, and jq is a separate install. Anthropic's note is plain: Python and Node.js have built-in JSON parsing. A Python status line therefore needs no second tool, and the null handling reads more like the language you already write.
The rest of the setup is identical. Claude Code runs statusLine.command in a shell, so the file only has to be executable and named in settings. Anthropic's own setup line lists .sh, .py and .js as the usual file types.
The one Python-specific habit worth keeping is the null guard: .get('used_percentage', 0) or 0. The percentage can be null early in a session, and or 0 turns both a missing key and a None into a number the arithmetic can use.
Script 1: the context bar
This is Anthropic's context window usage example in Python. It prints the model and a ten-character bar of filled and empty blocks, then the percentage.
#!/usr/bin/env python3
import json, sys
data = json.load(sys.stdin)
model = data['model']['display_name']
pct = int(data.get('context_window', {}).get('used_percentage', 0) or 0)
filled = pct * 10 // 100
bar = '▓' * filled + '░' * (10 - filled)
print(f"[{model}] {bar} {pct}%")Two lines carry the meaning. filled = pct * 10 // 100 turns a percentage into a count of blocks out of ten, using integer division so the bar has no partial block. The string multiplication then builds the filled part and the empty part in one expression.
The or 0 is not decoration. used_percentage may be null early in a session, and int(None) raises. With the guard the row prints an empty bar instead of a traceback, which is the difference between a readable row and a blank one.
Script 2: git status with colours
This is Anthropic's git status example in Python. It reads the model and folder from the JSON, runs git for the branch and the two file counts, and falls back to model and folder outside a repository.
#!/usr/bin/env python3
import json, sys, subprocess, os
data = json.load(sys.stdin)
model = data['model']['display_name']
directory = os.path.basename(data['workspace']['current_dir'])
GREEN, YELLOW, RESET = '\033[32m', '\033[33m', '\033[0m'
try:
subprocess.check_output(['git', 'rev-parse', '--git-dir'], stderr=subprocess.DEVNULL)
branch = subprocess.check_output(['git', 'branch', '--show-current'], text=True).strip()
staged_output = subprocess.check_output(['git', 'diff', '--cached', '--numstat'], text=True).strip()
modified_output = subprocess.check_output(['git', 'diff', '--numstat'], text=True).strip()
staged = len(staged_output.split('\n')) if staged_output else 0
modified = len(modified_output.split('\n')) if modified_output else 0
git_status = f"{GREEN}+{staged}{RESET}" if staged else ""
git_status += f"{YELLOW}~{modified}{RESET}" if modified else ""
print(f"[{model}] 📁 {directory} | 🌿 {branch} {git_status}")
except:
print(f"[{model}] 📁 {directory}")The try block is the repository test: git rev-parse --git-dir succeeds inside a repository and raises outside one, and the except branch prints the shorter row. The two counts come from numstat output split on newlines, which counts files rather than lines.
The JSON has no branch field for a normal session, which is why the script runs git itself. The worktree.branch field exists only while the session runs inside a Claude Code worktree, a linked checkout of the repository, so it is not a general-purpose branch source. That distinction is covered in full on the git branch page.
Script 3: cost and duration
This is Anthropic's cost and duration example in Python. It prints the session's estimated cost and how long it has been running, in minutes and seconds.
#!/usr/bin/env python3
import json, sys
data = json.load(sys.stdin)
model = data['model']['display_name']
cost = data.get('cost', {}).get('total_cost_usd', 0) or 0
duration_ms = data.get('cost', {}).get('total_duration_ms', 0) or 0
duration_sec = duration_ms // 1000
mins, secs = duration_sec // 60, duration_sec % 60
print(f"[{model}] 💰 ${cost:.2f} | ⏱️ {mins}m {secs}s")The cost is an estimate computed on your machine at list price unless a modelPricing table is in effect, so it can differ from your bill. It resets to zero when /clear starts a new session.
The duration is the time the session has been running, which accumulates across resumes and excludes time the session was not running. Python's :.2f is doing the formatting that Bash does with printf '$%.2f', and the integer division by 1000 and then by 60 is the same milliseconds-to-minutes conversion as the documented scripts in the other two languages.
The settings entry
Save your chosen script as ~/.claude/statusline.py and make it executable, then add this to ~/.claude/settings.json or to a project's settings file.
chmod +x ~/.claude/statusline.py{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.py"
}
}Add the object beside whatever else the file holds, inside the same braces. Claude Code reloads settings and runs the script as soon as you save it, so there is nothing to restart.
If the executable bit or the first line that names the interpreter (the shebang) is a problem on your system, name the interpreter in the command instead: python3 ~/.claude/statusline.py. On Windows, use the interpreter name your install provides and a forward-slash path.
How to confirm it renders
Test the script before you trust the setting. Anthropic's tip is to pipe mock JSON into it:
echo '{"model":{"display_name":"Opus"},"workspace":{"current_dir":"/home/you/my-app"},"context_window":{"used_percentage":25},"session_id":"test"}' | ~/.claude/statusline.pyThe context script should print [Opus] ▓▓░░░░░░░░ 25%. The git script should print the model and folder, with a branch when you run it inside a repository. The cost script should print $0.00 and 0m 0s from that mock, because the mock carries no cost object and the or 0 fallbacks apply.
Inside Claude Code, claude --debug logs the script's stderr on every invocation and its exit code on the first invocation in a session. A Python traceback there is the whole diagnosis: the script ran and failed, rather than never having run.
When the row does not appear at all, the causes are the same as for a Bash script: the workspace trust dialog has not been accepted for the folder, the file is not executable, the output went to stderr, or the script exited non-zero.
What goes wrong with a Python row
| What you see | Check |
|---|---|
| No row at all | The workspace trust dialog has been accepted for the folder, the file is executable, and the interpreter line or command is right. claude --debug shows the exit code |
| The row was there, then went blank | A traceback. Read the mock run: a KeyError or TypeError on a missing field is the usual cause |
| The percentage prints as zero early in a session | Expected. used_percentage may be null before the first API response, and the guard prints zero |
| A raw traceback appears in the row | Python writes tracebacks to stderr, but a shell wrapper can echo them. Run the file directly and fix the exception |
| Nothing works on Windows | Write the path with forward slashes, or name the interpreter in command |
More in this set
Each page carries a complete setup, not a fragment.
Where Omniscio fits
The status line is Claude Code's own, and nothing on this page needs Omniscio. Omniscio is a desktop app for running several Claude Code agents side by side, in one list rather than a wall of terminals.
Its agent sessions run Claude Code in print mode, so they show Omniscio's session list rather than a terminal row. A status line you configure still applies to any claude you run yourself in a terminal.
The features page lists what the app does today.
How this page was checked
Every statement here about Claude Code comes from Anthropic's own documentation, read in its Markdown form on November 26, 2026: the status line page, the settings reference and the changelog. The version line comes from the changelog, whose newest release is 2.1.332, dated November 25, 2026.
All three scripts are Anthropic's Python examples reproduced in full; the context example's code comments are removed from its code block and kept as prose on this page. They were not written for this page and not run on our machine.
What this page says about Omniscio comes from our own pages. If Anthropic's page and this one ever disagree about Claude Code, Anthropic's page is right.
Sources
- Customize your status line: the setting, the full JSON, the Python versions of every example, the setup steps and the troubleshooting section
- Settings reference: the
statusLineentry and its fields - The changelog: release 2.1.332, the newest listed
Omniscio's own pages, for what this section says about this app:
- Omniscio's homepage: the product description
- Features: what the app does today
- Claude Code status line: the setting and the payload this page assumes
Common questions
Do I need jq for a Python Claude Code status line?
No. Anthropic notes that Python and Node.js have built-in JSON parsing, while the Bash examples use jq. A Python script calls json.load on stdin and needs nothing installed beyond Python itself.
Where does a Python status line script go?
Anywhere you like. Anthropic's setup says to save the script to a file like ~/.claude/statusline.sh, .py or .js, make it executable, and add the path to your settings. The statusLine command is a shell command, so it just has to run the file.
Why does my Python status line print nothing?
Claude Code shows the output only after the script exits with code 0. A traceback exits non-zero and leaves the row blank, so run the script by hand with mock JSON first and read claude --debug for its stderr and exit code.
Does a Python status line work on Windows?
Yes, if the command names the interpreter or the file is executable in the shell Claude Code uses. On Windows Claude Code runs the command through Git Bash when it is installed and PowerShell when it is not, so write paths with forward slashes.
Run those Claude Code sessions from one window
Install Omniscio, keep your Claude Code sessions in one list, and see what each one needs without hunting through terminals. The features page lists what is in it today.