Stop daemon session workers on switch, not just the supervisor
v0.1.1 stopped only the daemon supervisor (--keep-workers). But a kept worker holds in memory the account it was started under, so `claude --resume` reattached to the old worker and the switch appeared to have no effect — the resumed session kept the previous org. Drop --keep-workers so `claude daemon stop --any` also stops the workers, and every subsequent session (resumed or fresh) picks up the switched account. Trade-off: switching ends detached background sessions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+37
-17
No files matched your search
@@ -8,6 +8,18 @@ All notable changes to ccswitch are documented here. The format follows
|
||||
|
||||
_Nothing yet._
|
||||
|
||||
## [0.1.2] — 2026-07-08
|
||||
|
||||
### Changed
|
||||
|
||||
- **Daemon stop now includes session workers.** v0.1.1 stopped only the daemon
|
||||
supervisor (`--keep-workers`), but a kept worker holds in memory the account
|
||||
it was started under — so `claude --resume` reattached to the old worker and
|
||||
the switch appeared to have no effect (the resumed session kept the previous
|
||||
org). The switch now runs `claude daemon stop --any` (no `--keep-workers`), so
|
||||
every subsequent session, resumed or fresh, picks up the switched account.
|
||||
Trade-off: switching ends any detached background Claude Code sessions.
|
||||
|
||||
## [0.1.1] — 2026-07-08
|
||||
|
||||
### Fixed
|
||||
|
||||
Generated
+1
-1
@@ -60,7 +60,7 @@ checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"
|
||||
|
||||
[[package]]
|
||||
name = "ccswitch"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ccswitch"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
description = "Switch between multiple Claude Code accounts"
|
||||
license = "MIT"
|
||||
|
||||
@@ -327,12 +327,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 credentials, while any detached background sessions keep running.
|
||||
This is best-effort: on an older Claude Code, or when no daemon is running, it
|
||||
is a 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 credentials. 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. This is best-effort: on an older
|
||||
Claude Code, or when no daemon is running, it is a 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`
|
||||
|
||||
+8
-6
@@ -248,9 +248,11 @@ pub trait System {
|
||||
/// Whether a `claude` process is currently running.
|
||||
fn claude_is_running(&self) -> bool;
|
||||
|
||||
/// Stop the Claude Code daemon's supervisor so the next session re-reads the
|
||||
/// restored credentials, while leaving detached background sessions running
|
||||
/// (`claude daemon stop --any --keep-workers`). Best-effort.
|
||||
/// Stop the Claude Code daemon and its session workers so the next session
|
||||
/// re-reads the restored credentials (`claude daemon stop --any`). A kept
|
||||
/// worker would hold its original account in memory and a resumed session
|
||||
/// would reattach to it, ignoring the switch — so workers are stopped too.
|
||||
/// Best-effort.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
@@ -545,9 +547,9 @@ impl<'a> App<'a> {
|
||||
"warning: a running 'claude' may overwrite ~/.claude.json on exit; quit it first"
|
||||
)?;
|
||||
}
|
||||
// A running daemon caches the account's auth; stop its supervisor so the
|
||||
// next session picks up the restored credentials (detached background
|
||||
// sessions keep running). Best-effort — never block the switch on it.
|
||||
// A running daemon (and its session workers) cache the account's auth;
|
||||
// stop them so the next session — including a `claude --resume` — picks
|
||||
// up the restored credentials. Best-effort — never block the switch.
|
||||
if let Err(e) = self.system.stop_daemon() {
|
||||
writeln!(io.err, "warning: could not stop the claude daemon: {e}")?;
|
||||
}
|
||||
|
||||
+6
-3
@@ -44,10 +44,13 @@ impl System for RealSystem {
|
||||
}
|
||||
|
||||
fn stop_daemon(&self) -> Result<()> {
|
||||
// Best-effort: an old Claude Code without the daemon, a missing binary,
|
||||
// or no daemon running are all fine — never fail the switch on this.
|
||||
// Stop the supervisor AND its session workers: a kept worker holds the
|
||||
// account it was started under in memory, so `claude --resume` would
|
||||
// reattach to it and ignore the switch. Killing workers makes every
|
||||
// switch take effect. Best-effort: an old Claude Code without the
|
||||
// daemon, a missing binary, or no daemon running never fail the switch.
|
||||
let _ = Proc::new("claude")
|
||||
.args(["daemon", "stop", "--any", "--keep-workers"])
|
||||
.args(["daemon", "stop", "--any"])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status();
|
||||
|
||||
Reference in new issue
Block a user