1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeのstatuslineを使ってプラン使用量やその他情報を表示してみた

1
Last updated at Posted at 2026-03-20

ども@s_hirokiです。

今回はClaudeCodeでstatuslineという機能を知ったので、他の方の情報を参考にしながら自分用にカスタマイズをしてみました。

statuslineとは

ClaudeCodeの下部にあるカスタマイズ可能なバーということで、都度シェルスクリプトを実行してくれてプラン使用量とかその他情報を表示出来る機能です。

/statuslineコマンドでAIに要望を伝えることで作成することができます。
詳細は以下公式をご確認ください。

自分用にカスタマイズ

こんな感じにカスタマイズしました。とても便利。

image.png

  • 1行目:ディレクトリのフルパスを表示
  • 2行目:プロジェクト名ブランチがあれば表示
  • 3行目:コンテキストウィンドウの使用状況と、使用モデルを表示
  • 4行目:5時間単位と週単位のプラン使用量と次のリセットまでの時間を表示
  • 5行目:セッション内の累計コスト時間を表示
  • 6行目:現在ブランチに紐づくPRが作成されていれば表示(ghコマンドで情報取得)

ご注意
4行目のプラン使用量については初回起動の場合はN/Aと表示されますが、何か指示出した後にはちゃんと表示されるようになります。

コンテキストウィンドウの使用量は使用率に応じで色分けをしました。

image.png

手動での設定方法(Macの場合)

1. シェルスクリプトのファイルを作成する

~/.claude直下にstatusline-command.shのファイルを作成し以下コードを記載する。
(作成場所はどこでも良いと思います)

==== コードが長いので折りたたみ ====

警告
--- Line 6: GitHub PR ---以下の部分はghコマンドが使えないと正しく表示されないのでご注意ください。

#!/bin/bash

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

# --- Line 1: Working directory ---
cwd=$(echo "$input" | jq -r '.cwd // .workspace.current_dir // ""')
cwd_display=$(echo "$cwd" | sed "s|^$HOME|~|")
echo "🗂️  $cwd_display"

# --- Line 2: Project name and git branch ---
project_name=$(basename "$cwd")
branch=$(git -C "$cwd" --no-optional-locks rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -n "$branch" ]; then
  echo "💡 $project_name | 🌿 $branch"
else
  echo "💡 $project_name"
fi

# --- Line 3: Context usage bar + model (Fine Bar + Gradient) ---
used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
model=$(echo "$input" | jq -r 'if .model | type == "object" then .model.id else .model end // empty')

make_bar() {
  local pct=$1 bar_width=20
  local full_blocks remaining
  full_blocks=$(( pct * bar_width / 100 ))

  local r g
  if [ "$pct" -le 50 ]; then
    r=$(awk "BEGIN{printf \"%d\", $pct * 5.1}")
    g=200
  else
    r=255
    g=$(awk "BEGIN{v=200-($pct-50)*4; if(v<0) v=0; printf \"%d\", v}")
  fi
  local color reset
  color=$(printf '\033[38;2;%d;%d;0m' "$r" "$g")
  reset=$(printf '\033[0m')

  local filled="" empty="" i
  remaining=$(( bar_width - full_blocks ))
  i=0; while [ "$i" -lt "$full_blocks" ]; do filled="${filled}█"; i=$(( i + 1 )); done
  i=0; while [ "$i" -lt "$remaining" ]; do empty="${empty}░"; i=$(( i + 1 )); done

  printf '%s%s%s%s' "$color" "$filled" "$reset" "$empty"
}

if [ -n "$used_pct" ]; then
  used_int=$(printf "%.0f" "$used_pct")
  bar=$(make_bar "$used_int")
  if [ -n "$model" ]; then
    printf '🧠 %s %d%% │ 💪 %s\n' "$bar" "$used_int" "$model"
  else
    printf '🧠 %s %d%%\n' "$bar" "$used_int"
  fi
else
  if [ -n "$model" ]; then
    printf '🧠 ░░░░░░░░░░░░░░░░░░░░ 0%% │ 💪 %s\n' "$model"
  else
    printf '🧠 ░░░░░░░░░░░░░░░░░░░░ 0%%\n'
  fi
fi

# --- Line 4: サブスク使用率(rate_limits から直接取得) ---

# リセットまでの残り時間をフォーマット(Unix epoch → "Xh Ym" or "Xd Yh")
format_reset_time() {
  local ts="$1"
  [ -z "$ts" ] || [ "$ts" = "null" ] && return

  local epoch now remaining
  # Unix timestamp(整数)をそのまま使う
  epoch="$ts"
  now=$(date +%s)
  remaining=$(( epoch - now ))
  [ "$remaining" -le 0 ] && return

  local days hours mins
  days=$(( remaining / 86400 ))
  hours=$(( (remaining % 86400) / 3600 ))
  mins=$(( (remaining % 3600) / 60 ))

  if [ "$days" -gt 0 ]; then
    echo "${days}d ${hours}h"
  elif [ "$hours" -gt 0 ]; then
    echo "${hours}h ${mins}m"
  else
    echo "${mins}m"
  fi
}

five_h_pct="N/A"
seven_d_pct="N/A"
five_h_reset=""
seven_d_reset=""

five_hour_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
seven_day_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
five_hour_reset_ts=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
seven_day_reset_ts=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')

if [ -n "$five_hour_pct" ]; then
  five_h_pct="$(printf "%.0f" "$five_hour_pct")%"
fi
if [ -n "$seven_day_pct" ]; then
  seven_d_pct="$(printf "%.0f" "$seven_day_pct")%"
fi
five_h_reset=$(format_reset_time "$five_hour_reset_ts")
seven_d_reset=$(format_reset_time "$seven_day_reset_ts")

five_h_display="${five_h_pct}"
seven_d_display="${seven_d_pct}"
[ -n "$five_h_reset" ] && five_h_display="${five_h_pct} (🔄 ${five_h_reset})"
[ -n "$seven_d_reset" ] && seven_d_display="${seven_d_pct} (🔄 ${seven_d_reset})"
echo "📦 5h: ${five_h_display} | 7d: ${seven_d_display}"

# --- Line 5: セッションコスト・時間(JSONから直接取得) ---
session_cost=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
duration_ms=$(echo "$input" | jq -r '.cost.total_duration_ms // 0')

if awk "BEGIN{exit !($session_cost > 0)}" 2>/dev/null; then
  cost_fmt=$(printf "\$%.4f" "$session_cost")
else
  cost_fmt="None"
fi

duration_sec=$((duration_ms / 1000))
duration_min=$((duration_sec / 60))
duration_sec_rem=$((duration_sec % 60))
if [ "$duration_min" -gt 0 ]; then
  duration_fmt="${duration_min}m ${duration_sec_rem}s"
else
  duration_fmt="${duration_sec_rem}s"
fi
echo "🔌 Session: ${cost_fmt} | ⏱️ ${duration_fmt}"

# --- Line 6: GitHub PR ---
if [ -n "$branch" ] && command -v gh >/dev/null 2>&1; then
  pr=$(gh pr view --json number -q '.number' 2>/dev/null)
  if [ -n "$pr" ]; then
    echo "🔗 PR #${pr}"
  else
    echo "🔗 PR None"
  fi
elif [ -n "$branch" ]; then
  echo "🔗 PR (gh not installed)"
fi

settings.jsonへ追加

~/.claude/settings.jsonに以下内容を追加
(ファイルの配置場所を変えたら適宜変更してください)

"statusLine": {
  "type": "command",
  "command": "bash /Users/${ユーザーディレクトリ}/.claude/statusline-command.sh"
}

おわりに

いかがだったでしょうか。
色々とカスタマイズが出来るので、是非自分に合った設定を試してみてください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?