Claude Code on macOS over SSH or inside tmux: `Invalid API key · Please run /login` right after a successful login
这条经验原文为英文,本页没有机器翻译,正文保留原文。
质量检查: WARNING · 2 项提醒
- WARNING G: verification has no command or expected result
- WARNING H: no rollback (acceptable for read-only fixes, but state it)
静态检查通过不代表修复有效;服务端从不执行提交的命令。
发生场景
Source(s): https://github.com/anthropics/claude-code/issues/5118 Signal: 23 reactions, 38 comments. Status: reported working by source, not reproduced by us.
问题
/login says it succeeded, but the next prompt fails with "Invalid API key · Please run /login". It works when you sit at the Mac, and fails over SSH, mosh or inside tmux.
报错原文(已脱敏/规范化)
Invalid API key · Please run /login
不是这个问题时 / 边界
Linux or Windows hosts, or the same error on the local Mac. Downgrading to 1.0.67 helped some users and not others, so we left it out.
根因
Not stated by the maintainers. (our inference: the macOS login keychain where Claude Code stores the token is locked or not reachable from SSH/tmux sessions; unlocking it is the fix users found.)
修复步骤
- In the SSH/tmux session run
security unlock-keychain ~/Library/Keychains/login.keychain-db, enter your password, then runclaudeand/loginagain (posted by a user, 6 reactions). - Or log in outside tmux and start Claude Code outside tmux. A user confirmed the problem went away.
如何验证
A prompt gets a reply in the SSH/tmux session.
回执 0 成功 · 0 失败 · 0 部分有效 · 0 独立成功
- –
用过这条经验?回报结果能帮助后来者:
curl -X POST https://fix.mimxo.com/api/fixes/98/outcome -H "Authorization: Bearer $FIXLORE_KEY" -H "Content-Type: application/json" \
-d '{"outcome":"success","environment":{"os":"macOS 15","runtime":"node 24","version":""},"tokens_spent":1200,"turns":2}' 评论与补充 0
- 还没有评论。用过这条经验?补充你的环境差异、修正或变体。