Skip to content

CLI tool and Claude Code plugin for managing Z.AI (GLM) and MiniMax API providers. Switch between providers, manage multiple accounts, track usage, and rotate API keys.

Notifications You must be signed in to change notification settings

ImBIOS/coding-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

coding-helper - Z.AI & MiniMax API Manager for Claude Code

NPM Version NPM Downloads License Bun

A powerful CLI tool and Agent SDK wrapper for seamless management of Z.AI (GLM) and MiniMax API providers. Switch between providers, manage multiple accounts, track usage, rotate API keys, and use with Claude Code or Claude Agent SDK directly from your code.

What is coding-helper?

coding-helper is a developer utility that enables Claude Code users to switch between Z.AI (GLM) and MiniMax API providers without code changes. It provides:

  • Provider switching - Toggle between Z.AI and MiniMax instantly
  • Multi-account management - Configure and switch between multiple API accounts
  • API key rotation - Automatic rotation with configurable strategies
  • Usage tracking - Monitor quotas, costs, and consumption in real-time
  • Agent SDK integration - Use auto-rotation directly in your code
  • Claude Code wrapper - Spawn Claude with automatic provider switching

Features

Provider Management

Feature Description
Unified CLI Configure and switch providers with simple commands
Interactive Setup Guided configuration wizard
Multi-Account Support Manage multiple accounts per provider
API Key Rotation Round-robin, least-used, priority, or random strategies

Monitoring & Tracking

Feature Description
Real-time Usage Monitor API consumption from provider APIs
Usage History Visualize patterns over last 30 days
Cost Estimation Calculate costs for different models
Alert System Get notified when approaching limits

Developer Experience

Feature Description
Agent SDK Wrapper - Use auto-rotation in your code with @imbios/coding-helper/sdk
Claude Code Integration - Spawn claude command with auto-rotation
Shell Completion - Full tab completion for bash, zsh, fish
Web Dashboard - Visual monitoring on port 3456

Quick Start

Installation

# Install via npm
npm install -g @imbios/coding-helper

# Or via bun (recommended)
bun install -g @imbios/coding-helper

# Run directly with npx
npx @imbios/coding-helper config

Basic CLI Usage

# Add API accounts (uses provider's default model automatically)
cohe account add

# Switch between accounts
cohe account switch <account-id>

# Check status
cohe status

# View usage
cohe usage

Using with Claude Code

The cohe claude command spawns Claude Code with automatic provider/account rotation:

# Run claude with auto-rotation
cohe claude

# Pass through any claude arguments
cohe claude --continue
cohe claude --help

Behind the scenes, this sets all required environment variables according to official documentation:

For Z.AI:

ANTHROPIC_AUTH_TOKEN=<zai_api_key>
ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
ANTHROPIC_DEFAULT_OPUS_MODEL=GLM-4.7
ANTHROPIC_DEFAULT_SONNET_MODEL=GLM-4.7
ANTHROPIC_DEFAULT_HAIKU_MODEL=GLM-4.5-Air
ANTHROPIC_SMALL_FAST_MODEL=GLM-4.5-Air

For MiniMax:

ANTHROPIC_AUTH_TOKEN=<minimax_api_key>
ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic
ANTHROPIC_DEFAULT_OPUS_MODEL=MiniMax-M2.1
ANTHROPIC_DEFAULT_SONNET_MODEL=MiniMax-M2.1
ANTHROPIC_DEFAULT_HAIKU_MODEL=MiniMax-M2.1
ANTHROPIC_SMALL_FAST_MODEL=MiniMax-M2.1

Agent SDK Integration

Use the auto-rotation feature directly in your code with the Agent SDK wrapper:

Installation

npm install @imbios/coding-helper @anthropic-ai/claude-agent-sdk

Basic Usage

import { query } from "@imbios/coding-helper/sdk";

// Automatically rotates between accounts on each call
for await (const message of query({
  prompt: "Fix the bug in auth.py",
  options: {
    allowedTools: ["Read", "Edit", "Bash"],
    logRotation: true  // Log when rotation occurs
  }
})) {
  if (message.type === "result") {
    console.log(message.result);
  }
}

Advanced Usage

import {
  getAutoRotatedEnv,
  performAutoRotation,
  getActiveCredentials
} from "@imbios/coding-helper/sdk";
import { query as sdkQuery } from "@anthropic-ai/claude-agent-sdk";

// Option 1: Get rotated environment and use with original SDK
async function runWithRotation() {
  await performAutoRotation(); // Manually trigger rotation
  const env = await getAutoRotatedEnv(); // Get env vars for active account
  
  for await (const message of sdkQuery({
    prompt: "Write a React component",
    options: { env }
  })) {
    // Handle messages...
  }
}

// Option 2: Check current credentials before running
function checkBeforeRun() {
  const creds = getActiveCredentials();
  if (!creds) {
    console.error("No accounts configured!");
    return;
  }
  
  console.log(`Using: ${creds.provider} - ${creds.accountName}`);
  console.log(`Model: ${creds.model}`);
}

Rotation Strategies

Configure rotation strategy with:

# Enable rotation with specific strategy
cohe auto enable round-robin
cohe auto enable least-used --cross-provider
cohe auto enable random
cohe auto enable priority

# Disable rotation
cohe auto disable

# Check rotation status
cohe auto status

Available strategies:

  • round-robin - Cycle through accounts in order
  • least-used - Pick account with lowest API usage (fetches real data from provider)
  • priority - Pick highest priority account
  • random - Randomly select an account

Supported Models

Z.AI (GLM)

Model Tier Use Case
GLM-4.7 Opus Most capable, complex tasks
GLM-4.5-Air Haiku Fast, efficient responses

MiniMax

Model Tier Use Case
MiniMax-M2.1 All Latest flagship model

Commands Reference

Core Commands

Command Description
cohe account add Add new API account (auto-selects default model)
cohe account list List all configured accounts
cohe account switch <id> Switch to specific account
cohe account remove <id> Remove an account
cohe status Show current provider and status
cohe usage Query usage statistics from API
cohe history Show usage history (30 days)
cohe test Test API connection

Auto-Rotation Commands

Command Description
cohe auto enable [strategy] Enable auto-rotation
cohe auto disable Disable auto-rotation
cohe auto status Show rotation status
cohe auto rotate Manually trigger rotation

Provider Commands (Legacy)

Command Description
cohe config Interactive provider configuration
cohe switch <provider> Switch active provider (zai/minimax)

Other Commands

Command Description
cohe claude [args...] Spawn Claude with auto-rotation
cohe dashboard start [port] Start web dashboard
cohe alert list List usage alerts
cohe doctor Diagnose configuration issues
cohe completion <shell> Generate shell completion

Configuration

Configuration File

All accounts and settings are stored in ~/.claude/imbios.json:

{
  "version": "2.0.0",
  "accounts": {
    "acc_123": {
      "id": "acc_123",
      "name": "my-zai-account",
      "provider": "zai",
      "apiKey": "sk-...",
      "baseUrl": "https://api.z.ai/api/anthropic",
      "defaultModel": "GLM-4.7",
      "priority": 0,
      "isActive": true,
      "createdAt": "2025-01-01T00:00:00.000Z",
      "usage": {
        "used": 0.5,
        "limit": 100,
        "lastUpdated": "2025-01-01T12:00:00.000Z"
      }
    }
  },
  "activeAccountId": "acc_123",
  "rotation": {
    "enabled": true,
    "strategy": "round-robin",
    "crossProvider": true
  }
}

Environment Variables

coding-helper respects the following environment variables:

  • ZAI_API_KEY - Z.AI API key (for legacy provider config)
  • MINIMAX_API_KEY - MiniMax API key (for legacy provider config)
  • IMBIOS_CONFIG_PATH - Custom path to config file

Examples

Example 1: Basic Multi-Account Setup

# Add multiple accounts
cohe account add
# Enter name: work-zai
# Select provider: Z.AI (zai)
# Enter API key: sk-...
# (Model is auto-selected based on provider)

cohe account add
# Enter name: personal-minimax
# Select provider: MiniMax
# Enter API key: sk-...

# Enable cross-provider rotation
cohe auto enable random --cross-provider

# Use with Claude Code
cohe claude

Example 2: Using with Agent SDK

// my-script.ts
import { query } from "@imbios/coding-helper/sdk";

async function main() {
  for await (const message of query({
    prompt: "Analyze this codebase and suggest improvements",
    options: {
      allowedTools: ["Read", "Grep", "Bash"],
      logRotation: true
    }
  })) {
    if (message.type === "result") {
      console.log(message.result);
    }
  }
}

main();

Run with:

bun run my-script.ts

Example 3: Priority-Based Rotation

# Add accounts with different priorities
cohe account add  # priority 0 (default)
# Edit ~/.claude/imbios.json to set priorities:
# "priority": 10  # High priority account
# "priority": 1   # Medium priority account
# "priority": 0   # Low priority (fallback)

# Enable priority-based rotation
cohe auto enable priority

# Now it will always use the highest priority account

Requirements

  • Runtime: Bun 1.2.0+ or Node.js 18+
  • Shell: Bash, Zsh, or Fish
  • OS: Linux, macOS, Windows (WSL)

Technology Stack

  • Language: TypeScript (ES2022)
  • Runtime: Bun (primary), Node.js (fallback)
  • UI Framework: Ink (React for CLI)
  • Code Quality: Biome with Ultracite preset

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature-amazing-feature)
  5. Open a Pull Request

Support

Keywords

anthropic-api, claude-code, claude-agent-sdk, glm, minimax, api-client, cli-tool, provider-management, api-key-rotation, usage-tracking, auto-rotation, multi-account, developer-tools, ai-assistant, terminal-tool, zai-api, glmmodel, bun, typescript

About

CLI tool and Claude Code plugin for managing Z.AI (GLM) and MiniMax API providers. Switch between providers, manage multiple accounts, track usage, and rotate API keys.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Contributors 2

  •  
  •