Chuyển tới nội dung chính
Dev Templates
Dev Experience3 phút đọc

Tùy biến statusline cho Claude Code trong 3 bước: model, chi phí, rate limit, branch

Một script shell ngắn hiển thị model đang dùng, context đã xài, chi phí session, rate limit 5h và branch git — chạy nhiều Claude session song song không bị lạc.

Bởi Phạm Thanh Tùng

Khi mở 3-4 Claude Code session ở các worktree khác nhau, chuyện thường xuyên là: nhầm terminal, không biết đang ăn bao nhiêu token, đến khi gặp rate limit mới hay. Giải pháp đơn giản nhất là thêm một dòng statusline ở đáy terminal, tự update theo mỗi tin nhắn.

Tài liệu chính thức của Anthropic (code.claude.com/docs/en/statusline) mô tả đầy đủ cách Claude Code đẩy JSON vào script và các field có sẵn. Dưới đây là phiên bản setup gọn — copy-paste là chạy.

Yêu cầu

Claude Code phiên bản 1.2.80+ (để có data rate limit), jq để parse JSON (brew install jq trên macOS), và git — gần như máy dev nào cũng có sẵn.

Bước 1: Tải script

curl -o ~/.claude/statusline-command.sh \
  https://raw.githubusercontent.com/danielmackay/claude-code-statusline/main/statusline-command.sh
chmod +x ~/.claude/statusline-command.sh

Bước 2: Cấu hình `settings.json`

Mở (hoặc tạo mới) ~/.claude/settings.json:

nano ~/.claude/settings.json

Rồi thêm khối statusLine:

{
  "statusLine": {
    "type": "command",
    "command": "sh ~/.claude/statusline-command.sh",
    "padding": 0
  }
}

Bước 3: Restart Claude Code

Đóng và mở lại session. Statusline sẽ hiện ở đáy cửa sổ sau tin nhắn đầu tiên, dạng:

🤖 Claude Sonnet 4.6 | 🧠 12% | 💰 $0.04 | ⏱️ 5h ████░░░░░░ 42% resets 2:00PM
🌳 my-app-payments | 🌿 feature/payments +42 -7

Dòng 1: model, % context đã dùng, cost session, progress bar rate limit 5 giờ + giờ reset. Dòng 2: tên worktree, branch, lines added/removed trong session.

Tùy biến thêm

Script đọc JSON Claude Code đẩy vào mỗi lần update (có model.display_name, context_window.used_percentage, cost.total_cost_usd, worktree.name, rate_limits.five_hour.used_percentage...) rồi printf ra. Muốn thêm/bớt field thì sửa thẳng file .sh — không có config riêng.

Rate limit 7 ngày (rl_7d_pct) được comment sẵn trong script. Bỏ comment nếu muốn thấy cả số này.

Xem thêm

Tài liệu đầy đủ về schema JSON, hook, và các kiểu statusline khác có tại Claude Code — Statusline. Nếu cần dashboard đầy đủ hơn (lịch sử, multi-session), tham khảo thêm ccusage hoặc ccstatusline.

Thẻ

  • Claude Code
  • AI
  • Productivity
  • Terminal

Bài viết khác