Skip to content

Instantly share code, notes, and snippets.

@ptaylor
Created November 16, 2026 17:04
Show Gist options
  • Select an option

  • Save ptaylor/1fc9b8284a79b8dc7339baba49155edf to your computer and use it in GitHub Desktop.

Select an option

Save ptaylor/1fc9b8284a79b8dc7339baba49155edf to your computer and use it in GitHub Desktop.
Claude Status Line
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh"
},
#!/usr/bin/env bash
# Claude Code status line. Receives session JSON on stdin.
input=$(cat)
cwd=$(jq -r '.workspace.current_dir // .cwd // empty' <<<"$input")
model=$(jq -r '.model.display_name // empty' <<<"$input")
[ -z "$cwd" ] && cwd=$PWD
dim=$'\e[2m'; cyan=$'\e[36m'; green=$'\e[32m'; yellow=$'\e[33m'; magenta=$'\e[35m'; reset=$'\e[0m'
parts=()
if top=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null); then
# Repo name from the origin remote, falling back to the main checkout's directory name
remote=$(git -C "$cwd" remote get-url origin 2>/dev/null)
if [ -n "$remote" ]; then
repo=$(basename "${remote%.git}")
org=$(basename "$(dirname "${remote/://}")")
repo="$org/$repo"
else
common=$(git -C "$cwd" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)
repo=$(basename "$(dirname "$common")")
fi
branch=$(git -C "$cwd" symbolic-ref --short -q HEAD || git -C "$cwd" rev-parse --short HEAD)
dirty=""
[ -n "$(git -C "$cwd" status --porcelain --untracked-files=no 2>/dev/null | head -1)" ] && dirty="*"
ahead_behind=""
if counts=$(git -C "$cwd" rev-list --left-right --count '@{u}...HEAD' 2>/dev/null); then
read -r behind ahead <<<"$counts"
[ "$ahead" -gt 0 ] && ahead_behind+="↑$ahead"
[ "$behind" -gt 0 ] && ahead_behind+="↓$behind"
fi
# Linked worktree: git-dir differs from the common dir
wt=""
[ "$(git -C "$cwd" rev-parse --absolute-git-dir)" != "$(git -C "$cwd" rev-parse --path-format=absolute --git-common-dir)" ] && wt=" ${magenta}[worktree]${reset}"
rel=${cwd#"$top"}; rel=${rel#/}
dir="$(basename "$top")${rel:+/$rel}"
parts+=("${cyan}${repo}${reset}${wt}")
parts+=("${green}${branch}${yellow}${dirty}${ahead_behind:+ $ahead_behind}${reset}")
parts+=("${dim}${dir}${reset}")
else
parts+=("${dim}${cwd/#$HOME/~}${reset}")
fi
[ -n "$model" ] && parts+=("${dim}${model}${reset}")
sep=" ${dim}│${reset} "
out="${parts[0]}"
for p in "${parts[@]:1}"; do out+="$sep$p"; done
printf '%s' "$out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment