この記事は、筆者が Zennに投稿した記事 の転載です。
はじめに
Claude Code CLIのstatusLine機能を使うと、ターミナル下部に「モデル名」「コンテキスト使用率」「カレントディレクトリ」「Gitブランチ」などの情報を常時表示できます。
この記事では、設定ファイルをコピペするだけで使える設定方法を紹介します。
settings.jsonの場所
| OS | パス |
|---|---|
| Windows | %USERPROFILE%\.claude\settings.json |
| macOS/Linux | ~/.claude/settings.json |
ファイルが存在しない場合は、フォルダとファイルを新規作成してください。
設定コード(コピペ用)
以下をsettings.jsonに貼り付けてください。
{
"statusLine": {
"type": "command",
"command": "powershell -NoProfile -Command \"$input = $input | ConvertFrom-Json; $usage = $input.context_window.current_usage; $pct = 0; if ($usage -ne $null) { $current = $usage.input_tokens + $usage.cache_creation_input_tokens + $usage.cache_read_input_tokens; $size = $input.context_window.context_window_size; $pct = [math]::Floor($current * 100 / $size) }; $cwd = $input.workspace.current_dir; $model = $input.model.display_name; $gitBranch = ''; if (Test-Path (Join-Path $input.workspace.current_dir '.git')) { Push-Location $input.workspace.current_dir; $gitBranch = git branch --show-current 2>$null; Pop-Location; if ($gitBranch) { $gitBranch = ' | [branch] ' + $gitBranch } }; Write-Host -NoNewline ('[model] {0} | [ctx] {1}% | [dir] {2}{3}' -f $model, $pct, $cwd, $gitBranch)\""
}
}
表示例
[model] Sonnet | [ctx] 23% | [dir] C:\Projects\my-app | [branch] main
設定コードの解説
| 表示項目 | 取得元 | 説明 |
|---|---|---|
[model] |
$input.model.display_name |
使用中のモデル名 |
[ctx] |
$input.context_window.current_usage |
コンテキストウィンドウ使用率(%) |
[dir] |
$input.workspace.current_dir |
現在の作業ディレクトリ |
[branch] |
git branch --show-current |
Gitブランチ名(リポジトリ内のみ表示) |
コンテキスト使用率の計算式
使用率 = (input_tokens + cache_creation_input_tokens + cache_read_input_tokens) / context_window_size × 100
カスタマイズ例
例1: モデル名とコンテキストのみ(シンプル版)
{
"statusLine": {
"type": "command",
"command": "powershell -NoProfile -Command \"$input = $input | ConvertFrom-Json; $usage = $input.context_window.current_usage; $pct = 0; if ($usage -ne $null) { $current = $usage.input_tokens + $usage.cache_creation_input_tokens + $usage.cache_read_input_tokens; $size = $input.context_window.context_window_size; $pct = [math]::Floor($current * 100 / $size) }; $model = $input.model.display_name; Write-Host -NoNewline ('[{0}] ctx: {1}%' -f $model, $pct)\""
}
}
表示例: [Sonnet] ctx: 23%
例2: ディレクトリ名のみ表示(フルパスではなくフォルダ名)
{
"statusLine": {
"type": "command",
"command": "powershell -NoProfile -Command \"$input = $input | ConvertFrom-Json; $model = $input.model.display_name; $dir = Split-Path $input.workspace.current_dir -Leaf; Write-Host -NoNewline ('{0} | {1}' -f $model, $dir)\""
}
}
表示例: Sonnet | my-app
例3: macOS/Linux向け(bash版)
{
"statusLine": {
"type": "command",
"command": "bash -c 'input=$(cat); model=$(echo \"$input\" | jq -r \".model.display_name\"); dir=$(echo \"$input\" | jq -r \".workspace.current_dir\"); size=$(echo \"$input\" | jq -r \".context_window.context_window_size\"); usage=$(echo \"$input\" | jq \".context_window.current_usage\"); if [ \"$usage\" != \"null\" ]; then current=$(echo \"$usage\" | jq \".input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens\"); pct=$((current * 100 / size)); else pct=0; fi; branch=\"\"; if [ -d \"$dir/.git\" ]; then branch=\" | $(cd \"$dir\" && git branch --show-current 2>/dev/null)\"; fi; echo \"[$model] $pct% | $dir$branch\"'"
}
}
bash版を使用する場合は、jqコマンドのインストールが必要です。
利用可能なJSON入力データ
Claude Code CLIはstatusLineコマンドに以下のJSONデータを渡します。
{
"model": {
"id": "claude-sonnet-4-20250514",
"display_name": "Sonnet"
},
"workspace": {
"current_dir": "/current/working/directory",
"project_dir": "/original/project/directory"
},
"context_window": {
"context_window_size": 200000,
"current_usage": {
"input_tokens": 8500,
"output_tokens": 1200,
"cache_creation_input_tokens": 5000,
"cache_read_input_tokens": 2000
}
},
"cost": {
"total_cost_usd": 0.01234,
"total_duration_ms": 45000
},
"version": "1.0.80"
}
これらを組み合わせて、好みの表示にカスタマイズできます。