Show HN:Claude-account——无需重新登录即可切换 Claude Code 账户
英文标题:🔶 Show HN: Claude-account – switch Claude Code accounts without logging in again
Claude-account 是一个仅支持 Linux 的 Claude Code 多账户配置文件切换工具,通过为每个账户分配独立的 `CLAUDE_CONFIG_DIR` 实现隔离。它将常规 `claude` 命令透明转发给官方 Claude 可执行文件,而登录、登出、凭据保存和令牌刷新仍完全由 Claude Code 负责。该工具不会读取或复制凭据内容,并会默认移除可能覆盖所选配置文件认证状态的环境变量。对于需要在工作、个人、SSO 或 API 计费账户之间频繁切换的开发者,它提供了无需重复认证的本地账户管理方案。
100.1 KB
中文
这是一个仅支持 Linux 的 Claude Code 配置文件切换器。它为每个账户提供独立的 CLAUDE_CONFIG_DIR,并将普通命令透明转发给官方 Claude 可执行文件。
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 本身负责登录、登出、凭据存储和令牌刷新。claude-account 从不读取或复制凭据内容。
重要提示
这是一个独立的社区项目,并非由 Anthropic 制作、认可或支持。Claude 和 Claude Code 是 Anthropic 的产品。
- Linux
- 可正常运行的 Claude Code 安装
- 如需从源码构建,需 Rust 1.85 或更高版本
从最新发布版本下载 claude-account-v0.1.1-x86_64-unknown-linux-gnu.tar.gz 及其 .sha256 文件,然后验证并安装:
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
安装程序会输出一行 export PATH=...。将该行添加至 ~/.bashrc,然后打开一个新的终端。该 shim 位于自己的目录中,不会替换官方 Claude 可执行文件。
确认安装:
type -a claude
claude account list
claude-account shim 应出现在官方 Claude 可执行文件之前。
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 you@example.com
claude account add company --sso
claude account add api-billing --console
这会打开 Claude Code 的官方登录流程。第一个配置文件会成为活动配置文件;添加其他配置文件不会切换当前活动配置文件。该命令还会完成 Claude Code 的本地初始设置状态,因此下次启动 claude 时将使用已保存的登录状态,无需再次进行认证。
切换只会影响新启动的 Claude 进程。现有会话会继续使用其启动时所对应的账户。
claude account list
claude account current
current 仅输出配置文件名称,因此可安全用于脚本。
claude account remove personal
该命令会在配置文件内运行 Claude Code 官方的 auth logout,然后注销该配置文件。设置和会话历史会被保留,因此之后可以使用相同的配置文件名称复用它们。
要删除属于该配置文件的全部本地数据:
claude account remove personal --purge --yes
除非提供 --force,否则不允许移除活动配置文件。除已保存的登录状态外,--purge 还会永久删除该配置文件的设置、会话、插件和历史记录。
claude account --help
claude account add --help
claude account remove --help
所有非账户相关的命令和标志都会原样传递给官方 Claude 可执行文件:
claude
claude -p "explain this project"
claude --model opus
claude auth status --text
默认情况下:
~/.config/claude-account/state.json
~/.local/share/claude-account/profiles/<name>/
~/.local/share/claude-account/bin/claude
~/.local/share/claude-account/libexec/claude-account
该工具遵循标准的 XDG_CONFIG_HOME 和 XDG_DATA_HOME 变量。CLAUDE_ACCOUNT_HOME 可将所有应用数据放在同一个绝对路径目录下,这对测试尤其有用。
状态文件包含配置文件名称、目录路径以及真实 Claude 可执行文件的路径,绝不包含访问令牌或刷新令牌。
认证环境变量
为确保实际使用所选配置文件,包装器会从子 Claude 进程中移除以下变量:
ANTHROPIC_API_KEYANTHROPIC_AUTH_TOKENCLAUDE_CODE_OAUTH_TOKEN
如果你有意让这些变量覆盖配置文件认证状态,请设置 CLAUDE_ACCOUNT_PRESERVE_AUTH_ENV=1。
cargo fmt --check
cargo test --locked --all-targets
cargo clippy --locked --all-targets -- -D warnings
贡献流程请参阅 CONTRIBUTING.md,私密漏洞报告请参阅 SECURITY.md。
基于 MIT License 发布。
English / 原文
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 you@example.com
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_KEYANTHROPIC_AUTH_TOKENCLAUDE_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.