{"slug": "a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec", "title": "A premium developer's guide to running Claude Code CLI for free using AgentRouter and HCNSEC (IAMHC) API proxies.", "summary": "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.", "body_md": "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.\n\n[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)\n\nClaude 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.\n\n| Feature | Provider A: AgentRouter | Provider B: HCNSEC (formerly IAMHC) |\n|---|---|---|\nReferral Link |\nYes (\n|\n\n[HCNSEC Invite Link](https://api.hcnsec.cn/register?aff=1vZv))**Featured Models**`claude-opus-4-8`\n\n, `glm-5.2`\n\n`DeepSeek-V4-Pro`\n\n, `DeepSeek-V4-Flash`\n\n, `glm-5.2`\n\n**Trial Credit****Base URL**`https://agentrouter.org`\n\n`https://api.hcnsec.cn`\n\n- Sign up on your chosen platform:\n\n**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)\n\n- Navigate to the\n**API Keys / Tokens (令牌)** tab. - Generate a new API key. It should start with\n`sk-`\n\n.\n\nImportant\n\n**API Key vs. Redemption Code:**\nIf you have a token ending in `==`\n\n(e.g. `AXfq6y...==`\n\n), 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-`\n\nkey.\n\nInstall Node.js on your system first. Then run the installation command:\n\nIf you are running in a Termux environment, it is highly recommended to pin the version to `2.1.112`\n\nfor the best compatibility and stability:\n\n```\nnpm install -g @anthropic-ai/claude-code@2.1.112\n```\n\nIf you encounter shebang interpretation errors, run:\n\n```\ntermux-fix-shebang $(which claude)\n```\n\nInstall the latest stable version:\n\n```\nnpm install -g @anthropic-ai/claude-code\n```\n\nOpen the Claude Code settings file using a terminal text editor:\n\n```\nnano ~/.claude/settings.json\n```\n\nReplace the file content with one of the following JSON templates. Make sure to paste your own API Key in `ANTHROPIC_AUTH_TOKEN`\n\n.\n\n```\n{\n \"env\": {\n  \"ANTHROPIC_AUTH_TOKEN\": \"YOUR_AGENTROUTER_API_KEY\",\n  \"ANTHROPIC_BASE_URL\": \"https://agentrouter.org\",\n  \"ANTHROPIC_MODEL\": \"claude-opus-4-8\",\n  \"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC\": \"1\"\n },\n \"permissions\": {\n  \"allow\": [],\n  \"deny\": []\n },\n \"skipWorkflowUsageWarning\": true\n}\n{\n \"env\": {\n  \"ANTHROPIC_AUTH_TOKEN\": \"YOUR_HCNSEC_API_KEY\",\n  \"ANTHROPIC_BASE_URL\": \"https://api.hcnsec.cn\",\n  \"ANTHROPIC_MODEL\": \"DeepSeek-V4-Flash\",\n  \"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC\": \"1\"\n },\n \"permissions\": {\n  \"allow\": [],\n  \"deny\": []\n },\n \"skipWorkflowUsageWarning\": true\n}\n```\n\nWarning\n\n**Base URL Structure:**\nDo **NOT** add `/v1`\n\nat the end of the `ANTHROPIC_BASE_URL`\n\n(e.g. use `https://api.hcnsec.cn`\n\ninstead of `https://api.hcnsec.cn/v1`\n\n).\nThe Claude Code client automatically appends `/v1/messages`\n\ninternally. If `/v1`\n\nis present in your config, the client will try to call `/v1/v1/messages`\n\nwhich results in a **404 Not Found** error.\n\nYou can substitute the `ANTHROPIC_MODEL`\n\nin your settings file with any of these exact model IDs:\n\n**For AgentRouter:**`claude-opus-4-8`\n\n`claude-opus-4-7`\n\n`claude-opus-4-6`\n\n`glm-5.2`\n\n**For HCNSEC:**`DeepSeek-V4-Flash`\n\n*(Highly Recommended for speed)*`DeepSeek-V4-Pro`\n\n`glm-5.2`\n\n`glm-5.1`\n\n`glm-4.7`\n\n`Kimi-K2.6`\n\n`MiniMax-M3`\n\nIf you use both providers and want to switch between them instantly without editing files manually, you can set up this helper CLI switcher script.\n\n- Create the script file:\n\n```\nnano ~/.claude/switch-claude.sh\n```\n\n- Paste the following script code:\n\n``` bash\n #!/data/data/com.termux/files/usr/bin/bash\n\n # Color definitions\n RED='\\e[1;31m'\n GREEN='\\e[1;32m'\n YELLOW='\\e[1;33m'\n BLUE='\\e[1;34m'\n CYAN='\\e[1;36m'\n BOLD='\\e[1m'\n RESET='\\e[0m'\n\n # Configuration paths\n CONFIG_DIR=\"$HOME/.claude\"\n SETTINGS_FILE=\"$CONFIG_DIR/settings.json\"\n KEYS_FILE=\"$CONFIG_DIR/keys.conf\"\n\n # Ensure config directory exists\n mkdir -p \"$CONFIG_DIR\"\n\n # Defaults\n DEFAULT_AGENTROUTER_MODEL=\"claude-opus-4-8\"\n DEFAULT_HCNSEC_MODEL=\"glm-5.2\"\n\n # Load saved keys if they exist\n if [ -f \"$KEYS_FILE\" ]; then\n     source \"$KEYS_FILE\"\n fi\n\n # Set models to defaults if not present\n if [ -z \"$AGENTROUTER_MODEL\" ]; then\n     AGENTROUTER_MODEL=$DEFAULT_AGENTROUTER_MODEL\n fi\n if [ -z \"$HCNSEC_MODEL\" ]; then\n     HCNSEC_MODEL=$DEFAULT_HCNSEC_MODEL\n fi\n\n # Function to save keys and models\n save_config() {\n     cat << EOF > \"$KEYS_FILE\"\n AGENTROUTER_KEY=\"$AGENTROUTER_KEY\"\n HCNSEC_KEY=\"$HCNSEC_KEY\"\n AGENTROUTER_MODEL=\"$AGENTROUTER_MODEL\"\n HCNSEC_MODEL=\"$HCNSEC_MODEL\"\n EOF\n }\n\n # Prompt for key if not saved\n get_key() {\n     local provider_name=$1\n     local current_key=$2\n     if [ -z \"$current_key\" ]; then\n         echo -e \"${YELLOW}Kunci API untuk $provider_name belum disimpan.${RESET}\"\n         read -p \"Masukkan API Key: \" new_key\n         echo \"$new_key\"\n     else\n         echo \"$current_key\"\n     fi\n }\n\n show_usage() {\n     echo -e \"${CYAN}┌────────────────────────────────────────────────────────┐${RESET}\"\n     echo -e \"${CYAN}│${RESET}         ${BOLD}CLAUDE CODE PROVIDER SWITCHER CLI${RESET}            ${CYAN}│${RESET}\"\n     echo -e \"${CYAN}└────────────────────────────────────────────────────────┘${RESET}\"\n     echo -e \"${BOLD}Penggunaan:${RESET}\"\n     echo -e \"  ${GREEN}switch-claude 1${RESET} (atau ${GREEN}agentrouter${RESET})  : Beralih ke AgentRouter\"\n     echo -e \"  ${GREEN}switch-claude 2${RESET} (atau ${GREEN}hcnsec${RESET})       : Beralih ke HCNSEC/IAMHC\"\n     echo -e \"  ${GREEN}switch-claude --model 1 <nama_model>${RESET} : Ubah model AgentRouter\"\n     echo -e \"  ${GREEN}switch-claude --model 2 <nama_model>${RESET} : Ubah model HCNSEC\"\n     echo -e \"  ${GREEN}switch-claude --reset${RESET}            : Hapus kunci API yang disimpan\"\n     echo \"\"\n     exit 1\n }\n\n # Handle reset flag\n if [ \"$1\" == \"--reset\" ]; then\n     rm -f \"$KEYS_FILE\"\n     echo -e \"${RED}Konfigurasi yang disimpan telah dihapus!${RESET}\"\n     echo -e \"${YELLOW}Silakan jalankan script kembali untuk memulai ulang.${RESET}\"\n     exit 0\n fi\n\n # Handle model change flag\n if [ \"$1\" == \"--model\" ]; then\n     if [ \"$2\" == \"1\" ] || [ \"$2\" == \"agentrouter\" ]; then\n         if [ -n \"$3\" ]; then\n             AGENTROUTER_MODEL=\"$3\"\n             save_config\n             echo -e \"${GREEN}Model AgentRouter berhasil diubah menjadi: ${YELLOW}$3${RESET}\"\n             exit 0\n         else\n             echo -e \"${RED}Harap sebutkan nama modelnya. Contoh: switch-claude --model 1 claude-opus-4-7${RESET}\"\n             exit 1\n         fi\n     elif [ \"$2\" == \"2\" ] || [ \"$2\" == \"hcnsec\" ]; then\n         if [ -n \"$3\" ]; then\n             HCNSEC_MODEL=\"$3\"\n             save_config\n             echo -e \"${GREEN}Model HCNSEC berhasil diubah menjadi: ${YELLOW}$3${RESET}\"\n             exit 0\n         else\n             echo -e \"${RED}Harap sebutkan nama modelnya. Contoh: switch-claude --model 2 DeepSeek-V4-Flash${RESET}\"\n             exit 1\n         fi\n     else\n         show_usage\n     fi\n fi\n\n # Parse argument\n PROVIDER=\"\"\n if [ \"$1\" == \"1\" ] || [ \"$1\" == \"agentrouter\" ]; then\n     PROVIDER=\"agentrouter\"\n elif [ \"$1\" == \"2\" ] || [ \"$1\" == \"hcnsec\" ]; then\n     PROVIDER=\"hcnsec\"\n elif [ -n \"$1\" ]; then\n     show_usage\n else\n     # Interactive menu if no argument\n     echo -e \"${CYAN}┌────────────────────────────────────────────────────────┐${RESET}\"\n     echo -e \"${CYAN}│${RESET}         ${BOLD}CLAUDE CODE PROVIDER SWITCHER CLI${RESET}            ${CYAN}│${RESET}\"\n     echo -e \"${CYAN}└────────────────────────────────────────────────────────┘${RESET}\"\n     echo -e \"${BOLD}Pilih Provider:${RESET}\"\n     echo -e \"  ${CYAN}[1]${RESET} AgentRouter (${BLUE}https://agentrouter.org${RESET})\"\n     echo -e \"  ${CYAN}[2]${RESET} HCNSEC/IAMHC (${BLUE}https://api.hcnsec.cn${RESET})\"\n     echo \"\"\n     read -p \"Pilihan Anda (1/2): \" pilihan\n     if [ \"$pilihan\" == \"1\" ]; then\n         PROVIDER=\"agentrouter\"\n     elif [ \"$pilihan\" == \"2\" ]; then\n         PROVIDER=\"hcnsec\"\n     else\n         echo -e \"${RED}Pilihan tidak valid!${RESET}\"\n         show_usage\n     fi\n fi\n\n if [ \"$PROVIDER\" == \"agentrouter\" ]; then\n     AGENTROUTER_KEY=$(get_key \"AgentRouter\" \"$AGENTROUTER_KEY\")\n     save_config\n     \n     # Write settings.json nicely formatted\n     cat << EOF > \"$SETTINGS_FILE\"\n {\n   \"env\": {\n     \"ANTHROPIC_AUTH_TOKEN\": \"$AGENTROUTER_KEY\",\n     \"ANTHROPIC_BASE_URL\": \"https://agentrouter.org\",\n     \"ANTHROPIC_MODEL\": \"$AGENTROUTER_MODEL\",\n     \"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC\": \"1\"\n   },\n   \"permissions\": {\n     \"allow\": [],\n     \"deny\": []\n   },\n   \"skipWorkflowUsageWarning\": true\n }\n EOF\n     \n     echo -e \"\\n${GREEN}BERHASIL DIUBAH!${RESET}\"\n     echo -e \"Endpoint: ${CYAN}https://agentrouter.org${RESET}\"\n     echo -e \"Model: ${YELLOW}$AGENTROUTER_MODEL${RESET}\"\n     echo -e \"Jalankan ${GREEN}claude${RESET} untuk memulai.\"\n\n elif [ \"$PROVIDER\" == \"hcnsec\" ]; then\n     HCNSEC_KEY=$(get_key \"HCNSEC\" \"$HCNSEC_KEY\")\n     save_config\n     \n     # Write settings.json nicely formatted\n     cat << EOF > \"$SETTINGS_FILE\"\n {\n   \"env\": {\n     \"ANTHROPIC_AUTH_TOKEN\": \"$HCNSEC_KEY\",\n     \"ANTHROPIC_BASE_URL\": \"https://api.hcnsec.cn\",\n     \"ANTHROPIC_MODEL\": \"$HCNSEC_MODEL\",\n     \"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC\": \"1\"\n   },\n   \"permissions\": {\n     \"allow\": [],\n     \"deny\": []\n   },\n   \"skipWorkflowUsageWarning\": true\n }\n EOF\n     \n     echo -e \"\\n${GREEN}BERHASIL DIUBAH!${RESET}\"\n     echo -e \"Endpoint: ${CYAN}https://api.hcnsec.cn${RESET}\"\n     echo -e \"Model: ${YELLOW}$HCNSEC_MODEL${RESET}\"\n     echo -e \"Jalankan ${GREEN}claude${RESET} untuk memulai.\"\n fi\n```\n\n- Make it executable and globally link it:\n\n```\nchmod +x ~/.claude/switch-claude.sh\nln -sf ~/.claude/switch-claude.sh /data/data/com.termux/files/usr/bin/switch-claude\n```\n\n**Interactive Mode:** Simply run`switch-claude`\n\nand select option`1`\n\nor`2`\n\n.**Quick Commands:**- Switch to\n**AgentRouter:**`switch-claude 1`\n\n(or`switch-claude agentrouter`\n\n) - Switch to\n**HCNSEC:**`switch-claude 2`\n\n(or`switch-claude hcnsec`\n\n) **Reset Saved Keys:**`switch-claude --reset`\n\nOnce configured, simply run:\n\n```\nclaude\n```\n\nThe Claude Code interactive CLI terminal should start up immediately and connect to the proxy endpoint seamlessly.\n\n**Reason:** You probably appended`/v1`\n\nto the base URL in your`settings.json`\n\n.**Fix:** Remove the`/v1`\n\nsuffix from your`ANTHROPIC_BASE_URL`\n\nparameter.\n\n**Reason 1:** You might have pasted a Redemption Code (base64-like string ending in`==`\n\n) directly into the config. Check the Step 1 instructions.**Reason 2:** The model configured in`ANTHROPIC_MODEL`\n\nis not bound to your proxy channel/tier. Double-check your proxy account balance.\n\n**Reason:** Very old Claude Code versions (e.g.,`0.2.x`\n\n) crash on newer Node versions (like Node 22/26) due to dependency issues.**Fix:** Upgrade to version`2.1.112`\n\nor later which fixes the Node interpreter crash.", "url": "https://wpnews.pro/news/a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec", "canonical_source": "https://gist.github.com/kyiov/7fa4ade364f520609d7ef65c46b69388", "published_at": "2026-07-15 10:37:08+00:00", "updated_at": "2026-07-27 10:58:58.674906+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-tools"], "entities": ["Anthropic", "Claude Code", "AgentRouter", "HCNSEC"], "alternates": {"html": "https://wpnews.pro/news/a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec", "markdown": "https://wpnews.pro/news/a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec.md", "text": "https://wpnews.pro/news/a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec.txt", "jsonld": "https://wpnews.pro/news/a-premium-developer-s-guide-to-running-claude-code-cli-for-free-using-and-hcnsec.jsonld"}}