A premium developer's guide to running Claude Code CLI for free using AgentRouter and HCNSEC (IAMHC) API proxies. A developer's guide details how to run Anthropic's Claude Code CLI for free using third-party API proxy services AgentRouter and HCNSEC. The guide provides step-by-step instructions for installation, configuration, and troubleshooting across multiple platforms. A comprehensive, step-by-step developer's guide to installing, configuring, and running Anthropic's Claude Code CLI client on PC, Linux, macOS, and Termux using alternative compatible API endpoints. Overview & Comparison https://gist.github.com/starred.atom -overview--comparison Step 1: Get Your API Credentials https://gist.github.com/starred.atom -step-1-get-your-api-credentials Step 2: Install Claude Code CLI https://gist.github.com/starred.atom -step-2-install-claude-code-cli Step 3: Configuration Templates https://gist.github.com/starred.atom -step-3-configuration-templates Quick Switcher Script https://gist.github.com/starred.atom -quick-switcher-script-optional Step 4: Running Claude Code https://gist.github.com/starred.atom -running-claude-code Troubleshooting & Common Pitfalls https://gist.github.com/starred.atom %EF%B8%8F-troubleshooting--common-pitfalls Claude Code normally requires an active Claude Pro subscription or official Anthropic API keys. By routing requests through compatible third-party API proxy services, you can run Claude Code for free or at a significantly lower cost using alternative routing endpoints. | Feature | Provider A: AgentRouter | Provider B: HCNSEC formerly IAMHC | |---|---|---| Referral Link | Yes | HCNSEC Invite Link https://api.hcnsec.cn/register?aff=1vZv Featured Models claude-opus-4-8 , glm-5.2 DeepSeek-V4-Pro , DeepSeek-V4-Flash , glm-5.2 Trial Credit Base URL https://agentrouter.org https://api.hcnsec.cn - Sign up on your chosen platform: AgentRouter: https://bit.ly/3Tf0TJj https://bit.ly/3Tf0TJj HCNSEC with referral - Get bonus : https://api.hcnsec.cn/register?aff=1vZv https://api.hcnsec.cn/register?aff=1vZv - Navigate to the API Keys / Tokens 令牌 tab. - Generate a new API key. It should start with sk- . Important API Key vs. Redemption Code: If you have a token ending in == e.g. AXfq6y...== , this is a Redemption Code 兑换码 , not an API Key. You must redeem it in the portal Top Up - Redeem Code to add credits to your account first, then create a standard sk- key. Install Node.js on your system first. Then run the installation command: If you are running in a Termux environment, it is highly recommended to pin the version to 2.1.112 for the best compatibility and stability: npm install -g @anthropic-ai/claude-code@2.1.112 If you encounter shebang interpretation errors, run: termux-fix-shebang $ which claude Install the latest stable version: npm install -g @anthropic-ai/claude-code Open the Claude Code settings file using a terminal text editor: nano ~/.claude/settings.json Replace the file content with one of the following JSON templates. Make sure to paste your own API Key in ANTHROPIC AUTH TOKEN . { "env": { "ANTHROPIC AUTH TOKEN": "YOUR AGENTROUTER API KEY", "ANTHROPIC BASE URL": "https://agentrouter.org", "ANTHROPIC MODEL": "claude-opus-4-8", "CLAUDE CODE DISABLE NONESSENTIAL TRAFFIC": "1" }, "permissions": { "allow": , "deny": }, "skipWorkflowUsageWarning": true } { "env": { "ANTHROPIC AUTH TOKEN": "YOUR HCNSEC API KEY", "ANTHROPIC BASE URL": "https://api.hcnsec.cn", "ANTHROPIC MODEL": "DeepSeek-V4-Flash", "CLAUDE CODE DISABLE NONESSENTIAL TRAFFIC": "1" }, "permissions": { "allow": , "deny": }, "skipWorkflowUsageWarning": true } Warning Base URL Structure: Do NOT add /v1 at the end of the ANTHROPIC BASE URL e.g. use https://api.hcnsec.cn instead of https://api.hcnsec.cn/v1 . The Claude Code client automatically appends /v1/messages internally. If /v1 is present in your config, the client will try to call /v1/v1/messages which results in a 404 Not Found error. You can substitute the ANTHROPIC MODEL in your settings file with any of these exact model IDs: For AgentRouter: claude-opus-4-8 claude-opus-4-7 claude-opus-4-6 glm-5.2 For HCNSEC: DeepSeek-V4-Flash Highly Recommended for speed DeepSeek-V4-Pro glm-5.2 glm-5.1 glm-4.7 Kimi-K2.6 MiniMax-M3 If you use both providers and want to switch between them instantly without editing files manually, you can set up this helper CLI switcher script. - Create the script file: nano ~/.claude/switch-claude.sh - Paste the following script code: bash /data/data/com.termux/files/usr/bin/bash Color definitions RED='\e 1;31m' GREEN='\e 1;32m' YELLOW='\e 1;33m' BLUE='\e 1;34m' CYAN='\e 1;36m' BOLD='\e 1m' RESET='\e 0m' Configuration paths CONFIG DIR="$HOME/.claude" SETTINGS FILE="$CONFIG DIR/settings.json" KEYS FILE="$CONFIG DIR/keys.conf" Ensure config directory exists mkdir -p "$CONFIG DIR" Defaults DEFAULT AGENTROUTER MODEL="claude-opus-4-8" DEFAULT HCNSEC MODEL="glm-5.2" Load saved keys if they exist if -f "$KEYS FILE" ; then source "$KEYS FILE" fi Set models to defaults if not present if -z "$AGENTROUTER MODEL" ; then AGENTROUTER MODEL=$DEFAULT AGENTROUTER MODEL fi if -z "$HCNSEC MODEL" ; then HCNSEC MODEL=$DEFAULT HCNSEC MODEL fi Function to save keys and models save config { cat << EOF "$KEYS FILE" AGENTROUTER KEY="$AGENTROUTER KEY" HCNSEC KEY="$HCNSEC KEY" AGENTROUTER MODEL="$AGENTROUTER MODEL" HCNSEC MODEL="$HCNSEC MODEL" EOF } Prompt for key if not saved get key { local provider name=$1 local current key=$2 if -z "$current key" ; then echo -e "${YELLOW}Kunci API untuk $provider name belum disimpan.${RESET}" read -p "Masukkan API Key: " new key echo "$new key" else echo "$current key" fi } show usage { echo -e "${CYAN}┌────────────────────────────────────────────────────────┐${RESET}" echo -e "${CYAN}│${RESET} ${BOLD}CLAUDE CODE PROVIDER SWITCHER CLI${RESET} ${CYAN}│${RESET}" echo -e "${CYAN}└────────────────────────────────────────────────────────┘${RESET}" echo -e "${BOLD}Penggunaan:${RESET}" echo -e " ${GREEN}switch-claude 1${RESET} atau ${GREEN}agentrouter${RESET} : Beralih ke AgentRouter" echo -e " ${GREEN}switch-claude 2${RESET} atau ${GREEN}hcnsec${RESET} : Beralih ke HCNSEC/IAMHC" echo -e " ${GREEN}switch-claude --model 1