Building a Multi-Provider Statusline for Claude Code

Building a Multi-Provider Statusline for Claude Code

A practical guide to setting up, extending, and automating a custom Claude Code statusline that works across Anthropic, GLM, DeepSeek, and Kimi.

Ad - In Article In-Article Ad (Auto) Google AdSense

If you use Claude Code daily, you know how important it is to keep track of your context window, token usage, git status, and rate limits. By default, Claude Code talks to Anthropic - but today, many engineers route it through alternative providers like GLM (z.ai / BigModel), DeepSeek, or Kimi (Moonshot) instead.

In this guide, I’ll break down how the Claude Code statusline works under the hood, how to set one up manually, and how to use an LLM to extend it with support for new providers.

How the Claude Code Statusline Works

Claude Code lets you point the statusline at a custom command. Whenever a response completes, Claude Code runs that command and feeds it a JSON payload over stdin.

1. Stdin input

Claude Code passes useful metadata to your statusline script via stdin:

{
  "model": {
    "display_name": "GLM-5.2"
  },
  "context_window": {
    "context_window_size": 1000000,
    "current_usage": {
      "input_tokens": 50000,
      "cache_creation_input_tokens": 0,
      "cache_read_input_tokens": 0
    }
  },
  "cwd": "/Users/developer/project",
  "rate_limits": {
    "five_hour": { "used_percentage": 20, "resets_at": 1785766680 },
    "seven_day": { "used_percentage": 5, "resets_at": 1786262468 }
  }
}

2. Stdout output

Your script reads stdin, formats a single string with ANSI colors, and prints it to stdout - that’s the banner shown at the top of this post: model, git diff, context usage, effort level, and 5h/7d rate limits, all in one line.

The challenge: every provider is different

Different LLM providers expose usage and billing data in completely different ways:

ProviderAuthenticationUsage / Quota EndpointData Format
AnthropicOAuth / Bearerapi.anthropic.com/api/oauth/usage5h / 7d sliding windows + Extra Credits
GLM (z.ai)ANTHROPIC_AUTH_TOKENapi.z.ai/api/monitor/usage/quota/limit5h / 7d limits + Epoch ms timestamps
DeepSeekANTHROPIC_AUTH_TOKENapi.deepseek.com/user/balanceLive currency balance (e.g. ¥88.50)
Kimi (Moonshot)ANTHROPIC_AUTH_TOKENapi.moonshot.cn/v1/users/me/balanceAccount available balance (e.g. ¥100.00)

A robust statusline detects which provider you’re on from ANTHROPIC_BASE_URL and formats the bar accordingly, instead of hard-coding one provider’s quirks.

Guide 1: Manual setup

Step 1: Install the statusline script

Run the one-liner installer:

curl -fsSL https://raw.githubusercontent.com/trongdth/ClaudeCodeStatusLine/main/install.sh | bash

Or place statusline.sh in ~/.claude/statusline.sh yourself:

mkdir -p ~/.claude
curl -fsSL https://raw.githubusercontent.com/trongdth/ClaudeCodeStatusLine/main/statusline.sh -o ~/.claude/statusline.sh
chmod +x ~/.claude/statusline.sh

Step 2: Configure ~/.claude/settings.json

Add a statusLine block to your settings file:

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

Provider configuration examples

Standard Anthropic - no extra env vars needed:

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

GLM / z.ai:

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "your-zai-api-key",
    "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.2[1m]"
  },
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh"
  }
}

DeepSeek:

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-your-deepseek-key",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_MODEL": "deepseek-v4-flash"
  },
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh"
  }
}

Guide 2: Extending it with an LLM

Want to add a new provider - Ollama, OpenRouter, Together AI - without hand-writing the parsing logic? Hand the spec to an AI coding assistant and let it write the extension.

1. A prompt template you can reuse

I want to add support for a new provider [Provider Name] to my statusline.sh script.

Provider details:
- Domain host in ANTHROPIC_BASE_URL: [e.g. api.openrouter.ai]
- Auth header: Authorization: Bearer $ANTHROPIC_AUTH_TOKEN
- Quota API URL: [e.g. https://openrouter.ai/api/v1/credits]
- Response structure: {"data": {"total_credits": 50, "total_usage": 12.5}}

Requirements:
1. Add host detection for [domain] under base_host parsing.
2. Implement 60-second file caching in /tmp/claude/ to prevent API rate limits.
3. Render formatted usage/balance output in ANSI colors.
4. Add a test case to statusline.test.sh to verify offline hermetic behavior.

2. Write hermetic tests first

Network calls slow down test suites and make them flaky. Use a small TDD harness that pipes mock JSON into stdin and seeds temporary cache files under /tmp/claude/, so the whole suite runs offline:

# Seed mock provider cache
seed_myprovider_cache() {
    printf '%s' '{"balance": 42.50}' > /tmp/claude/statusline-myprovider-cache.json
}

echo "CASE: MyProvider balance render"
SL_BASE_URL="https://api.myprovider.com/v1" SL_AUTH="test-token"
seed_myprovider_cache
out=$(render '{"model":{"display_name":"Custom-Model"},"context_window":{"context_window_size":100000}}')

assert_contains "renders balance" "$out" "balance"
assert_contains "renders amount"  "$out" "42.50"

Design principles that keep it fast and reliable

The statusline command runs after every single response, so a slow or fragile script drags down the whole CLI. A few rules keep it snappy:

  1. Short-circuit early. If stdin is empty, print a default fallback (e.g. Claude) and exit 0 immediately.
  2. Cache per host, on disk. Cache external API responses in /tmp/claude/ for 60 seconds. Polling a provider’s quota API on every prompt without caching gets you rate-limited fast.
  3. Guard against stampedes. touch the cache file before firing curl, so multiple open tmux/iTerm panes don’t all trigger concurrent requests at once.
  4. Stay cross-platform. Wrap date formatting in a helper that falls back between GNU date (Linux) and BSD date (macOS).
  5. Fail quietly. If a network call fails or the base URL doesn’t match a known provider, hide the usage segment - but keep showing model, context usage, git diff, and effort level.

Conclusion

A good statusline gives you constant visibility into your AI workflow, no matter which model or provider is behind it. The setup above covers Anthropic, GLM, DeepSeek, and Kimi out of the box, and the LLM-assisted workflow makes adding the next provider a five-minute task instead of an afternoon of reading API docs.

Fork it, add your own provider adapters, and contribute back.

Ad - After Content Rectangle Ad (300×250) Google AdSense

Categories:

Comments (0)

Loading comments...