-
-
Save alexandrule/d4c5a208523aeba5b38aa3df316edba3 to your computer and use it in GitHub Desktop.
Example of Claude Code status line command script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| # Extract git remote repo name | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // empty') | |
| reponame="" | |
| if [ -n "$cwd" ] && [ -d "$cwd" ]; then | |
| remote_url=$(git -C "$cwd" --no-optional-locks remote get-url origin 2>/dev/null) | |
| if [ -n "$remote_url" ]; then | |
| reponame=$(basename "$remote_url" .git) | |
| fi | |
| fi | |
| reponame="${reponame:-"~"}" | |
| # Get git branch if in a git repository | |
| branch="" | |
| if [ -n "$cwd" ] && [ -d "$cwd" ]; then | |
| branch=$(git -C "$cwd" --no-optional-locks branch --show-current 2>/dev/null) | |
| fi | |
| # Get git worktree name | |
| worktree="" | |
| if [ -n "$cwd" ] && [ -d "$cwd" ]; then | |
| wt_path=$(git -C "$cwd" --no-optional-locks rev-parse --show-toplevel 2>/dev/null) | |
| [ -n "$wt_path" ] && worktree=$(basename "$wt_path") | |
| fi | |
| # Extract context usage percentage (pre-calculated field) | |
| used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| if [ -n "$used_pct" ]; then | |
| used_pct=$(printf "%.0f" "$used_pct") | |
| context="${used_pct}% context" | |
| else | |
| context="0% context" | |
| fi | |
| # Extract session cost | |
| cost_usd=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') | |
| cost_fmt=$(printf '$%.2f' "$cost_usd") | |
| # Extract total tokens as request volume | |
| input_tokens=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0') | |
| output_tokens=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0') | |
| total_tokens=$(( input_tokens + output_tokens )) | |
| # Format tokens in K | |
| if [ "$total_tokens" -ge 1000000 ]; then | |
| tokens_fmt=$(printf '%.1fM' "$(echo "$total_tokens / 1000000" | bc -l)") | |
| elif [ "$total_tokens" -ge 1000 ]; then | |
| tokens_fmt=$(printf '%.0fK' "$(echo "$total_tokens / 1000" | bc -l)") | |
| else | |
| tokens_fmt="${total_tokens}" | |
| fi | |
| # Build output string | |
| output="$reponame" | |
| [ -n "$branch" ] && output="$output | $branch" | |
| [ -n "$worktree" ] && output="$output | $worktree" | |
| output="$output | $context | ${tokens_fmt} tok | $cost_fmt" | |
| echo "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment