Day 32 of 52 · about 15 min · Basics · Bonus
Build a status line for model, context and branch
Which model is this, how full is the context, which branch am I on? A status line answers all three at a glance, so you stop running commands to find out.
You’ll finish with
- A status line that shows the model, the share of context used and the git branch.
- A script that reads the session’s JSON on stdin, tested with sample input.
- The
statusLinesetting in your user settings, written for your system.
You’ll need
- Node.js 22 or newer, and
.claude/statusline.mjsfrom the Day 32 kit. - The docs’ examples are Bash scripts for macOS and Linux. Ours is Node, so it runs on Windows too; see the docs’ Windows configuration for PowerShell scripts.
Before you start
Tell us about your setup and the steps change to fit it. Your answers stay in this browser, and you can change them at any time.
Which system are you on?
Commands differ between systems. Pick the one you’ll run Claude Code on.
The steps
One step at a time. When a step’s check matches, tick it and the next one opens.
Step 1 of 4: Try the quick way
Describe the status line you want and let Claude Code write it.In Claude CodeYou type: /statusline show the model, context percentage and git branch
What happens: Claude Code writes a script in
~/.claude/and updates your settings. Approve the edits it asks for.Step 4 swaps this for the kit script, which you can read and test. Check it worked
A new row at the bottom of Claude Code shows what you asked for.
Step 2 of 4: Copy the kit script to your user folder
A status line in your user settings follows you into every project.For macOS, Linux and WSL
TerminalRun: mkdir -p ~/.claude
Run: cp .claude/statusline.mjs ~/.claude/statusline.mjs
Run this in the kit folder. For Windows
PowerShellRun: Copy-Item .claude\statusline.mjs "$HOME\.claude\statusline.mjs"
Run this in the kit folder. ~/.claude/statusline.mjsJavaScript// Status line: the model, how full the context window is, and the git branch. // // Opus | 25% context | branch main // // Claude Code runs this script with the session's data as JSON on stdin and // shows what it prints. The status line goes blank if the script exits with // a code other than 0, so every failure here falls back to a placeholder. // // It is plain Node, so the same file works on macOS, Linux, Windows and WSL. // Copy it to ~/.claude/statusline.mjs and point the statusLine setting in // ~/.claude/settings.json at it (see the Day 32 lesson). import { execFileSync } from 'node:child_process'; let data = {}; try { data = JSON.parse((await readStdin()) || '{}'); } catch { // Unreadable input: show the placeholders rather than nothing. } const model = data.model?.display_name || 'Model --'; // used_percentage can be null before the first reply in a session. const used = data.context_window?.used_percentage; const context = typeof used === 'number' ? `${Math.round(used)}% context` : '--% context'; const dir = data.workspace?.current_dir || data.cwd || process.cwd(); let branch = ''; try { branch = execFileSync('git', ['branch', '--show-current'], { cwd: dir, encoding: 'utf8', timeout: 2000, // the status line runs often, so never wait long stdio: ['ignore', 'pipe', 'ignore'], }).trim(); } catch { // Not a git repository, or git is not installed: leave the branch out. } console.log([model, context, branch && `branch ${branch}`].filter(Boolean).join(' | ')); async function readStdin() { let text = ''; for await (const chunk of process.stdin) text += chunk; // Windows PowerShell 5.1 can put a byte order mark in front of piped text. return text.replace(/^\uFEFF/, ''); }It reads three fields from stdin and asks git for the branch.
Check it worked
statusline.mjsis in the.claudefolder of your home folder.Step 3 of 4: Test it with sample input
Pipe in the kind of JSON Claude Code sends, before any settings change.For macOS, Linux and WSL
TerminalRun: echo '{"model":{"display_name":"Opus"},"context_window":{"used_percentage":25}}' | node ~/.claude/statusline.mjs
What happens: It prints
Opus | 25% context, then the branch in a git repository.The real input has many more fields; the script ignores them. For Windows
PowerShellRun: '{"model":{"display_name":"Opus"},"context_window":{"used_percentage":25}}' | node "$HOME\.claude\statusline.mjs"
What happens: It prints
Opus | 25% context, then the branch in a git repository.The real input has many more fields; the script ignores them. Check it worked
One line that starts with
Opus | 25% context.Step 4 of 4: Point your settings at it
Add the statusLine key to your user settings and keep everything else.For macOS, Linux and WSL
~/.claude/settings.json- statusLine.type: "command"
- Run a command and show what it prints.
- statusLine.command: "node ~/.claude/statusline.mjs"
- Your shell turns
~into your home folder.
Saving the file is enough; Claude Code reloads settings by itself. For Windows
~/.claude/settings.json- statusLine.type: "command"
- Run a command and show what it prints.
- statusLine.command: "node C:/Users/<you>/.claude/statusline.mjs"
- Your full home path, with forward slashes. Git Bash drops backslashes.
Saving the file is enough; Claude Code reloads settings by itself. Check it worked
The status line shows your model, the context percentage and the branch, and updates after each reply.
If it didn’t work
The status line is blank.
Run the step 3 test again: the script must print a line and exit 0. In a folder you haven’t trusted yet, it stays blank until you accept the trust dialog.
Finish · 4 of 4 steps to go
Three answers, always on screen
What you’ll have checked
- The sample input prints
Opus | 25% context. - Your status line updates after each reply.
Lesson updates by email
Get lesson updates by email
Leave your email and we’ll tell you when we add or update a lesson.
Claude Code for your team
Want Claude Code set up across your team?
HorizonLux sets up and repairs Claude Code for teams: CLAUDE.md rules, hooks that enforce them and reviewed MCP servers. Book a free call to talk it through.
Related
Questions
Questions about Day 32
Does the status line cost tokens?
No. It runs on your machine and doesn’t use API tokens.
Sources
Checked against the official Claude Code docs on .
Independent resource, not affiliated with Anthropic. HorizonLux wrote this lesson; Claude Code is made by Anthropic.