An open API service indexing awesome lists of open source software.

https://github.com/mysticaldevil/kime

A beautiful CLI tool to display your Kimi Code Console stats in the terminal.
https://github.com/mysticaldevil/kime

Last synced: 3 months ago
JSON representation

A beautiful CLI tool to display your Kimi Code Console stats in the terminal.

Awesome Lists containing this project

README

          

kime


Go
Kimi
License

> [!IMPORTANT]
> This project uses `encoding/json/v2`. You **must** build with `GOEXPERIMENT=jsonv2`.

A beautiful CLI tool to display your **Kimi Code Console** stats in the terminal.

---

## Features

- **Weekly Usage** – real-time API call
- **Rate Limit Details** – real-time API call
- **Usage Ratio** – real-time API call
- **Current Plan & Validity** – cached until the subscription expires
- **Model Permissions** – cached until the subscription expires
- Beautiful Unicode-box UI powered by [Lipgloss](https://github.com/charmbracelet/lipgloss)
- Automatic ASCII fallback for non-modern terminals, with environment overrides
- Multilingual output: **Chinese (default)**, Traditional Chinese, English, and Japanese
- Mock mode for safe testing without hitting real APIs

---

## Installation

### Via `go install`

```bash
GOEXPERIMENT=jsonv2 go install github.com/MysticalDevil/kime@latest
```

### Via `mise`

```bash
# using the Go backend
mise use -g go:github.com/MysticalDevil/kime@latest

# or using the GitHub backend (prebuilt binary)
mise use -g github:MysticalDevil/kime@latest
```

### Build from source

Unix-like:

```bash
git clone https://github.com/MysticalDevil/kime.git
cd kime
go mod tidy
GOEXPERIMENT=jsonv2 go build -o kime
```

Then move the binary to a directory in your `$PATH`:

```bash
mv kime ~/.local/bin/
```

Windows PowerShell:

```powershell
git clone https://github.com/MysticalDevil/kime.git
cd kime
go mod tidy
$env:GOEXPERIMENT = "jsonv2"
go build -o kime.exe .
New-Item -ItemType Directory -Force "$HOME\bin" | Out-Null
Move-Item .\kime.exe "$HOME\bin\kime.exe"
$env:Path = "$HOME\bin;$env:Path"
```

Windows binary name: `kime.exe`

### Developer commands

This repository uses `just` as the task runner:

```bash
just fmt # format with gofumpt
just fmt-check # verify formatting only
just lint # run golangci-lint with --fix
just lint-check # CI-style lint check
just test # run the full test suite
just coverage # enforce the coverage gate
just check # fmt + lint-check + test + coverage
```

Current CI coverage gate: **73%** total coverage.

---

## Configuration

`kime` reads credentials from the platform config directory:

- Linux: `~/.config/kime/config.json`
- macOS: `~/Library/Application Support/kime/config.json`
- Windows: `%AppData%\kime\config.json`

The cache file is also platform-specific:

- Linux: `~/.cache/kime/membership.json`
- macOS: `~/Library/Caches/kime/membership.json`
- Windows: `%LocalAppData%\kime\membership.json`

Both files are created automatically when needed, or you can create them manually.

### Interactive setup

The easiest way to configure `kime` is via the built-in interactive wizard:

```bash
kime init
```

Windows PowerShell:

```powershell
.\kime.exe init
```

This will prompt you for your token and auto-extract `device_id`, `session_id`,
and `user_id` from the JWT payload. You can also set your preferred language and
other options. `kime init` requires an interactive terminal; non-TTY stdin returns a clear error.

### How to obtain credentials (DevTools)

1. Open [https://www.kimi.com/code/console?from=kfc_overview_topbar](https://www.kimi.com/code/console?from=kfc_overview_topbar) and log in.
2. Open **Developer Tools** (`F12` or `Ctrl+Shift+I`).
3. Go to the **Console** tab and run:

```javascript
copy(localStorage.getItem('access_token'))
```

This copies your JWT token to the clipboard. Paste it as the `token` field.
4. (Optional) If you want to fill the other fields manually, paste the token into
[jwt.io](https://jwt.io) to decode the payload, or run in Console:

```javascript
const parts = localStorage.getItem('access_token').split('.');
const payload = JSON.parse(atob(parts[1].replace(/-/g, '+').replace(/_/g, '/')));
console.log('device_id:', payload.device_id);
console.log('session_id (ssid):', payload.ssid);
console.log('user_id (sub):', payload.sub);
```

`kime` can auto-extract `device_id`, `session_id`, and `user_id` from the JWT, so providing only `token` is usually enough.

### Config file example

```json
{
"token": "eyJhbGciOiJIUzUxMiIs...",
"device_id": "1234567890123456789",
"session_id": "9876543210987654321",
"user_id": "your_user_id_here",
"language": "zh",
"show_progress": false
}
```

| Field | Description |
|-------|-------------|
| `token` | JWT access token (`kimi-auth` cookie or `access_token` in LocalStorage) |
| `device_id` | `x-msh-device-id` header value (auto-extracted from JWT if omitted) |
| `session_id` | `x-msh-session-id` header value (auto-extracted from JWT if omitted) |
| `user_id` | `x-traffic-id` header value, i.e. your user ID (auto-extracted from JWT if omitted) |
| `language` | UI language: `"zh"` (default), `"zh_TW"`, `"en"`, or `"ja"` |
| `show_progress` | Set to `true` to show usage cards as progress bars instead of plain numbers |

### Environment variables (override config)

| Variable | Description |
|----------|-------------|
| `KIME_TOKEN` | JWT token |
| `KIME_DEVICE_ID` | Device ID |
| `KIME_SESSION_ID` | Session ID |
| `KIME_USER_ID` | User ID |
| `KIME_LANG` | UI language: `zh`, `zh_TW`, `en`, or `ja` |
| `KIME_RENDER_MODE` | Render mode: `auto` (default), `unicode`, or `ascii` |
| `KIME_MOCK` | Set to `1` to enable mock mode (no real API calls) |
| `KIME_FORCE_REFRESH` | Set to `1` to force a full refresh and update cache |
| `KIME_CONFIG_DIR` | Override config directory path |
| `KIME_CACHE_DIR` | Override cache directory path |

If `device_id` or `user_id` is missing, `kime` will try to extract them from the JWT payload automatically.

ASCII rendering uses English labels and ASCII-only decorations so it remains readable in non-UTF-8 terminals.

When both config and environment variables are present, environment variables take precedence.

---

## Usage

```bash
# Show help
kime
kime --help

# Check stats (Chinese UI, default)
kime check

# English UI
KIME_LANG=en kime check # or set "language": "en" in config

# Mock mode (no network requests)
KIME_MOCK=1 kime check

# Force ASCII rendering
KIME_RENDER_MODE=ascii kime check

# Force refresh (bypass cache and update it)
KIME_FORCE_REFRESH=1 kime check
```

Windows PowerShell:

```powershell
.\kime.exe --help
.\kime.exe check
$env:KIME_LANG = "en"; .\kime.exe check
$env:KIME_MOCK = "1"; .\kime.exe check
$env:KIME_FORCE_REFRESH = "1"; .\kime.exe check
```

---

## Cache

- **Cache file**:
Linux `~/.cache/kime/membership.json`
macOS `~/Library/Caches/kime/membership.json`
Windows `%LocalAppData%\kime\membership.json`
- **TTL**: until `subscription.currentEndTime`
- "Current Plan", "Validity", and "Model Permissions" are served from cache when the subscription is still active.
- "Weekly Usage", "Rate Limit", and "Usage Ratio" are always fetched live.
- Set `KIME_FORCE_REFRESH=1` to bypass cache and force a full update.

---

## Platform Support

- Supported OS targets: Linux, macOS, Windows
- Windows target: Windows Terminal is the primary supported terminal
- Recommended Windows shell: PowerShell 7
- `cmd.exe` and legacy Windows consoles are not supported targets

---

## License

BSD 3-Clause License. See [LICENSE](./LICENSE) for details.