legacy-fish: backport the daemon-stop-on-switch fix

Keep the vendored legacy-fish mirror in sync with lei-wego/ccswitch-fish:
stop the Claude Code daemon supervisor on switch so restored credentials
take effect. Best-effort, background sessions kept.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
mysqtoandClaude Opus 4.8 committed 2026-07-08 18:46:43 +08:00
1 parent 8c929cbc70
commit 7a29dc8e07
2 files changed
+22

No files matched your search

+6
View File
@@ -244,6 +244,12 @@ 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.
- 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`
+16
View File
@@ -147,6 +147,18 @@ 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.
# 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
return 0
end
function __ccswitch_sync_current -d "re-snapshot the live account into its matching profile"
# OAuth refresh tokens rotate on every use, so a profile saved earlier goes
# stale as its account keeps running. Before switching away, copy the live
@@ -205,6 +217,10 @@ function __ccswitch_use -d "restore a profile as the active account"
echo "ccswitch: warning — a running 'claude' may overwrite ~/.claude.json on exit; quit it first" >&2
end
# a running daemon caches this account's auth; stop its supervisor so the
# next session picks up the restored credential (background sessions kept)
__ccswitch_stop_daemon
# refresh the outgoing account's snapshot (its token may have rotated)
__ccswitch_sync_current "$home" "$config"