Claude Code 상태라인 - 3줄로 비용, 사용량·모델까지 한눈에!

목차
📌 이런 분들께 추천
- Claude Code 쓰면서 사용량 / 비용 / 리셋 시간 헷갈리는 분
- 터미널에서 깔끔한 상태 UI 만들고 싶은 개발자
- “와 이거 뭐야?” 소리 듣고 싶은 개발 감성충(?)
Quick Start
아래 실제 코드부분을 복사한후 다음과 같이 명령
아래 코드를 이용해서 statusline 설정해줘. [아래 코드 복사]한 줄 요약
Claude Code의 JSON 상태를 파싱해서
👉 디렉토리 / 모델 / 버전 / 사용량 / 비용을
👉 이모지 + 컬러 + 프로그레스바로 예쁘게 보여주는 statusline 스크립트입니다.
이 스크립트가 하는 일
이 statusline은 단순 출력이 아니라 꽤 똑똑합니다:
JSON → 환경변수 자동 파싱
- Node.js로 stdin JSON을 읽어서
- 필요한 값만 export 처리
👉 모델, 사용량, 비용, 리셋 시간까지 전부 자동 추출
디렉토리 표시 최적화
- 홈 디렉토리는
~로 치환 - 긴 경로도 깔끔하게 표시
감성 터지는 프로그레스 바
- 사용량 퍼센트 기반 컬러 변경
- 🟢 0~49% → 여유
- 🟡 50~79% → 주의
- 🔴 80% 이상 → 위험
- 이모지까지 자동 변경 (✨ ⚡ 🔥)
리셋 시간 계산
- 남은 시간 자동 계산
5h,7d각각 따로 표시
비용 + 시간당 비용 계산
- 총 사용 비용
- 시간당 비용($/h)까지 계산
👉 “이거 너무 비싼데?” 바로 감지 가능
실제 코드
아래는 실제로 사용하는 스크립트입니다
#!/bin/bash
# Claude Code 3-line statusline with emojis
input=$(cat)
# JSON parsing via node
eval "$(echo "$input" | node -e "
const d = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
const e = (k,v) => console.log('export ' + k + '=' + JSON.stringify(String(v ?? '')));
e('MODEL', d.model?.display_name ?? '—');
e('CWD', d.workspace?.current_dir ?? '—');
e('VERSION', d.version ?? '—');
e('CTX_PCT', d.context_window?.used_percentage ?? '');
e('RATE_5H', d.rate_limits?.five_hour?.used_percentage ?? '');
e('RATE_7D', d.rate_limits?.seven_day?.used_percentage ?? '');
e('COST_USD', d.cost?.total_cost_usd ?? 0);
e('DURATION_MS', d.cost?.total_duration_ms ?? 0);
// Calculate reset remaining
const now = Date.now() / 1000;
const fmt = (s) => {
if (!s || s <= 0) return '';
const d = Math.floor(s / 86400);
const h = Math.floor((s % 86400) / 3600);
const m = Math.floor((s % 3600) / 60);
if (d > 0) return d + 'd ' + h + 'h';
if (h > 0) return h + 'h ' + String(m).padStart(2,'0') + 'm';
return m + 'm';
};
const r5 = d.rate_limits?.five_hour?.resets_at;
const r7 = d.rate_limits?.seven_day?.resets_at;
e('RESET_5H', r5 ? fmt(r5 - now) : '');
e('RESET_7D', r7 ? fmt(r7 - now) : '');
" 2>/dev/null)"
# ── Directory with ~ substitution ──
DISPLAY_DIR="$CWD"
if [ "$CWD" = "$HOME" ]; then
DISPLAY_DIR="~"
elif [[ "$CWD" == "$HOME/"* ]]; then
DISPLAY_DIR="~${CWD#$HOME}"
fi
# ── ANSI colors ──
RST="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"
BLUE="\033[38;5;75m"
GREEN="\033[38;5;114m"
YELLOW="\033[38;5;222m"
MAGENTA="\033[38;5;177m"
CYAN="\033[38;5;116m"
RED="\033[38;5;204m"
GREY="\033[38;5;240m"
WHITE="\033[38;5;252m"
ORANGE="\033[38;5;215m"
PINK="\033[38;5;211m"
# ── Progress bar (rounded style) ──
progress_bar() {
local pct=${1:-0}
local width=${2:-12}
local pct_int=$(printf "%.0f" "$pct" 2>/dev/null || echo 0)
local color="$GREEN"
local glow="✨"
if [ "$pct_int" -ge 80 ] 2>/dev/null; then
color="$RED"; glow="🔥"
elif [ "$pct_int" -ge 50 ] 2>/dev/null; then
color="$YELLOW"; glow="⚡"
fi
# Round properly: add 50 before dividing to avoid always rounding down
local filled=$(( (pct_int * width + 50) / 100 ))
[ "$filled" -gt "$width" ] && filled=$width
[ "$pct_int" -gt 0 ] && [ "$filled" -eq 0 ] && filled=1
local empty=$(( width - filled ))
local bar_f="" bar_e=""
for ((i=0; i<filled; i++)); do bar_f+="▓"; done
for ((i=0; i<empty; i++)); do bar_e+="░"; done
printf "${GREY}[${color}%s${GREY}%s]${RST} ${color}%3d%%${RST} %s" "$bar_f" "$bar_e" "$pct_int" "$glow"
}
# ══════════════════════════════════════════════════
# Line 1: 📁 Directory · 🤖 Model · 📦 Version
# ══════════════════════════════════════════════════
printf "📂 ${CYAN}${BOLD}%s${RST}" "$DISPLAY_DIR"
printf " ${GREY}·${RST} "
printf "🤖 ${MAGENTA}${BOLD}%s${RST}" "$MODEL"
printf " ${GREY}·${RST} "
printf "📦 ${BLUE}v%s${RST}" "$VERSION"
printf "\n"
# ══════════════════════════════════════════════════
# Line 2: 📊 Usage progress bars
# ══════════════════════════════════════════════════
printf "📊 "
# 5h usage rate
printf "⏳ ${WHITE}usage${RST} "
if [ -n "$RATE_5H" ]; then
progress_bar "$RATE_5H" 16
if [ -n "$RESET_5H" ]; then
printf " ${GREY}↻ ${RST}${CYAN}%s${RST}" "$RESET_5H"
fi
else
printf "${DIM}─────────${RST} "
fi
printf " ${GREY}│${RST} "
# 7d week rate
printf "📅 ${WHITE}week${RST} "
if [ -n "$RATE_7D" ]; then
progress_bar "$RATE_7D" 16
if [ -n "$RESET_7D" ]; then
printf " ${GREY}↻ ${RST}${CYAN}%s${RST}" "$RESET_7D"
fi
else
printf "${DIM}─────────${RST} "
fi
printf "\n"
# ══════════════════════════════════════════════════
# Line 3: 💰 Cost
# ══════════════════════════════════════════════════
if [ "$DURATION_MS" -gt 0 ] 2>/dev/null; then
DURATION_H=$(awk "BEGIN {printf \"%.4f\", $DURATION_MS / 3600000}")
COST_PER_H=$(awk "BEGIN {v=$COST_USD/$DURATION_H; if(v>999) printf \"%.0f\", v; else if(v>10) printf \"%.1f\", v; else printf \"%.2f\", v}")
COST_FMT=$(awk "BEGIN {v=$COST_USD; if(v>10) printf \"%.2f\", v; else if(v>1) printf \"%.3f\", v; else printf \"%.4f\", v}")
printf "💰 ${GREEN}${BOLD}\$%s${RST} ${GREY}total${RST} ${GREY}·${RST} ⏱️ ${ORANGE}${BOLD}\$%s${RST}${GREY}/h${RST}" "$COST_FMT" "$COST_PER_H"
else
printf "💰 ${DIM}waiting for first response...${RST}"
fi
printf "\n"

댓글 0개
등록된 댓글이 없습니다.