Skip to content

原文(日本語に翻訳)

ステータスラインコマンドをN秒ごとに再実行するrefreshIntervalステータスライン設定を追加しました。

原文(英語)

Added refreshInterval status line setting to re-run the status line command every N seconds

概要

Claude Codeのステータスラインは従来、会話の変化をトリガーに更新されていました。新たにrefreshInterval設定が追加され、指定した秒数ごとにステータスラインコマンドを自動再実行できるようになりました。これにより、時刻・システムリソース使用率・外部APIの状態など、会話とは独立したリアルタイム情報をステータスラインに表示できます。

基本的な使い方

settings.jsonstatusLineセクションにrefreshInterval(秒単位)を追加します。

json
{
  "statusLine": {
    "command": "echo '{\"text\": \"'$(date +%H:%M:%S)'\"}'",
    "refreshInterval": 5
  }
}

この例では5秒ごとにコマンドを再実行し、ステータスラインの時刻表示を更新します。

実践例

現在時刻の表示

json
{
  "statusLine": {
    "command": "printf '{\"text\": \"%s\"}' \"$(date '+%Y-%m-%d %H:%M:%S')\"",
    "refreshInterval": 1
  }
}

CPU・メモリ使用率のモニタリング

bash
#!/bin/bash
# ~/.config/claude/statusline.sh
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)
MEM=$(free | awk '/Mem:/ {printf "%.0f", $3/$2*100}')
echo "{\"text\": \"CPU: ${CPU}% | MEM: ${MEM}%\"}"
json
{
  "statusLine": {
    "command": "~/.config/claude/statusline.sh",
    "refreshInterval": 10
  }
}

外部サービスの状態確認

bash
#!/bin/bash
# Gitリモートの同期状態をポーリング
STATUS=$(git fetch --dry-run 2>&1 | grep -c "origin" || echo "0")
if [ "$STATUS" -gt "0" ]; then
  echo '{"text": "↓ 更新あり", "color": "yellow"}'
else
  echo '{"text": "✓ 同期済み", "color": "green"}'
fi
json
{
  "statusLine": {
    "command": "~/.config/claude/git-sync-status.sh",
    "refreshInterval": 30
  }
}

APIコスト・レート制限の監視

bash
#!/bin/bash
# カスタムスクリプトでAPIの使用状況を定期取得
USAGE=$(curl -s https://internal-api/usage | jq -r '.cost')
echo "{\"text\": \"API: $USAGE\"}"
json
{
  "statusLine": {
    "command": "~/.config/claude/api-monitor.sh",
    "refreshInterval": 60
  }
}

注意点

  • refreshIntervalの値は秒単位で指定します。過度に短い間隔(1秒未満など)はサポートされません。
  • 重いコマンドを短い間隔で実行するとシステムリソースに影響する場合があります。適切な間隔を設定してください。
  • ステータスラインコマンドはJSON形式({"text": "表示テキスト"})を標準出力に出力する必要があります。
  • refreshIntervalを設定しない場合、従来通り会話イベントをトリガーとした更新のみが行われます。

関連情報