Skip to content

Instantly share code, notes, and snippets.

@metcalfc
Created September 7, 2025 05:32
Show Gist options
  • Save metcalfc/1184651c1f9f4f5700fc3abccbc6f398 to your computer and use it in GitHub Desktop.
Save metcalfc/1184651c1f9f4f5700fc3abccbc6f398 to your computer and use it in GitHub Desktop.
A Claude Code statusline using Starship
#!/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'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment