legacy-fish: stop daemon workers on switch (sync with plugin)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+16
-12
No files matched your search
@@ -244,12 +244,15 @@ plaintext tokens to a shared or public repo.
|
||||
- Quit any running `claude` session before switching — an open session can
|
||||
rewrite `~/.claude.json` on exit and clobber the swap. `ccswitch` warns when it
|
||||
detects one.
|
||||
- Recent Claude Code releases keep a background **daemon** that caches each
|
||||
account's auth in memory. On every switch `ccswitch` stops its supervisor
|
||||
(`claude daemon stop --any --keep-workers`) so the next session re-reads the
|
||||
restored credential, while any detached background sessions keep running. It
|
||||
is best-effort: on an older Claude Code, or when no daemon is running, it is a
|
||||
harmless no-op and the switch proceeds regardless.
|
||||
- Recent Claude Code releases keep a background **daemon** (and per-session
|
||||
workers) that cache each account's auth in memory. On every switch `ccswitch`
|
||||
stops the daemon and its workers (`claude daemon stop --any`) so the next
|
||||
session re-reads the restored credential. Workers are stopped too because a
|
||||
kept worker holds the account it was started under, so a `claude --resume`
|
||||
would reattach to it and ignore the switch. It is best-effort: on an older
|
||||
Claude Code, or when no daemon is running, it is a harmless no-op and the
|
||||
switch proceeds regardless. **Note:** this ends any detached background
|
||||
Claude Code sessions when you switch.
|
||||
- Access tokens expire, but the refresh token is restored too, so Claude Code
|
||||
re-refreshes automatically after a switch.
|
||||
- OAuth refresh tokens rotate on every use. To keep snapshots valid, `ccswitch`
|
||||
|
||||
@@ -147,15 +147,16 @@ function __ccswitch_add -d "log in a new account and save it as a profile"
|
||||
__ccswitch_save "$home" "$config" "$name"
|
||||
end
|
||||
|
||||
function __ccswitch_stop_daemon -d "stop the Claude Code daemon supervisor so a switch takes effect"
|
||||
# Recent Claude Code releases keep a background daemon that caches each
|
||||
# account's auth in memory, so a switch would not take effect until the
|
||||
# daemon exited. Stop its supervisor so the next session re-reads the
|
||||
# restored credential, while any detached background sessions keep running.
|
||||
function __ccswitch_stop_daemon -d "stop the Claude Code daemon so a switch takes effect"
|
||||
# Recent Claude Code releases keep a background daemon (and per-session
|
||||
# workers) that cache each account's auth in memory. A kept worker holds
|
||||
# the account it was started under, so `claude --resume` would reattach to
|
||||
# it and ignore the switch. Stop the daemon and its workers so the next
|
||||
# session — including a resume — re-reads the restored credential.
|
||||
# Best-effort — an older Claude Code or no running daemon is a harmless
|
||||
# no-op, and a failure never blocks the switch.
|
||||
command -sq claude; or return 0
|
||||
command claude daemon stop --any --keep-workers >/dev/null 2>&1
|
||||
command claude daemon stop --any >/dev/null 2>&1
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user