cd /news/developer-tools/a-premium-developer-s-guide-to-runni… Β· home β€Ί topics β€Ί developer-tools β€Ί article
[ARTICLE Β· art-75242] src=gist.github.com β†— pub= topic=developer-tools verified=true sentiment=Β· neutral

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.

read6 min views21 publishedJul 15, 2026

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 & ComparisonStep 1: Get Your API CredentialsStep 2: Install Claude Code CLIStep 3: Configuration TemplatesQuick Switcher ScriptStep 4: Running Claude CodeTroubleshooting & 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)Featured Modelsclaude-opus-4-8

, glm-5.2

DeepSeek-V4-Pro

, DeepSeek-V4-Flash

, glm-5.2

Trial Credit****Base URLhttps://agentrouter.org

https://api.hcnsec.cn

  • Sign up on your chosen platform:

AgentRouter:https://bit.ly/3Tf0TJj** HCNSEC (with referral - Get bonus):**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:
 #!/data/data/com.termux/files/usr/bin/bash

 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'

 CONFIG_DIR="$HOME/.claude"
 SETTINGS_FILE="$CONFIG_DIR/settings.json"
 KEYS_FILE="$CONFIG_DIR/keys.conf"

 mkdir -p "$CONFIG_DIR"

 DEFAULT_AGENTROUTER_MODEL="claude-opus-4-8"
 DEFAULT_HCNSEC_MODEL="glm-5.2"

 if [ -f "$KEYS_FILE" ]; then
     source "$KEYS_FILE"
 fi

 if [ -z "$AGENTROUTER_MODEL" ]; then
     AGENTROUTER_MODEL=$DEFAULT_AGENTROUTER_MODEL
 fi
 if [ -z "$HCNSEC_MODEL" ]; then
     HCNSEC_MODEL=$DEFAULT_HCNSEC_MODEL
 fi

 save_config() {
     cat << EOF > "$KEYS_FILE"
 AGENTROUTER_KEY="$AGENTROUTER_KEY"
 HCNSEC_KEY="$HCNSEC_KEY"
 AGENTROUTER_MODEL="$AGENTROUTER_MODEL"
 HCNSEC_MODEL="$HCNSEC_MODEL"
 EOF
 }

 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 <nama_model>${RESET} : Ubah model AgentRouter"
     echo -e "  ${GREEN}switch-claude --model 2 <nama_model>${RESET} : Ubah model HCNSEC"
     echo -e "  ${GREEN}switch-claude --reset${RESET}            : Hapus kunci API yang disimpan"
     echo ""
     exit 1
 }

 if [ "$1" == "--reset" ]; then
     rm -f "$KEYS_FILE"
     echo -e "${RED}Konfigurasi yang disimpan telah dihapus!${RESET}"
     echo -e "${YELLOW}Silakan jalankan script kembali untuk memulai ulang.${RESET}"
     exit 0
 fi

 if [ "$1" == "--model" ]; then
     if [ "$2" == "1" ] || [ "$2" == "agentrouter" ]; then
         if [ -n "$3" ]; then
             AGENTROUTER_MODEL="$3"
             save_config
             echo -e "${GREEN}Model AgentRouter berhasil diubah menjadi: ${YELLOW}$3${RESET}"
             exit 0
         else
             echo -e "${RED}Harap sebutkan nama modelnya. Contoh: switch-claude --model 1 claude-opus-4-7${RESET}"
             exit 1
         fi
     elif [ "$2" == "2" ] || [ "$2" == "hcnsec" ]; then
         if [ -n "$3" ]; then
             HCNSEC_MODEL="$3"
             save_config
             echo -e "${GREEN}Model HCNSEC berhasil diubah menjadi: ${YELLOW}$3${RESET}"
             exit 0
         else
             echo -e "${RED}Harap sebutkan nama modelnya. Contoh: switch-claude --model 2 DeepSeek-V4-Flash${RESET}"
             exit 1
         fi
     else
         show_usage
     fi
 fi

 PROVIDER=""
 if [ "$1" == "1" ] || [ "$1" == "agentrouter" ]; then
     PROVIDER="agentrouter"
 elif [ "$1" == "2" ] || [ "$1" == "hcnsec" ]; then
     PROVIDER="hcnsec"
 elif [ -n "$1" ]; then
     show_usage
 else
     echo -e "${CYAN}β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”${RESET}"
     echo -e "${CYAN}β”‚${RESET}         ${BOLD}CLAUDE CODE PROVIDER SWITCHER CLI${RESET}            ${CYAN}β”‚${RESET}"
     echo -e "${CYAN}β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜${RESET}"
     echo -e "${BOLD}Pilih Provider:${RESET}"
     echo -e "  ${CYAN}[1]${RESET} AgentRouter (${BLUE}https://agentrouter.org${RESET})"
     echo -e "  ${CYAN}[2]${RESET} HCNSEC/IAMHC (${BLUE}https://api.hcnsec.cn${RESET})"
     echo ""
     read -p "Pilihan Anda (1/2): " pilihan
     if [ "$pilihan" == "1" ]; then
         PROVIDER="agentrouter"
     elif [ "$pilihan" == "2" ]; then
         PROVIDER="hcnsec"
     else
         echo -e "${RED}Pilihan tidak valid!${RESET}"
         show_usage
     fi
 fi

 if [ "$PROVIDER" == "agentrouter" ]; then
     AGENTROUTER_KEY=$(get_key "AgentRouter" "$AGENTROUTER_KEY")
     save_config
     
     cat << EOF > "$SETTINGS_FILE"
 {
   "env": {
     "ANTHROPIC_AUTH_TOKEN": "$AGENTROUTER_KEY",
     "ANTHROPIC_BASE_URL": "https://agentrouter.org",
     "ANTHROPIC_MODEL": "$AGENTROUTER_MODEL",
     "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
   },
   "permissions": {
     "allow": [],
     "deny": []
   },
   "skipWorkflowUsageWarning": true
 }
 EOF
     
     echo -e "\n${GREEN}BERHASIL DIUBAH!${RESET}"
     echo -e "Endpoint: ${CYAN}https://agentrouter.org${RESET}"
     echo -e "Model: ${YELLOW}$AGENTROUTER_MODEL${RESET}"
     echo -e "Jalankan ${GREEN}claude${RESET} untuk memulai."

 elif [ "$PROVIDER" == "hcnsec" ]; then
     HCNSEC_KEY=$(get_key "HCNSEC" "$HCNSEC_KEY")
     save_config
     
     cat << EOF > "$SETTINGS_FILE"
 {
   "env": {
     "ANTHROPIC_AUTH_TOKEN": "$HCNSEC_KEY",
     "ANTHROPIC_BASE_URL": "https://api.hcnsec.cn",
     "ANTHROPIC_MODEL": "$HCNSEC_MODEL",
     "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
   },
   "permissions": {
     "allow": [],
     "deny": []
   },
   "skipWorkflowUsageWarning": true
 }
 EOF
     
     echo -e "\n${GREEN}BERHASIL DIUBAH!${RESET}"
     echo -e "Endpoint: ${CYAN}https://api.hcnsec.cn${RESET}"
     echo -e "Model: ${YELLOW}$HCNSEC_MODEL${RESET}"
     echo -e "Jalankan ${GREEN}claude${RESET} untuk memulai."
 fi
  • Make it executable and globally link it:
chmod +x ~/.claude/switch-claude.sh
ln -sf ~/.claude/switch-claude.sh /data/data/com.termux/files/usr/bin/switch-claude

Interactive Mode: Simply runswitch-claude

and select option1

or2

.Quick Commands:- Switch to AgentRouter:switch-claude 1

(orswitch-claude agentrouter

) - Switch to HCNSEC:switch-claude 2

(orswitch-claude hcnsec

) Reset Saved Keys:switch-claude --reset

Once configured, simply run:

claude

The Claude Code interactive CLI terminal should start up immediately and connect to the proxy endpoint seamlessly.

Reason: You probably appended/v1

to the base URL in yoursettings.json

.Fix: Remove the/v1

suffix from yourANTHROPIC_BASE_URL

parameter.

Reason 1: You might have pasted a Redemption Code (base64-like string ending in==

) directly into the config. Check the Step 1 instructions.Reason 2: The model configured inANTHROPIC_MODEL

is not bound to your proxy channel/tier. Double-check your proxy account balance.

Reason: Very old Claude Code versions (e.g.,0.2.x

) crash on newer Node versions (like Node 22/26) due to dependency issues.Fix: Upgrade to version2.1.112

or later which fixes the Node interpreter crash.

── more in #developer-tools 4 stories Β· sorted by recency
── more on @anthropic 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/a-premium-developer-…] indexed:0 read:6min 2026-07-15 Β· β€”