Chutes.ai Claude Code Setup Script

This script (chutes.sh) automates the installation and configuration of Claude Code for use with the Chutes.ai API. It handles Node.js setup, Claude Code installation, and API configuration with an interactive model selection interface.

Overview

The script performs the following tasks:

  1. Node.js Installation: Checks for Node.js (minimum v18) and installs v22 via nvm if needed
  2. Claude Code Installation: Installs or updates @anthropic-ai/claude-code globally
  3. API Configuration: Sets up your Chutes.ai API key and selects a model
  4. Environment Setup: Configures all necessary settings for Claude Code to work with Chutes.ai

Prerequisites

  • Operating System: Linux or macOS
  • Internet Connection: Required for downloading Node.js, nvm, and npm packages
  • Chutes.ai API Key: You'll need an API key from chutes.ai

Installation

Step 1: Download the Script

Ensure the script is executable:

chmod +x chutes.sh

Step 2: Run the Script

Execute the script:

./chutes.sh

The script will guide you through the installation process.

Installation Process

1. Node.js Setup

The script checks if Node.js is installed:

  • If Node.js v18+ is found: Uses the existing installation
  • If Node.js < v18 is found: Upgrades to Node.js v22
  • If Node.js is not found: Installs Node.js v22 using nvm (Node Version Manager)

The nvm version used is v0.40.3.

2. Claude Code Installation

The script installs or updates Claude Code:

  • If already installed: Updates to the latest version
  • If not installed: Installs @anthropic-ai/claude-code globally via npm

3. API Configuration

You'll be prompted to enter your Chutes.ai API key:

Enter your chutes.ai API key: [your-api-key]

4. Model Selection

The script fetches available models from the Chutes.ai API and displays them in a two-column format:

Available models (per 1M tokens: input/output):

   [TH] model-name-1                           $1.00/$2.00      [TH] model-name-2    $0.50/$1.00
        model-name-3                           $0.80/$1.50           model-name-4    $0.30/$0.80

Legend:

  • [TH] - Thinking models with enhanced reasoning capabilities
  • Pricing shown as $input_price/$output_price per 1M tokens

Select a model by entering its number:

Select a model (1-10) [default: 1]: 1

Configuration Files

The script creates/modifies the following files:

~/.claude/settings.json

Main configuration file containing:

  • model: Selected Claude model
  • alwaysThinkingEnabled: Set to true
  • env: Environment variables including:
    • ANTHROPIC_AUTH_TOKEN: Your Chutes.ai API key
    • ANTHROPIC_BASE_URL: https://claude.chutes.ai (proxy URL)
    • API_TIMEOUT_MS: 6000000 (100 minutes)
    • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1
    • Model defaults for Haiku, Sonnet, Opus, and subagent models

~/.claude.json

Contains onboarding status:

{
  "hasCompletedOnboarding": true
}

Using Claude Code

After installation, start Claude Code by running:

claude

This will launch the Claude Code interface with your configured Chutes.ai API and selected model.

Environment Variables

The script sets the following environment variables in the configuration:

Variable Value Description
ANTHROPIC_AUTH_TOKEN Your API key Authentication token for Chutes.ai API
ANTHROPIC_BASE_URL https://claude.chutes.ai Proxy base URL for API requests
API_TIMEOUT_MS 6000000 API request timeout (100 minutes)
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 1 Disables non-essential network traffic
ANTHROPIC_DEFAULT_HAIKU_MODEL Selected model Default model for Haiku
ANTHROPIC_DEFAULT_SONNET_MODEL Selected model Default model for Sonnet
ANTHROPIC_DEFAULT_OPUS_MODEL Selected model Default model for Opus
CLAUDE_CODE_SUBAGENT_MODEL Selected model Model for subagent operations
ANTHROPIC_SMALL_FAST_MODEL Selected model Small/fast model variant

Non-Interactive Mode

For automation purposes, you can run the script in non-interactive mode by setting the CLAUDE_NONINTERACTIVE environment variable:

CLAUDE_NONINTERACTIVE=1 ./chutes.sh

In non-interactive mode:

  • The first available model will be selected automatically
  • You'll still need to provide the API key interactively

Troubleshooting

Node.js Installation Fails

If Node.js installation fails, try:

# Remove existing nvm installation
rm -rf ~/.nvm

# Run the script again
./chutes.sh

API Key Issues

If you encounter API authentication errors:

  1. Verify your API key is correct
  2. Get a new API key from https://chutes.ai/app/api
  3. Re-run the script to update your configuration

Model Selection Fails

If the script cannot fetch available models:

  1. Check your internet connection
  2. Verify your API key is valid
  3. The script will fall back to the default model: deepseek-ai/DeepSeek-R1

Permission Errors

If you encounter permission errors:

# Ensure the script is executable
chmod +x chutes.sh

# Run with appropriate permissions
sudo ./chutes.sh

Claude Code Not Found

After installation, if claude command is not found:

# Reload your shell configuration
source ~/.bashrc   # for bash
# or
source ~/.zshrc    # for zsh

# Or add nvm to your PATH manually
export PATH="$HOME/.nvm:$PATH"
source "$HOME/.nvm/nvm.sh"

Manual Configuration

If you need to manually update your configuration after installation:

Update API Key

Edit ~/.claude/settings.json and update the ANTHROPIC_AUTH_TOKEN value.

Change Model

Edit ~/.claude/settings.json and update the model value and all model-related environment variables.

Re-run Configuration

You can re-run the script to update your configuration:

./chutes.sh

Script Constants

The following constants are defined in the script (lines 10-20):

Constant Value Description
NODE_MIN_VERSION 18 Minimum required Node.js version
NODE_INSTALL_VERSION 22 Node.js version to install
NVM_VERSION v0.40.3 Node Version Manager version
CLAUDE_PACKAGE @anthropic-ai/claude-code npm package name
CONFIG_DIR $HOME/.claude Configuration directory
CONFIG_FILE $HOME/.claude/settings.json Settings file path
PROXY_BASE_URL https://claude.chutes.ai Proxy API URL
BACKEND_BASE_URL https://llm.chutes.ai Backend API URL
API_TIMEOUT_MS 6000000 API timeout in milliseconds

Support

For issues related to:

  • Chutes.ai API: Visit chutes.ai
  • Claude Code: Check the official documentation
  • This script: Review the script comments or contact your system administrator

Credits

This script is based on the original version created by Z.AI. The original version using z.ai can be found at: https://cdn.bigmodel.cn/install/claude_code_zai_env.sh

License

Please refer to the original source for licensing information.

Description
No description provided
Readme 30 KiB
Languages
Shell 100%