Show HN: Claude-account – 无需重新登录即可切换 Claude Code 账号
Show HN: Claude-account – switch Claude Code accounts without logging in again

原始链接: https://github.com/hamzarehmandeveloper/claude-account

**claude-account** 是一款面向 Linux 平台的开源社区工具,旨在为 Claude Code 提供配置文件的管理功能。它允许用户通过为不同的账户(如“工作”和“个人”)指定独立的 `CLAUDE_CONFIG_DIR`,从而实现配置的隔离。 **主要特性包括:** * **无缝集成:** 它作为一个透明的垫片(shim)运行,在转发所有标准 Claude 命令的同时,通过 Claude Code 的官方登录流程管理认证。 * **隐私至上:** 该工具从不读取或存储敏感凭据、令牌或 API 密钥,仅负责环境变量的隔离管理。 * **工作流灵活:** 用户可以轻松添加、列出、移除或切换配置文件。切换配置仅影响新会话,现有进程仍绑定于原账户。 * **安全性:** 它遵循 XDG 标准,并支持在移除配置文件时选择性清除数据。为防止冲突,它会自动清理敏感的环境变量,除非显式覆盖。 **安装:** 该工具可以通过预编译二进制文件安装,也可以使用 Rust 1.85+ 从源码构建。安装完成后,用户只需将提供的路径添加到 `.bashrc` 中即可。请注意,这是一个独立项目,未得到 Anthropic 的认可。

开发者 Hamza Rehman 发布了 **Claude-account**,这是一款简洁的命令行工具,旨在帮助用户管理多个 Claude Code 账号,免去了反复登录的繁琐。 该工具允许用户添加多个配置,并通过简单的命令(如 `claude account use [name]`)在不同账号间无缝切换。这使得用户在处理工作和个人项目时,无需再手动登出并重新验证身份。 在讨论帖中,用户对该工具的实用性表示赞赏,并提出了一些替代方案,例如使用简单的 shell 别名,或创建 `.claude-profile` 文件来自动管理环境变量,以防止误用账号。该项目现已开源,可在 GitHub 上获取。
相关文章

原文

CI Release License: MIT

A Linux-only profile switcher for Claude Code. It gives Claude Code an isolated CLAUDE_CONFIG_DIR for each account and transparently forwards normal commands to the official Claude executable.

claude account add work
claude account add personal
claude account use work
claude account list
claude account current
claude account remove personal

claude
claude "fix this bug in main.py"

Claude Code itself performs login, logout, credential storage, and token refresh. claude-account never reads or copies credential contents.

Important

This is an independent community project. It is not made, endorsed, or supported by Anthropic. Claude and Claude Code are products of Anthropic.

  • Linux
  • A working Claude Code installation
  • Rust 1.85 or later to build from source

Download claude-account-v0.1.1-x86_64-unknown-linux-gnu.tar.gz and its .sha256 file from the latest release, then verify and install it:

sha256sum --check claude-account-v0.1.1-x86_64-unknown-linux-gnu.tar.gz.sha256
tar -xzf claude-account-v0.1.1-x86_64-unknown-linux-gnu.tar.gz
./claude-account install

The installer prints one export PATH=... line. Add that line to ~/.bashrc and open a new terminal. The shim lives in its own directory; it does not replace the official Claude executable.

Confirm the installation:

type -a claude
claude account list

The claude-account shim should appear before the official Claude executable.

git clone https://github.com/hamzarehmandeveloper/claude-account.git
cd claude-account
cargo build --locked --release
./target/release/claude-account install
claude account add work
claude account add personal --email [email protected]
claude account add company --sso
claude account add api-billing --console

This opens Claude Code's official login flow. The first profile becomes active. Adding another profile does not switch the active profile. The command also completes Claude Code's local onboarding state, so the next claude launch uses the saved login without asking you to authenticate again.

Switching affects newly launched Claude processes. Existing sessions keep the account with which they were started.

claude account list
claude account current

current prints only the profile name, making it safe to use in scripts.

claude account remove personal

This runs Claude Code's official auth logout inside the profile and unregisters it. Settings and session history are preserved, allowing the same profile name to reuse them later.

To delete all local data belonging to the profile:

claude account remove personal --purge --yes

Removing the active profile is refused unless --force is supplied. --purge permanently deletes that profile's settings, sessions, plugins, and history in addition to its stored login.

claude account --help
claude account add --help
claude account remove --help

All non-account commands and flags are passed unchanged to the official Claude executable:

claude
claude -p "explain this project"
claude --model opus
claude auth status --text

By default:

~/.config/claude-account/state.json
~/.local/share/claude-account/profiles/<name>/
~/.local/share/claude-account/bin/claude
~/.local/share/claude-account/libexec/claude-account

The standard XDG_CONFIG_HOME and XDG_DATA_HOME variables are respected. CLAUDE_ACCOUNT_HOME can place all application data under one absolute directory, which is especially useful for tests.

The state file contains profile names, directory paths, and the real Claude executable path. It never contains access or refresh tokens.

Authentication environment variables

To guarantee that the selected profile is actually used, the wrapper removes these variables from the child Claude process:

  • ANTHROPIC_API_KEY
  • ANTHROPIC_AUTH_TOKEN
  • CLAUDE_CODE_OAUTH_TOKEN

Set CLAUDE_ACCOUNT_PRESERVE_AUTH_ENV=1 if you intentionally want those variables to override profile authentication.

cargo fmt --check
cargo test --locked --all-targets
cargo clippy --locked --all-targets -- -D warnings

See CONTRIBUTING.md for the contribution workflow and SECURITY.md for private vulnerability reporting.

Released under the MIT License.

联系我们 contact @ memedata.com