Claude Code Cli 支持通过 CLAUDE_CONFIG_DIR 指定配置目录。
默认情况下,直接在终端输入 claude,使用的是 ~/.claude 目录。这里保存着账号登录状态、配置、历史记录、插件和会话等信息。
所以,想使用第二个 Claude Pro 账号,只需要给它指定一个独立的配置目录即可。
1. 配置第二个账号
打开 ~/.zshrc,添加一个别名:
alias claude-work='CLAUDE_CONFIG_DIR="$HOME/.claude-work" claude'
保存后,执行:
source ~/.zshrc
2. 如何使用?
以后在终端中:
claude # 使用第一个账号
claude-work # 使用第二个账号
第一次执行 claude-work 时,Claude Code 会在 ~/.claude-work 目录下初始化配置,并要求你重新登录第二个账号。
之后,你甚至可以同时打开两个终端窗口:
- 终端 A:使用第一个 Claude Pro 账号。
- 终端 B:使用第二个 Claude Pro 账号。
两个账号各自拥有独立的登录状态、配置和会话记录,互不干扰。
3. 为什么这样就可以?
关键在于这条命令:
CLAUDE_CONFIG_DIR="$HOME/.claude-work" claude
Linux 和 macOS 支持在命令前设置环境变量,这个变量只对当前启动的进程生效。但是这个原理不重要,用起来才是最重要的。
4. 如何单独看额度
这里可以用到 Claude Code 的 Status Line 这个功能,我们可以在 Status 上面看到当前的模型、上下文长度、5H 剩余、周额度等等
先来看一下效果:

第一行是当前模型、思考强度、上下文占用和缓存命中率,第二行是 5 小时额度和 7 天额度的剩余量,以及多久后重置。
脚本依赖 jq。macOS 可以这样装:
brew install jq
把下面的内容保存为 ~/.claude/statusline.sh:
#!/usr/bin/env bash
# Claude Code status line. Requires jq.
set -u
# Claude Code sends one JSON object to stdin on every refresh.
IFS=$'\t' read -r model effort ctx hit used5 reset5 used7 reset7 < <(
jq -r '
def percent:
if type == "number" then ([0, ([100, .] | min)] | max | round)
else "NA" end;
[
(.model.display_name // "Unknown"),
(.effort.level // "N/A"),
(.context_window.used_percentage | percent),
(.prompt_cache.hit_ratio | if type == "number" then (. * 100 | round) else "NA" end),
(.rate_limits.five_hour.used_percentage | percent),
(.rate_limits.five_hour.resets_at // "NA"),
(.rate_limits.seven_day.used_percentage | percent),
(.rate_limits.seven_day.resets_at // "NA")
] | @tsv
'
)
RESET=$'\033[0m'
DIM=$'\033[2m'
MODEL_COLOR=$'\033[1;35m'
CYAN=$'\033[36m'
SEPARATOR=$'\033[38;2;130;130;130m'
TRACK=$'\033[38;2;120;120;120m'
GREEN=$'\033[32m'
YELLOW=$'\033[33m'
RED=$'\033[31m'
percent_text() {
if [[ $1 =~ ^[0-9]+$ ]]; then printf '%d%%' "$1"; else printf '%s' '--%'; fi
}
left_text() {
if [[ $1 =~ ^[0-9]+$ ]]; then printf '%d%%' "$((100 - $1))"; else printf '%s' '--%'; fi
}
reset_after() {
local ts=$1 seconds days hours mins
if [[ ! $ts =~ ^[0-9]+([.][0-9]+)?$ ]]; then printf '%s' '--'; return; fi
seconds=$(( ${ts%%.*} - NOW ))
(( seconds < 0 )) && seconds=0
days=$((seconds / 86400))
hours=$(((seconds % 86400) / 3600))
mins=$(((seconds % 3600) / 60))
if (( days > 0 )); then
printf '%dd %dh' "$days" "$hours"
elif (( hours > 0 )); then
printf '%dh %dm' "$hours" "$mins"
else
printf '%dm' "$mins"
fi
}
# Gradient uses stable, full-width block characters: no fractional glyphs.
context_bar() {
local pct=$1 width=20 filled=0 i pos r g b offset
if [[ $pct =~ ^[0-9]+$ ]]; then filled=$(((pct * width + 50) / 100)); fi
for ((i = 0; i < width; i++)); do
if (( i >= filled )); then
printf '%s░' "$TRACK"
continue
fi
pos=$((i * 100 / (width - 1)))
if ((pos <= 50)); then
r=$(( 0 + 220 * pos / 50 ))
g=200
b=$(( 80 - 80 * pos / 50 ))
else
offset=$((pos - 50))
r=220
g=$(( 200 - 160 * offset / 50 ))
b=$(( 20 * offset / 50 ))
fi
printf '\033[38;2;%d;%d;%dm█' "$r" "$g" "$b"
done
printf '%s' "$RESET"
}
usage_color() {
if [[ ! $1 =~ ^[0-9]+$ ]] || (( $1 < 70 )); then printf '%s' "$GREEN"
elif (( $1 < 90 )); then printf '%s' "$YELLOW"
else printf '%s' "$RED"; fi
}
NOW=$(date +%s)
ctx_label=$(percent_text "$ctx")
hit_label=$(percent_text "$hit")
five_left=$(left_text "$used5")
seven_left=$(left_text "$used7")
five_reset=$(reset_after "$reset5")
seven_reset=$(reset_after "$reset7")
ctx_color=$(usage_color "$ctx")
five_color=$(usage_color "$used5")
seven_color=$(usage_color "$used7")
printf '%s[%s · %s]%s ' "$MODEL_COLOR" "$model" "$effort" "$RESET"
context_bar "$ctx"
printf ' %s%s%s %s│%s %sHit%s %s%s\n' "$ctx_color" "$ctx_label" "$RESET" "$SEPARATOR" "$RESET" "$CYAN" "$RESET" "$CYAN" "$hit_label"
printf '5h %s%s%s left %s·%s reset %s %s│%s 7d %s%s%s left %s·%s reset %s\n' \
"$five_color" "$five_left" "$RESET" "$DIM" "$RESET" "$five_reset" "$SEPARATOR" "$RESET" \
"$seven_color" "$seven_left" "$RESET" "$DIM" "$RESET" "$seven_reset"
然后在 ~/.claude/settings.json 里加上:
{
"statusLine": {
"type": "command",
"command": "bash \"$HOME/.claude/statusline.sh\""
}
}
第二个账号用的是 ~/.claude-work/settings.json,同样加上这段。两个账号可以共用 ~/.claude/statusline.sh,额度是 Claude Code 按当前登录账号传给脚本的,所以各自显示各自的用量。