Yesterday I introduced to you statusline command. It allows you to configure a persistent, live bar at the bottom of your CLI session that shows whatever your script prints — token usage, context percentage, current model, cost estimates, session duration, and more.
I promised that we would setup something like this:
█████░░░░░ 50% 64.0k/128.0k | ✱ Sonnet 4.5 | ~$0.04 | ⏱️ 00:12:34
But yesterday we only got as far as showing this:
Hello from PowerShell status line!
If you missed the previous post, go read it first, before continuing here. Back? Let's continue...
Now we have confirmed the script runs and we've the payload, we can now focus on creating a production-ready version. It extracts context usage, model name, cost (from the payload if available, estimated otherwise), and session duration.
I first created my own version but while researching this post I discovered this blog post by Madis Kõosaar: Customize GitHub Copilot CLI Status Line. He created a much nicer version of what I was trying to achieve.
As he created it for bash with a Linux focus, I adapted it to work on Windows using Powershell. Replace the original Powershell test script with the following code:
Two things were important to get the output correct. First I had to explicitly set the output encoding to UTF-8:
# Force output encoding to UTF-8 without BOM to ensure proper display of special characters in the status line.
$utf8 = New-Object System.Text.UTF8Encoding $false
[Console]::OutputEncoding = $utf8
$OutputEncoding = $utf8
Second, save the file with a UTF8 BOM. I did this by clicking on the encoding in the footer in VSCode and choose Save with encoding from the command pallet:
Then choose, save UTF-8 with BOM from the list:
This is how the result looks like:
Feel free to adapt it further to your needs.