Statusline meet my prompt

If you can’t tell I love my terminal. I like setting it up just the way I like it. There are many terminals but this one is mine. Starship is a big part of dialing in that experience. I really like my prompt.

I like that it trims the CWD to the last two directories if I’m deep in a tree. I love that it shows the git branch and status. And while there is questionable value in knowing which go version is being used, I like that it has a cute gerbil emoji filling in as a gopher.

It also shows me if my battery is low (>30%). Could I look at the top right corner of this Mac and see that same info? I could but I don’t and then I get the “plug me in or I’ll die” warning and I have to go scrambling for a power supply. No, I like it in my terminal.

So when I saw that Claude Code supported statusline I was unreasonably happy. It seemed reasonable enough:

  • Make a bash script that prints what you want
  • Add it to .claude/settings.json

And you can do similar things…

#!/bin/bash
# Read JSON input from stdin
input=$(cat)

# Extract values using jq
MODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')
CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')

# Show git branch if in a git repo
GIT_BRANCH=""
if git rev-parse --git-dir > /dev/null 2>&1; then
    BRANCH=$(git branch --show-current 2>/dev/null)
    if [ -n "$BRANCH" ]; then
        GIT_BRANCH=" | 🌿 $BRANCH"
    fi
fi

echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$GIT_BRANCH"

But I have a prompt. I like my prompt. I don’t want to reimplement Starship in bash to have a worse experience. I want to use my prompt. Starship is a command. It prints.

It took some experimentation and sed magic. Starship wraps prompt segments in %{...%} for terminal formatting. For example:

%{^[[0;36m%}~/code%{^[[0m%} %{^[[0;32m%}main%{^[[0m%}

The sed strips the %{ and %} wrappers but keeps the ANSI codes inside:

^[[0;36m~/code^[[0m ^[[0;32mmain^[[0m

This converts Starship’s zsh-style prompt format to raw ANSI codes that work in other contexts (like a certain CLI statusline).

The script is available below. It lets me keep my carefully tuned Starship prompt in Claude Code instead of rebuilding it from scratch. Sometimes the best solution is just calling the tool you already love.

Even if you need a little duct tape and sed.

#!/bin/bash

# Read JSON input from stdin
input=$(cat)

# Extract current directory from Claude Code context
CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')

# Set up environment variables that Starship expects
export PWD="$CURRENT_DIR"
cd "$CURRENT_DIR" 2>/dev/null || cd /

# Set reasonable defaults for missing shell variables
export COLUMNS=${COLUMNS:-120}  # Default terminal width
export KEYMAP=${KEYMAP:-}       # Empty keymap (not in vi mode)
export STARSHIP_CMD_STATUS=${STARSHIP_CMD_STATUS:-0}    # Success status
export STARSHIP_PIPE_STATUS=${STARSHIP_PIPE_STATUS:-}   # No pipe status
export STARSHIP_DURATION=${STARSHIP_DURATION:-}         # No command duration
export STARSHIP_JOBS_COUNT=${STARSHIP_JOBS_COUNT:-0}    # No background jobs

# Use minimal starship config specifically for Claude Code
export STARSHIP_CONFIG="$HOME/.config/starship-claude.toml"

# Call Starship with minimal config and preserve ANSI colors
/opt/homebrew/bin/starship prompt \
    --terminal-width="$COLUMNS" \
    --keymap="$KEYMAP" \
    --status="$STARSHIP_CMD_STATUS" \
    --pipestatus="$STARSHIP_PIPE_STATUS" \
    --cmd-duration="$STARSHIP_DURATION" \
    --jobs="$STARSHIP_JOBS_COUNT" | \
    sed 's/%{\([^}]*\)%}/\1/g'