<h1 align="center"> Claude Code Statusline </h1>

<p align="center">
  <img src="https://img.shields.io/badge/Claude-191919?style=flat-square&logo=anthropic&logoColor=white" alt="Claude" />
  <img src="https://img.shields.io/badge/CLI-000000?style=flat-square&logo=windowsterminal&logoColor=white" alt="CLI" />
  <img src="https://img.shields.io/badge/Rust-000000?style=flat-square&logo=rust&logoColor=white" alt="Rust" />
  <img src="https://img.shields.io/badge/macOS-000000?style=flat-square&logo=apple&logoColor=white" alt="macOS" />
  <img src="https://img.shields.io/badge/Linux-FCC624?style=flat-square&logo=linux&logoColor=black" alt="Linux" />
</p>

A lightweight statusline for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) that shows where your context tokens are going and how much you're spending.

![Demo](demo.gif)

## Features

- ⚡ **Subagent tracking** - See how many background agents are running
- 📊 **Context breakdown** - Visual bar showing token usage by segment
- 💰 **Cost tracking** - Session and daily spending at a glance
- 🔀 **Git integration** - Branch, staged/unstaged changes, ahead/behind
- 🦀 **Language detection** - Auto-detects project language
- 📁 **Working directory** - Shows your current path

## Performance

Built in Rust with zero runtime dependencies. A statusline runs on every prompt, so speed matters.

| Metric | cc-statusline | Typical Node.js CLI |
|--------|---------------|---------------------|
| ⚡ Binary size | ~570KB | 50-100MB+ (with node_modules) |
| 🚀 Startup | <50ms | 200-500ms |
| 💾 Memory | <5MB | 30-100MB |

## What It Shows

```
[opus] ████████████████░░░░░░░░ 42% ⚡3 │ 2h 30m left │ $0.45 / $12.30 │ main ✚2 │ rust │ ~/dev/myproject
       ▲ context bar             ▲ subagents  ▲ time remaining  ▲ cost           ▲ git     ▲ lang  ▲ path
```

The colored bar shows your context usage at a glance:
- 🔵 **Blue** - Base system prompt (~5k tokens)
- 🩵 **Cyan** - Skills you've installed
- 🟣 **Magenta** - Enabled plugins
- 🟡 **Yellow** - MCP servers
- 🟢 **Green** - Your conversation
- ⬜ **Gray** - Available space

Subagent indicator:
- `⚡n` - Number of active background agents (hidden when 0)

Git status shows branch and working tree state:
- 🟢 **Green branch** - clean working tree
- 🔴 **Red branch** - dirty working tree
- `↑n` / `↓n` - commits ahead/behind upstream
- `✚n` - staged changes (green)
- `●n` - unstaged changes (red)
- `?n` - untracked files (dim)

Language is auto-detected from project files (Cargo.toml, package.json, go.mod, etc.)

Run `cc-statusline --legend` to see this in your terminal.

## Installation

### Shell script

```bash
curl -fsSL https://raw.githubusercontent.com/Demwunz/cc-statusline/main/install.sh | bash
```

### Homebrew

```bash
brew tap Demwunz/tap
brew install cc-statusline
```

### Debian/Ubuntu

Download from [releases](https://github.com/Demwunz/cc-statusline/releases):

```bash
# x86_64
sudo dpkg -i cc-statusline_0.1.0_amd64.deb

# ARM64
sudo dpkg -i cc-statusline_0.1.0_arm64.deb
```

### Cargo

```bash
cargo install cc-statusline
```

### From source

```bash
git clone https://github.com/Demwunz/cc-statusline.git
cd cc-statusline
cargo install --path .
```

## Setup

Add to your `~/.claude/settings.json`:

```json
{
  "statusLine": {
    "type": "command",
    "command": "cc-statusline"
  }
}
```

## How It Works

1. Claude Code pipes JSON to stdin with token counts and model info
2. The binary scans `~/.claude` for skills, plugins, and MCP servers
3. It reads `~/.claude/projects/**/*.jsonl` for daily cost totals
4. Outputs a single ANSI-colored line

## Configuration

Create `~/.config/cc-statusline/config.toml` to customize:

```toml
[format]
show_model = true
show_cost = true
show_daily_cost = true
bar_width = 24          # 0 = auto-detect
plan = "api"            # "api" (pay-per-token) or "max" (subscription)
plan_cost = 100.0       # Monthly cost of your Max plan (for savings calculation)
show_git = true         # Show git branch and status
show_lang = true        # Show detected language
show_cwd = true         # Show current working directory

[colors]
base = "blue"
skills = "cyan"
plugins = "magenta"
mcp = "yellow"
conversation = "green"
empty = "gray"

[cache]
ttl_seconds = 5
```

## Usage

```bash
# Normal mode - reads JSON from stdin (Claude Code sends this automatically)
echo '{"model":{"display_name":"Opus"},"context_window":{"total_input_tokens":50000,"total_output_tokens":10000,"context_window_size":200000},"cost":{"total_cost_usd":0.45,"total_duration_ms":5400000}}' | cc-statusline

# Show what the colors mean
cc-statusline --legend

# Version
cc-statusline --version
```

## License

MIT
