Skip to content

Instantly share code, notes, and snippets.

@khadorkin
Forked from RuiNelson/README.md
Created October 21, 2025 21:03
Show Gist options
  • Save khadorkin/6d91ed1c395e3238cf9834e681ac8698 to your computer and use it in GitHub Desktop.
Save khadorkin/6d91ed1c395e3238cf9834e681ac8698 to your computer and use it in GitHub Desktop.
How to Use GLM Coding Plan and Claude Pro/Max Simultaneously with Claude Code on macOS

Who is this script for?

For those who have a Claude (Anthropic) account and a GLM Coding Plan (Z.ai) account and want to use Claude Code for both.

What does this script solve?

On macOS, Claude Code stores access credentials in the Keychain (macOS Keychain is a secure database that the operating system provides to applications for storing secrets). This makes the setup more secure but less programmatically configurable.

How does this script solve this problem?

This script blocks access to the Keychain for this instance of Claude Code execution, forcing it to write account settings to configuration files.

Additionally, it creates and uses a separate directory for Claude Code configuration when using the GLM Coding Plan account.

TL;DR: It creates complete isolation for running claude. So your normal instances of claude don't see anything about Z.ai and vice versa.

How do I install it?

Copy this script to your Mac, insert your API Key (line 26), and grant execution permissions to the script.

For example, I saved my version to ~/Scripts/glm-claude.sh, then ran chmod +x ~/Scripts/glm-claude.sh to grant the execution permission.

Additionally, I recommend adding an alias.

For zsh users

Add alias glm="~/Scripts/glm-claude.sh" to the end of your .zshrc and restart the shell.

For fish users

alias glm "~/Scripts/glm-claude.sh" and funcsave glm

How do I use it?

Now you can use claude to run your untouched Claude Code with your Anthropic API or Claude Plan account. Or use glm for an isolated Claude Code.

Your claude user configuration gets stored in ~/.claude and your glm user configuration gets stored in ~/.glm.

The project specific configuration (.claude directory inside projects) is shared between claude and glm

You can even use arguments like glm mcp add ...

Disclaimer

This text/script is provided for academic purposes only. I am not associated with either company. Consult a lawyer to understand the legality of this process in your jurisdiction.

#!/usr/bin/env zsh
# Create a fake `security` executable
#
# This executable provides access to macOS Keychain for command-line
# apps like claude. Denying access to it, will force claude to save
# the credentials to config.json
TEMP_DIR="${HOME}/$(uuidgen).tmp"
mkdir -p "${TEMP_DIR}"
cat << 'EOF' > "${TEMP_DIR}/security"
#!/bin/sh
echo "Keychain access denied" >&2
exit 1
EOF
chmod +x "${TEMP_DIR}/security"
# Add the temporary directory to the top of PATH for this process
export PATH="${TEMP_DIR}":$PATH
# Setup the custom environment variables
export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
export ANTHROPIC_AUTH_TOKEN=------Your GLM API Key goes here!------
export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.5-air
export ANTHROPIC_DEFAULT_SONNET_MODEL=glm-4.6
export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-4.6
# Setup the custom config dir, creating it if it doesn't exists
export CLAUDE_CONFIG_DIR="${HOME}/.glm"
mkdir -p "${CLAUDE_CONFIG_DIR}"
# Run claude
claude "$@"
# Clean up the temporary files created
rm -rf "${TEMP_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment