Created
June 13, 2026 23:39
-
-
Save binhna/957299437dfaf30b9487ca50bc562b27 to your computer and use it in GitHub Desktop.
claude-switch.sh — switch Claude Code between Bedrock / Team / personal subscription accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # claude-switch.sh — switch Claude Code between the Team (subscription) and Bedrock accounts. | |
| # | |
| # Sourced from ~/.zshrc on the host and from ~/.zshrc + ~/.bashrc inside the | |
| # bellmere devcontainer. Because ~/.claude is bind-mounted into that container, | |
| # this file and the selection file (~/.claude/active-account) are shared: flip | |
| # the account on the host and the container's next `claude` launch follows. | |
| # | |
| # No credential ever crosses the host<->container boundary. The only shared | |
| # state is the word "team" or "bedrock". Auth lives where each platform keeps it: | |
| # - team : the OAuth login in the macOS keychain (host) or the container's | |
| # own login persisted in ~/.claude (set CLAUDE_CODE_USE_BEDROCK off) | |
| # - bedrock : CLAUDE_CODE_USE_BEDROCK=1 + your already-present AWS SSO creds | |
| # | |
| # POSIX sh syntax only, so it works unchanged in both zsh and bash. | |
| # Resolve the config dir the same way Claude Code does, defaulting to ~/.claude. | |
| CLAUDE_SWITCH_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}" | |
| CLAUDE_SWITCH_FILE="$CLAUDE_SWITCH_DIR/active-account" | |
| # Apply the currently-selected account to THIS shell's environment. | |
| # Called at shell startup and again after every `claude-acct` switch. | |
| _claude_apply_account() { | |
| _cs_acct="bedrock" | |
| if [ -r "$CLAUDE_SWITCH_FILE" ]; then | |
| _cs_acct="$(tr -d '[:space:]' < "$CLAUDE_SWITCH_FILE" 2>/dev/null)" | |
| fi | |
| case "$_cs_acct" in | |
| team) | |
| # Subscription account: turn Bedrock off and clear AWS-specific routing | |
| # so Claude Code falls back to the keychain / persisted OAuth login. | |
| unset CLAUDE_CODE_USE_BEDROCK | |
| unset ANTHROPIC_MODEL | |
| unset AWS_REGION | |
| ;; | |
| bedrock|*) | |
| # Bedrock account (also the default if the file is missing/garbled). | |
| export CLAUDE_CODE_USE_BEDROCK=1 | |
| export AWS_REGION="ap-southeast-2" | |
| # No ANTHROPIC_MODEL pin: let each account use its own default model. | |
| unset ANTHROPIC_MODEL | |
| _cs_acct="bedrock" | |
| ;; | |
| esac | |
| CLAUDE_ACTIVE_ACCOUNT="$_cs_acct" | |
| unset _cs_acct | |
| } | |
| # claude-acct [team|bedrock|status] | |
| # No argument or "status" -> print the current selection without changing it. | |
| claude-acct() { | |
| case "${1:-status}" in | |
| team|bedrock) | |
| printf '%s\n' "$1" > "$CLAUDE_SWITCH_FILE" | |
| _claude_apply_account | |
| printf 'Claude account -> %s (applied to this shell; new `claude` launches will use it)\n' "$CLAUDE_ACTIVE_ACCOUNT" | |
| ;; | |
| status|"") | |
| _claude_apply_account | |
| printf 'Claude account: %s\n' "$CLAUDE_ACTIVE_ACCOUNT" | |
| if [ "$CLAUDE_ACTIVE_ACCOUNT" = "bedrock" ]; then | |
| printf ' CLAUDE_CODE_USE_BEDROCK=%s AWS_REGION=%s AWS_PROFILE=%s\n' \ | |
| "${CLAUDE_CODE_USE_BEDROCK:-<unset>}" "${AWS_REGION:-<unset>}" "${AWS_PROFILE:-<unset>}" | |
| else | |
| printf ' using subscription login (keychain on host / persisted login in container)\n' | |
| fi | |
| ;; | |
| *) | |
| printf 'usage: claude-acct [team|bedrock|status]\n' >&2 | |
| return 2 | |
| ;; | |
| esac | |
| } | |
| # Apply the selection on shell startup. | |
| _claude_apply_account |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment