diff --git a/AGENTS.md b/AGENTS.md index f7ccc33..35092cd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,6 +44,7 @@ npm run dist # installers for the current OS into dist/ - **Usage** (`usage`): `GET api.anthropic.com/api/oauth/usage`, at most every 10 minutes per account. Answers are cached in `~/.claude-profiles/.usage-cache.json` (numbers only); after a 429 it waits for `Retry-After`. The active account reuses Claude Code's own `cachedUsageUtilization` when fresh. - **Session manager** (`keepSessions`): every 5 minutes, accounts with no running window and weekly limit left get the starting message via `claude -p --model haiku --tools ""`. The active account runs from the default location; others from their profile directory. - **Config** lives in `~/.claude-profiles/.switcher.json`: session manager (`autoStart`, `message`), `settings` (`startAtLogin`, `notify`, `autoSwitch`, `autoSwitchSkip`, `shortcut`, `trayHintShown`), `accounts` (per-name `label`, `color`, `pinned`) and `order`. Labels are display only; the folder name stays the account's identity. +- **Folder accounts** (`projects` in the config: folder → account): VS Code's `claudeCode.claudeProcessWrapper` points at our launcher, which sets `CLAUDE_CONFIG_DIR` to the account's profile for the folder Claude starts in (the deepest match wins; `configDirFor`). Folders are added in Settings → Folder accounts (path + account; nothing is bound by default). An account can be both bound and active: then `configDirFor` and the launcher return no override, since a second live copy of one refresh token logs the other out (`use` rewrites the launcher via `refreshFolders`). Known gap: a VS Code window already running from the profile keeps its token when you switch to that account. On macOS/Linux the launcher is `~/.claude-profiles/claude-launcher.sh`, rewritten by `refreshFolders`; on Windows it's Switcher.exe itself (the branch at the top of `main.js`), since VS Code can't start a script there. `refreshFolders` also links the user's own `~/.claude` setup (the `SHARED` list) into bound profiles; never add account or organisation files to that list. - **Tray and shortcut**: closing the window hides it to the tray; **Quit** is in the tray menu. The shortcut (an Electron accelerator, empty = off) opens the quick switcher. A single-instance lock brings the window back when the app is launched again. - **Notifications** (`watchUsage`, every 5 minutes): `usageAlerts` compares the last two usage readings and fires only when a threshold is crossed. `bestAccount` picks the account with the most left (lower of session and weekly headroom). - **Auto switch** (Settings → Auto switch, off by default; in `watchUsage`): when the active account's session or week is full, `autoSwitchTarget` picks the account with the most left among those taking part (`autoSwitchSkip` lists the accounts left out) and `main.js` runs a normal `use`. It never runs when the active account is left out or nobody has anything left; Claude Code picks the new login up on its next start. @@ -54,7 +55,7 @@ npm run dist # installers for the current OS into dist/ ## Invariants (never break these) 1. **Tokens never leave the machine** except to `api.anthropic.com` and `platform.claude.com`. No logging, printing, telemetry or new endpoints. -2. **Never refresh the active login.** Only Claude Code may refresh the login it's using; doing it here rotates the refresh token and logs Claude Code out. +2. **Never refresh the active login or a folder account's login.** Only Claude Code may refresh a login it's using; doing it here rotates the refresh token and logs Claude Code out. For the same reason a folder account can never be made the active login, and the active account can't get a folder. 3. **Back up before changing credentials**, and write credential files with `writeAtomic` (temporary file, then rename). 4. **Swap only `claudeAiOauth` and `oauthAccount`.** Every other key in those files belongs to Claude Code. 5. **Token-touching operations go through `serial()`**, so a refresh never races a switch. diff --git a/DESIGN.md b/DESIGN.md index 6b1036f..6fabba3 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -96,6 +96,9 @@ Fonts are bundled from `@fontsource` (SIL Open Font License), so nothing loads f | **Status tag** | One per account, next to the name, from `tags.js`, by priority: **Expired** and **Limit hit · 2h 5m** (red outline), **Almost out** (80%+, amber outline), **Most left** (coral outline), then plain pills: **Resets in 20m**, **Fresh**, **Session running**, **Pinned** (tray and quick switcher only). The active account keeps its **Active** badge and only gets the red and amber ones; a folder account gets **Folder** the same way | | **Side panel (What's new)** | A 420px panel that slides over the right of the main window (`.panel`, with a 25% ink scrim you can click to close; Esc closes it too): title and a muted line, a close button, then a scrolling list of notes. A note: a 15px title (a small coral dot when it's new since the user last looked), the date in `--muted`, then lines each with a tag (**New** on `--primary`, **Improved** and **Fixed** on `--pill`) and one short sentence. Opened from the sidebar's **What's new** link, which shows the same dot while something is unseen | | **Colour dot** | 10px circle before the account name, filled with a `--label-*` token; absent when no label is set | +| **Folder chip** | Under an account's email: "Used in" in `--muted`, then one `--pill` chip per folder (folder name, full path on hover). Read-only: folders are edited in Settings → Folder accounts | +| **Setup guide panel** | A 480px side panel that slides over the right of a settings pane (Settings → Folder accounts; opens by itself the first time, and the line-icon help button at the top right of the pane title reopens it). Header with title, "Step 2 of 4" and a close button; then one step at a time (22px `--primary` circle, 15px title, 14px `--muted` line with `kbd` keys), each with a real VS Code screenshot (`assets/guide/stepN.webp`: a short before/after loop, with the place to look outlined in `--focus`; `stepN.png` is the still for reduced motion). A footer holds the progress dots (6px, current in `--primary`), **Back** (hidden on the first step) and a primary **Next** (**Done** on the last); ← and → also move between steps, and the pane behind is dimmed. Esc closes the panel before the dialog. To retake them, use a throwaway VS Code profile and empty folder so no personal data is in the shot | +| **Folder row** | In Settings → Folder accounts: the folder path (ellipsis, full path on hover), an account select and a × link button; below the list, an add row: path field, Choose…, account select and a primary Add | | **Card menu** | Opened by the **⋯** link button: `--card` fill, hairline border, 12px radius, the menu shadow. Items are 34px rows with `--pill` on hover; **Remove** is `--error` | | **Settings dialog** | Modal, up to 860×560, 16px radius, `--card` fill, backdrop ink at 45%. Header: "Settings" (17px / 500) and a close button. Left: a 220px section list on `--soft`, 38px items, the current one on `--pill`. Right: the section title (16px / 500), then rows of label (15px; optional 13px `--muted` line under it) on the left and the control on the right, hairlines between rows. Opens from the sidebar or Ctrl/Cmd+,; Esc or a backdrop click closes it. Under 640px the section list becomes a row on top | | **Switch** | A checkbox with `role="switch"`: 38×22 round track, `--field-line` when off, `--primary` when on, 16px white knob | diff --git a/README.md b/README.md index f296c6c..1b06c63 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ See every account's session and weekly usage, and keep a 5-hour window running o - **Lives in the tray.** Closing the window keeps Switcher in the system tray (menu bar on macOS). Its popup shows every account's session (a ring with the % used) and this week (a bar), and switches with one click. Optionally starts when you log in. - **Notifications.** A heads-up when an account reaches 80% of its weekly limit, runs out, or gets its session back, and when a login expires. - **Most left.** The account with the most usage left is marked, so you know which one to switch to. +- **Folder accounts.** Give a project folder its own account: Claude Code in VS Code uses it there, whichever account is active. - **Yours to arrange.** Rename accounts, give them a colour, pin them to the top, and drag to reorder. - **Safe by design.** Credentials are backed up before every switch, never leave your machine except to Anthropic, and are never logged. - **Updates itself.** New versions download in the background; one click installs them. @@ -91,6 +92,8 @@ You also need the [Claude Code](https://docs.anthropic.com/en/docs/claude-code) If a card can't load usage, **Reconnect** retries, or reopens sign-in when the login has expired. Each card's **⋯** menu renames, pins, colours, moves or removes the account. +**Folder accounts**: in **Settings → Folder accounts** add the project folder and pick its account. Then, once, copy the launcher (the **?** icon on that page walks you through each step, one at a time) from **Settings → Folder accounts** into VS Code's *Claude Process Wrapper* setting (`claudeCode.claudeProcessWrapper`) and reload the window. The account stays usable everywhere else too, including as the active account (inside its folder the active login is simply used as is, so there are never two live copies). `claude` in a terminal keeps using the active account. One catch: switching to an account that a VS Code window is already running in its folder can sign that window out until you reload it. + **Settings** also has start at login (installed app only), notifications, and the quick switcher shortcut: click the field and press the new combination, or **Turn off**. ## How it works @@ -98,6 +101,7 @@ If a card can't load usage, **Reconnect** retries, or reopens sign-in when the l - Each account lives in `~/.claude-profiles//`, with its own `.credentials.json` and `.claude.json`. - Switching replaces only the login (`claudeAiOauth` in `~/.claude/.credentials.json`, or the `Claude Code-credentials` Keychain item on macOS) and the account info (`oauthAccount` in `~/.claude.json`). - Credentials are backed up to `~/.claude-profiles/.backups/` before every switch. +- A folder account runs from its profile folder. Your own setup in `~/.claude` (settings, `CLAUDE.md`, agents, commands, skills, plugins, hooks and session history) is linked into it, so nothing goes missing; the login, policy limits and remote settings stay per account. Switcher never refreshes a folder account's login: Claude Code does that. - Usage comes from Anthropic, using each account's own token, at most every 10 minutes per account. Switcher remembers the last answer, and backs off when Anthropic asks it to. ## Privacy @@ -130,6 +134,7 @@ Pushes to any branch build and test on Windows, macOS and Linux ([ci.yml](.githu - Built against Claude Code 2.1.332. It relies on Claude Code's file formats and undocumented endpoints, which can change. - Used day to day on Windows. Linux passes the full test suite in CI; the macOS Keychain switching isn't covered by automated tests yet. +- Folder accounts on Windows: VS Code starts Claude through Switcher.exe, which adds about half a second. Clear the *Claude Process Wrapper* setting before uninstalling Switcher. User-scope MCP servers (`claude mcp add --scope user`) aren't shared into folder accounts; project `.mcp.json` servers work. - Use it with your own accounts and within Anthropic's terms. ## License diff --git a/assets/chevron.svg b/assets/chevron.svg new file mode 100644 index 0000000..bca6bcf --- /dev/null +++ b/assets/chevron.svg @@ -0,0 +1 @@ + diff --git a/assets/guide/step1.png b/assets/guide/step1.png new file mode 100644 index 0000000..1acef62 Binary files /dev/null and b/assets/guide/step1.png differ diff --git a/assets/guide/step1.webp b/assets/guide/step1.webp new file mode 100644 index 0000000..6cd1323 Binary files /dev/null and b/assets/guide/step1.webp differ diff --git a/assets/guide/step2.png b/assets/guide/step2.png new file mode 100644 index 0000000..caf00d1 Binary files /dev/null and b/assets/guide/step2.png differ diff --git a/assets/guide/step2.webp b/assets/guide/step2.webp new file mode 100644 index 0000000..c95a896 Binary files /dev/null and b/assets/guide/step2.webp differ diff --git a/assets/guide/step3.png b/assets/guide/step3.png new file mode 100644 index 0000000..8acab8f Binary files /dev/null and b/assets/guide/step3.png differ diff --git a/assets/guide/step3.webp b/assets/guide/step3.webp new file mode 100644 index 0000000..71c31f1 Binary files /dev/null and b/assets/guide/step3.webp differ diff --git a/assets/guide/step4.png b/assets/guide/step4.png new file mode 100644 index 0000000..e879b74 Binary files /dev/null and b/assets/guide/step4.png differ diff --git a/assets/guide/step4.webp b/assets/guide/step4.webp new file mode 100644 index 0000000..f05fd2e Binary files /dev/null and b/assets/guide/step4.webp differ diff --git a/core.js b/core.js index 3a848f6..c38b330 100644 --- a/core.js +++ b/core.js @@ -115,7 +115,7 @@ const readJsonStr = (s) => { try { return JSON.parse(s); } catch { return null; function list() { fs.mkdirSync(root(), { recursive: true, mode: 0o700 }); const current = activeKey(); - const { accounts = {}, order = [] } = readConfig(); + const { accounts = {}, order = [], projects = {} } = readConfig(); const profiles = names().map((name) => { const p = loadProfile(name); const m = accounts[name] || {}; @@ -124,6 +124,7 @@ function list() { label: m.label || '', color: m.color || '', pinned: !!m.pinned, + folders: foldersOf(name, projects), ready: !!p, email: p?.account?.emailAddress || '', org: p?.account?.organizationName || '', @@ -147,9 +148,9 @@ function startLogin(name) { // Opens a terminal running `cmd` for this profile. Returns the same command for running by hand // (shown on Linux, where there may be no terminal app we know). +const shq = (s) => `'${s.replace(/'/g, `'\\''`)}'`; // POSIX shell single-quoting function openTerminal(configDir, cmd) { - const q = (s) => `'${s.replace(/'/g, `'\\''`)}'`; - const manual = `CLAUDE_CONFIG_DIR=${q(configDir)} ${cmd}`; + const manual = `CLAUDE_CONFIG_DIR=${shq(configDir)} ${cmd}`; if (process.platform === 'win32') { // `start` opens a new console window; it inherits CLAUDE_CONFIG_DIR from env. cp.spawn('cmd.exe', ['/c', 'start', '"Claude login"', 'cmd', '/c', `"${cmd} & pause"`], @@ -207,6 +208,7 @@ function use(name) { if (target.account) config.oauthAccount = target.account; else delete config.oauthAccount; // Claude Code refetches it; a stale one would show the wrong email writeAtomic(activeConfigFile(), JSON.stringify(config, null, 2)); + try { refreshFolders(); } catch {} // the folders' launcher depends on which account is active return { backupDir }; } @@ -224,9 +226,11 @@ function remove(name) { delete usageCache[name]; delete lastSeen[name]; saveUsageCache(); - const { accounts = {}, order = [] } = readConfig(); + const { accounts = {}, order = [], projects = {} } = readConfig(); delete accounts[name]; - writeConfig({ accounts, order: order.filter((n) => n !== name) }); + for (const f of foldersOf(name, projects)) delete projects[f]; + writeConfig({ accounts, order: order.filter((n) => n !== name), projects }); + refreshFolders(); } // Sign an existing account in again. The dead login is dropped first, so the card waits for the new one. @@ -299,6 +303,8 @@ async function fetchUsage(name) { const active = activeOauth(); const mine = profileKey(name, oauth); const isActive = mine !== null && mine === activeKey(); + const inFolders = foldersOf(name).length > 0; // Claude Code runs this login from its profile and refreshes it there + if (inFolders && MAC) oauth = readJsonStr(kcRead(serviceFor(profileDir(name)))?.raw)?.claudeAiOauth || oauth; // its live copy if (isActive) { // Claude Code owns the active login: use its freshest token and never refresh it ourselves (that would log it out). // Claude Code also keeps this account's usage on disk; reuse it when fresh instead of asking Anthropic again. @@ -313,6 +319,10 @@ async function fetchUsage(name) { if (c?.data && now - c.at < USAGE_GAP) return c.data; if (c?.retryAt > now) return staleOrThrow(c); if (!isActive && expired(oauth)) { + if (inFolders) { // refreshing here would log out the Claude Code sessions using it + if (c?.data) return { ...c.data, stale: c.at }; + throw new Error('Usage shows once Claude Code runs in its folder again.'); + } oauth = await refresh(oauth); writeAtomic(f, JSON.stringify({ ...saved, claudeAiOauth: oauth })); // the old refresh token is now dead; save at once } @@ -351,7 +361,7 @@ function bestAccount(pool) { // pool: only consider these names function autoSwitchTarget() { const s = getSettings(); if (!s.autoSwitch) return null; - const pool = list().profiles.filter((p) => p.ready && !p.folders?.length && !s.autoSwitchSkip.includes(p.name)); + const pool = list().profiles.filter((p) => p.ready && !s.autoSwitchSkip.includes(p.name)); const active = pool.find((p) => p.active), u = active && lastSeen[active.name]; if (!u || leftOf(u) > 0) return null; const best = bestAccount(pool.map((p) => p.name)); @@ -419,6 +429,79 @@ function reorder(order) { writeConfig({ order: [...new Set(order)] }); } +// --- folder accounts: Claude Code for VS Code uses one account in a folder and everything inside it --- +// VS Code starts Claude through our launcher (its claudeCode.claudeProcessWrapper setting), which sets CLAUDE_CONFIG_DIR +// from the folder Claude starts in. That makes the profile's login live, so a folder account can't also be the active +// login (two live copies of one refresh token log each other out), and Switcher never refreshes it. +const norm = (p) => (process.platform === 'linux' ? p : p.toLowerCase()); // Windows and macOS ignore case by default +const foldersOf = (name, projects = readConfig().projects || {}) => Object.keys(projects).filter((f) => projects[f] === name); + +// The profile folder for a working directory, or null for the active login. The deepest matching folder wins. +// A folder whose account is the active login needs no override: Claude Code already runs that login from ~/.claude, and a second +// live copy of one refresh token would log the other out. +function isActive(name) { + const p = loadProfile(name), cur = activeKey(); + return !!(p && cur && profileKey(name, p.oauth) === cur); +} +function configDirFor(cwd) { + const projects = readConfig().projects || {}; + const here = norm(path.resolve(cwd)); + const hit = Object.keys(projects).sort((a, b) => b.length - a.length) + .find((f) => here === norm(f) || here.startsWith(norm(f) + path.sep)); + return hit && !isActive(projects[hit]) ? profileDir(projects[hit]) : null; +} + +function bind(folder, name) { + checkName(name); + if (typeof folder !== 'string' || !path.isAbsolute(folder)) throw new Error('Choose a folder.'); + const f = path.resolve(folder); + if (path.parse(f).root === f) throw new Error('Choose a project folder, not a whole drive.'); + if (!fs.statSync(f, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`${f} isn't a folder.`); + const p = loadProfile(name); + if (!p) throw new Error(`"${name}" has no saved login yet.`); + const projects = readConfig().projects || {}; + for (const k of Object.keys(projects)) if (norm(k) === norm(f)) delete projects[k]; // a folder has one account + projects[f] = name; + writeConfig({ projects }); + refreshFolders(); + return f; +} + +function unbind(folder) { + const projects = readConfig().projects || {}; + for (const k of Object.keys(projects)) if (norm(k) === norm(String(folder))) delete projects[k]; + writeConfig({ projects }); + refreshFolders(); +} + +// Your own Claude Code setup and session history, linked into folder accounts' profiles so nothing goes missing there and +// VS Code still lists their sessions. Login, policy limits and remote settings belong to an account or organisation: not shared. +const SHARED = ['settings.json', 'CLAUDE.md', 'keybindings.json', 'agents', 'commands', 'skills', 'plugins', 'hooks', 'output-styles', + 'projects', 'history.jsonl', 'file-history', 'todos', 'plans', 'session-env', 'shell-snapshots', 'paste-cache', 'sessions', 'ide']; +function shareSetup(dir) { + for (const e of SHARED) { + const from = path.join(os.homedir(), '.claude', e), to = path.join(dir, e); + const st = fs.statSync(from, { throwIfNoEntry: false }); + if (!st || fs.lstatSync(to, { throwIfNoEntry: false })) continue; // never replace what's already there + // shortcut: without Windows Developer Mode a file gets a hard link, which goes stale if Claude Code replaces the file; upgrade if that bites + try { fs.symlinkSync(from, to, st.isDirectory() ? 'junction' : 'file'); } catch (err) { if (!st.isFile()) throw err; fs.linkSync(from, to); } + } +} + +// Re-links the shared setup (new files in ~/.claude) and rewrites the macOS/Linux launcher: a shell script with the folders +// baked in. Windows can't start a script from VS Code, so there Switcher.exe itself is the launcher (see main.js). +const launcherFile = () => path.join(root(), 'claude-launcher.sh'); +function refreshFolders() { + const projects = readConfig().projects || {}; + for (const name of new Set(Object.values(projects))) if (fs.existsSync(profileDir(name))) shareSetup(profileDir(name)); + if (process.platform === 'win32') return; + const cases = Object.keys(projects).filter((f) => !isActive(projects[f])).sort((a, b) => b.length - a.length) + .map((f) => ` ${shq(f)}|${shq(f)}/*) CLAUDE_CONFIG_DIR=${shq(profileDir(projects[f]))}; export CLAUDE_CONFIG_DIR ;;`); + writeAtomic(launcherFile(), ['#!/bin/sh', '# Written by Switcher: starts Claude Code with the account set for the folder it runs in.', + 'case "$PWD" in', ...cases, 'esac', 'exec "$@"', ''].join('\n')); + fs.chmodSync(launcherFile(), 0o755); +} + // --- session manager: keeps a 5-hour window running on every account --- const sessionStatus = {}; // name -> { at, error? } for the last start attempt const getSessions = () => { const c = readConfig(); return { autoStart: !!c.autoStart, message: c.message || 'hi', status: sessionStatus }; }; @@ -500,6 +583,7 @@ const api = { use: serial(use), remove: serial(remove), relogin: serial(relogin) module.exports = { list, startLogin, ...api, retryUsage, getSessions, setSessions, keepSessions, + bind, unbind, configDirFor, refreshFolders, launcherFile, getSettings, setSettings, setAccountMeta, reorder, bestAccount, autoSwitchTarget, usageAlerts, LABEL_COLORS, kcWrite, // for the tests; the app only calls it on macOS }; diff --git a/core.test.js b/core.test.js index d2d79b9..c5f9fab 100644 --- a/core.test.js +++ b/core.test.js @@ -300,6 +300,96 @@ test('notifications fire only when a threshold is crossed', () => { assert.match(core.usageAlerts('work', r(90, 50), r(100, 50))[0].text, /^work reached its session limit\. It resets in 1 hr \d+ min\.$/); }); +test('folder accounts: the deepest folder wins, the active account works in folders too, whole drives are refused, remove cleans up', fileOnly, async () => { + const c = fresh(); + const live = { expiresAt: Date.now() + 864e5 }; + for (const [n, id] of [['work', 'W'], ['client', 'C'], ['me', 'M']]) put(`.claude-profiles/${n}/.credentials.json`, { claudeAiOauth: oauth(id, n, live) }); + put('.claude/.credentials.json', { claudeAiOauth: oauth('M', 'me', live) }); // "me" is active + const proj = path.join(home, 'code', 'proj'), inner = path.join(proj, 'vendor', 'sdk'); + fs.mkdirSync(inner, { recursive: true }); + const dirOf = (n) => path.join(home, '.claude-profiles', n); + + assert.equal(c.bind(proj, 'work'), proj); + c.bind(inner, 'client'); + assert.equal(c.configDirFor(path.join(proj, 'src')), dirOf('work')); + assert.equal(c.configDirFor(path.join(inner, 'lib')), dirOf('client'), 'the deepest folder wins'); + assert.equal(c.configDirFor(proj + '-other'), null, 'a sibling with the same prefix is not inside'); + assert.equal(c.configDirFor(home), null, 'elsewhere: the active login'); + if (process.platform === 'win32') assert.equal(c.configDirFor(proj.toUpperCase()), dirOf('work'), 'Windows paths ignore case'); + + assert.throws(() => c.bind(path.parse(home).root, 'work'), /not a whole drive/); + assert.throws(() => c.bind(path.join(home, 'missing'), 'work'), /isn't a folder/); + assert.throws(() => c.bind('relative', 'work'), /Choose a folder/); + assert.deepEqual(c.list().profiles.find((p) => p.name === 'work').folders, [proj]); + + // The account can still be the active login. Then its folders need no override: one live copy of the login, not two. + await c.use('work'); + assert.equal(c.configDirFor(path.join(proj, 'src')), null, 'work is active: Claude Code runs it from ~/.claude'); + assert.equal(c.configDirFor(path.join(inner, 'lib')), dirOf('client'), 'client is not active: its own profile'); + await c.use('me'); + assert.equal(c.configDirFor(path.join(proj, 'src')), dirOf('work'), 'switched away: the folder runs it from its profile again'); + + c.bind(proj, 'client'); // a folder has one account + assert.deepEqual(c.list().profiles.find((p) => p.name === 'work').folders, []); + c.unbind(inner); + assert.equal(c.configDirFor(inner), dirOf('client'), 'still inside proj'); + await c.remove('client'); + assert.equal(c.configDirFor(proj), null); + assert.deepEqual(j('.claude-profiles/.switcher.json').projects, {}); +}); + +test('folder accounts share your Claude Code setup, never the login or org files; removing one keeps the originals', fileOnly, async () => { + const c = fresh(); + put('.claude-profiles/work/.credentials.json', { claudeAiOauth: oauth('W', 'w', { expiresAt: Date.now() + 864e5 }) }); + put('.claude/.credentials.json', { claudeAiOauth: oauth('M', 'me') }); + put('.claude/settings.json', { theme: 'dark' }); + put('.claude/policy-limits.json', { org: 'someone else' }); + put('.claude/projects/p/session.jsonl', { keep: true }); + fs.writeFileSync(path.join(home, '.claude', 'CLAUDE.md'), 'mine'); + const prof = path.join(home, '.claude-profiles', 'work'); + c.bind(fs.mkdtempSync(path.join(home, 'proj-')), 'work'); + + assert.equal(fs.readFileSync(path.join(prof, 'CLAUDE.md'), 'utf8'), 'mine'); + assert.deepEqual(j('.claude-profiles/work/settings.json'), { theme: 'dark' }); + assert.ok(fs.existsSync(path.join(prof, 'projects', 'p', 'session.jsonl')), 'sessions are shared, so VS Code still lists them'); + assert.ok(!fs.existsSync(path.join(prof, 'policy-limits.json')), 'organisation files stay per account'); + assert.equal(j('.claude-profiles/work/.credentials.json').claudeAiOauth.accessToken, 'w', 'its own login is untouched'); + + await c.remove('work'); + assert.ok(!fs.existsSync(prof)); + assert.deepEqual(j('.claude/projects/p/session.jsonl'), { keep: true }, 'removing the profile drops only the links'); + assert.equal(fs.readFileSync(path.join(home, '.claude', 'CLAUDE.md'), 'utf8'), 'mine'); +}); + +test("usage never refreshes a folder account's login (Claude Code does that in its folder)", fileOnly, async () => { + const c = fresh(); + put('.claude-profiles/work/.credentials.json', { claudeAiOauth: oauth('W', 'w-old', { expiresAt: 0 }) }); + put('.claude/.credentials.json', { claudeAiOauth: oauth('M', 'me', { expiresAt: Date.now() + 864e5 }) }); + c.bind(fs.mkdtempSync(path.join(home, 'proj-')), 'work'); + const calls = []; + global.fetch = async (url) => { calls.push(url); return new Response('{}'); }; + await assert.rejects(c.usage('work'), /once Claude Code runs in its folder/); + assert.deepEqual(calls, [], 'no token refresh, no usage call with a dead token'); + assert.equal(j('.claude-profiles/work/.credentials.json').claudeAiOauth.refreshToken, 'w-old'); +}); + +test('the shell launcher (macOS/Linux) sets CLAUDE_CONFIG_DIR only inside a folder account', { skip: process.platform !== 'linux' }, async () => { + const c = fresh(); + put('.claude-profiles/work/.credentials.json', { claudeAiOauth: oauth('W', 'w', { expiresAt: Date.now() + 864e5 }) }); + put('.claude/.credentials.json', { claudeAiOauth: oauth('M', 'me') }); + const proj = fs.mkdtempSync(path.join(home, "it's a proj-")); // a quote in the path + fs.mkdirSync(path.join(proj, 'src')); + c.bind(proj, 'work'); + const env = { ...process.env }; + delete env.CLAUDE_CONFIG_DIR; + const run = (cwd) => require('child_process').execFileSync(c.launcherFile(), ['sh', '-c', 'printf %s "${CLAUDE_CONFIG_DIR:-none}"'], + { cwd, env: { ...env, PWD: cwd }, encoding: 'utf8' }); + assert.equal(run(path.join(proj, 'src')), path.join(home, '.claude-profiles', 'work')); + assert.equal(run(home), 'none'); + await c.use('work'); + assert.equal(run(path.join(proj, 'src')), 'none', 'its account is the active one: no override'); +}); + test('accounts are told apart by .claude.json when the login has no accountUuid (some Claude Code versions)', fileOnly, async () => { const c = fresh(); const bare = (token, extra = {}) => ({ accessToken: token, refreshToken: token, expiresAt: Date.now() + 864e5, ...extra }); diff --git a/index.html b/index.html index 6fdac15..6c2c3bf 100644 --- a/index.html +++ b/index.html @@ -71,6 +71,10 @@

Settings

Quick switcher +
@@ -122,6 +126,34 @@

General

+ + + + diff --git a/main.js b/main.js index e999572..a56f5d9 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, ipcMain, nativeTheme, shell, Tray, Menu, nativeImage, Notification, globalShortcut, screen } = require('electron'); +const { app, BrowserWindow, ipcMain, nativeTheme, shell, Tray, Menu, nativeImage, Notification, globalShortcut, screen, dialog } = require('electron'); const { autoUpdater } = require('electron-updater'); const cp = require('child_process'); const fs = require('fs'); @@ -7,6 +7,19 @@ const path = require('path'); const core = require('./core'); const { statusTag } = require('./tags'); +// Windows launcher for folder accounts: VS Code's claudeCode.claudeProcessWrapper runs `Switcher.exe `. +// Start Claude with the account set for the folder it runs in, hand it our pipes, and exit with its code. +const launch = process.argv.slice(process.defaultApp ? 2 : 1); +if (process.platform === 'win32' && path.isAbsolute(launch[0] || '') && /^claude(\.exe)?$/i.test(path.basename(launch[0]))) { + app.disableHardwareAcceleration(); + app.setPath('userData', path.join(os.tmpdir(), 'switcher-launcher')); // stay out of the running app's browser profile + const dir = core.configDirFor(process.cwd()); + const child = cp.spawn(launch[0], launch.slice(1), { stdio: 'inherit', windowsHide: true, env: dir ? { ...process.env, CLAUDE_CONFIG_DIR: dir } : process.env }); + child.on('error', (e) => { process.stderr.write(`Switcher couldn't start Claude Code: ${e.message}\n`); app.exit(1); }); + child.on('exit', (code) => app.exit(code ?? 1)); + return; // CommonJS module: skip the app below +} + // Apps started from the macOS Dock/Finder or a Linux app menu don't get the login shell's PATH, so `claude` // (in ~/.local/bin, Homebrew, npm's bin...) wouldn't be found. Ask the user's shell once, plus the usual install dirs. if (process.platform !== 'win32') { @@ -223,7 +236,8 @@ function rebuildTray() { const s = core.getSettings(); const active = profiles.find((p) => p.active); const managed = core.getSessions().autoStart; - const tagText = (p) => statusTag({ usage: lastUsage[p.name], error: expiredSeen.has(p.name) ? 'Expired' : null, active: p.active, best: p.name === best, managed, pinned: p.pinned })?.text; + const tagOf = (p) => statusTag({ usage: lastUsage[p.name], error: expiredSeen.has(p.name) ? 'Expired' : null, active: p.active, best: p.name === best, managed, pinned: p.pinned }); + const tagText = (p) => tagOf(p)?.text; const usageText = (u) => (u ? `${Math.round(u.session.pct)}% session · ${Math.round(u.week.pct)}% week` : ''); const au = active && usageText(lastUsage[active.name]); tray.setToolTip(active ? `Switcher · ${labelOf(active)}${au ? ` · ${au}` : ''}` : 'Switcher'); @@ -269,7 +283,9 @@ function setLoginItem(on) { app.setLoginItemSettings({ openAtLogin: on, args: ['--hidden'] }); } -const settingsForUI = () => ({ ...core.getSettings(), loginSupported: app.isPackaged }); +// The value for VS Code's claudeCode.claudeProcessWrapper; empty in a Windows dev run (the bare Electron binary can't be it). +const launcher = () => (process.platform !== 'win32' ? core.launcherFile() : app.isPackaged ? process.execPath : ''); +const settingsForUI = () => ({ ...core.getSettings(), loginSupported: app.isPackaged, launcher: launcher() }); async function applySettings(patch) { const prev = core.getSettings(); const next = core.setSettings(patch); // validates @@ -289,6 +305,12 @@ const api = { remove: async (name) => { await core.remove(name); changed(); }, meta: (m) => { core.setAccountMeta(m); changed(); }, reorder: (order) => { core.reorder(order); changed(); }, + pickFolder: async () => { + const r = await dialog.showOpenDialog(win, { title: 'Choose a folder', buttonLabel: 'Use this folder', properties: ['openDirectory'] }); + return r.canceled ? null : r.filePaths[0] || null; + }, + bind: ({ folder, name } = {}) => { core.bind(folder, name); changed(); }, + unbind: (folder) => { core.unbind(folder); changed(); }, best: core.bestAccount, sessions: core.getSessions, setSessions: core.setSessions, settings: settingsForUI, setSettings: applySettings, @@ -331,6 +353,7 @@ else { const s = core.getSettings(); registerShortcut(s.shortcut); setLoginItem(s.startAtLogin); // re-applied each start, so the path stays right after updates + try { core.refreshFolders(); } catch {} // links setup files added to ~/.claude since, rewrites the launcher rebuildTray(); setInterval(rebuildTray, 60e3); // picks up accounts added in the main window core.keepSessions(); diff --git a/release-notes.json b/release-notes.json index 5cd38d4..fe2c5fa 100644 --- a/release-notes.json +++ b/release-notes.json @@ -1,4 +1,13 @@ [ + { + "id": "2026-12-01-folders", + "date": "2026-12-01", + "title": "Folder accounts", + "items": [ + { "tag": "New", "text": "Give a project folder its own account: in that folder, Claude Code in VS Code uses it. Everywhere else it uses the active account." }, + { "tag": "New", "text": "Settings → Folder accounts has a guide with the four VS Code steps, one at a time. The ? icon shows it again." } + ] + }, { "id": "2026-12-01", "date": "2026-12-01", diff --git a/renderer.js b/renderer.js index 192c285..4b3c21e 100644 --- a/renderer.js +++ b/renderer.js @@ -97,6 +97,43 @@ function cardMenu(p, i) { item('Remove', () => remove(p.name), false, 'danger')); } +// --- folder accounts: in a folder, Claude Code in VS Code uses the account picked in Settings; everywhere else, the active one --- +const baseName = (f) => f.split(/[\\/]/).filter(Boolean).pop() || f; +// The folder's parent path, shortened from the left so the part nearest the folder stays; the full path is the tooltip. +const shortPath = (f, max = 40) => { + const p = f.slice(0, f.length - baseName(f).length).replace(/[\\/]+$/, ''); + if (p.length <= max) return p; + const t = p.slice(-max), i = t.search(/[\\/]/); + return '…' + (i < 0 ? t : t.slice(i)); +}; +const folderChip = (f) => el('span', { className: 'folder', title: f, textContent: baseName(f) }); +// Cards show the first three folders, then "+N". +const folderChips = (fs) => [...fs.slice(0, 3).map(folderChip), ...(fs.length > 3 ? [el('span', { className: 'folder', title: fs.slice(3).join('\n'), textContent: `+${fs.length - 3}` })] : [])]; + +// Errors show inside the pane: the settings dialog is modal, so the sidebar message sits behind it. +async function folderCall(fn, arg) { + try { await window.call(fn, arg); $('folderMsg').textContent = ''; return true; } + catch (e) { $('folderMsg').textContent = clean(e); return false; } + finally { refresh(); } +} +function folderPane() { + const ready = data.profiles.filter((p) => p.ready); + const options = (sel) => ready.map((p) => el('option', { value: p.name, textContent: labelOf(p), selected: p.name === sel })); + const rows = data.profiles.flatMap((p) => p.folders.map((f) => [f, p])).sort(([a], [b]) => a.localeCompare(b)); + $('folderList').replaceChildren(...(rows.length ? rows.map(([f, p]) => { + const pick = el('select', { ariaLabel: `Account for ${f}`, onchange: () => folderCall('bind', { folder: f, name: pick.value }) }, ...options(p.name)); + return el('div', { className: 'setting folder-row' }, el('div', { className: 'path', title: f }, baseName(f), el('small', { textContent: shortPath(f) })), pick, + button('×', () => folderCall('unbind', f), 'link')); + }) : [el('small', { className: 'empty', textContent: 'No folders yet. Claude Code uses the active account everywhere.' })])); + $('folderAccount').replaceChildren(...options($('folderAccount').value)); + $('folderAdd').querySelector('[type=submit]').disabled = !ready.length; +} +$('folderChoose').onclick = async () => { const f = await window.call('pickFolder').catch(() => null); if (f) $('folderPath').value = f; }; +$('folderAdd').onsubmit = async (e) => { + e.preventDefault(); + if (await folderCall('bind', { folder: $('folderPath').value.trim(), name: $('folderAccount').value })) $('folderPath').value = ''; +}; + async function meta(m) { openMenu = null; await run('meta', m); @@ -136,7 +173,8 @@ function card(p, i) { p.color ? el('span', { className: `dot ${p.color}`, ariaHidden: 'true' }) : '', title, plan ? el('span', { className: 'plan', textContent: plan }) : '', p.pinned ? el('span', { className: 'plan', textContent: 'pinned' }) : '', - el('small', { textContent: p.ready ? [p.email, p.org].filter(Boolean).join(' · ') : 'Waiting for login in the terminal window...' })); + el('small', { textContent: p.ready ? [p.email, p.org].filter(Boolean).join(' · ') : 'Waiting for login in the terminal window...' }), + p.folders.length ? el('div', { className: 'folders' }, 'Used in', ...folderChips(p.folders)) : ''); const more = button('⋯', (e) => { e.stopPropagation(); openMenu = openMenu === p.name ? null : p.name; render(); }, 'link more'); more.ariaLabel = `More actions for ${labelOf(p)}`; more.setAttribute('aria-haspopup', 'menu'); @@ -240,7 +278,7 @@ const codeKey = (c) => (/^Key[A-Z]$/.test(c) ? c.slice(3) : /^Digit\d$/.test(c) // Auto switch: which accounts take part (all by default; folder accounts can't be switched to). function autoList() { const skip = settings.autoSwitchSkip || []; - $('autoList').replaceChildren(...data.profiles.filter((p) => p.ready && !p.folders?.length).map((p) => { + $('autoList').replaceChildren(...data.profiles.filter((p) => p.ready).map((p) => { const box = el('input', { type: 'checkbox', className: 'switch', id: `auto-${p.name}`, checked: !skip.includes(p.name), disabled: !settings.autoSwitch }); box.setAttribute('role', 'switch'); box.onchange = () => saveSettings({ autoSwitchSkip: box.checked ? skip.filter((n) => n !== p.name) : [...skip, p.name] }); @@ -255,6 +293,9 @@ function showSettings() { $('startAtLogin').disabled = !settings.loginSupported; $('notify').checked = settings.notify; if (document.activeElement !== $('shortcut')) $('shortcut').value = prettyKey(settings.shortcut); + $('launcher').value = settings.launcher || ''; + $('copyLauncher').disabled = !settings.launcher; + if (!settings.launcher) $('launcherHint').textContent = 'Works in the installed app.'; } async function loadSettings() { @@ -277,6 +318,11 @@ $('startAtLogin').onchange = () => saveSettings({ startAtLogin: $('startAtLogin' $('autoSwitch').onchange = () => saveSettings({ autoSwitch: $('autoSwitch').checked }); $('notify').onchange = () => saveSettings({ notify: $('notify').checked }); $('clearShortcut').onclick = () => saveSettings({ shortcut: '' }); +$('copyLauncher').onclick = async () => { + await navigator.clipboard.writeText($('launcher').value); + $('copyLauncher').textContent = 'Copied'; + setTimeout(() => ($('copyLauncher').textContent = 'Copy'), 1500); +}; $('shortcut').onfocus = () => { $('shortcut').value = 'Press a key combination...'; }; $('shortcut').onblur = showSettings; $('shortcut').onkeydown = (e) => { @@ -298,7 +344,35 @@ function showPane(id) { if (on) b.setAttribute('aria-current', 'page'); else b.removeAttribute('aria-current'); $(b.dataset.pane).hidden = !on; } -} + if (id !== 'paneFolders') guide.classList.remove('open'); + else firstGuide(); +} +// --- Folder accounts: the "Set up VS Code" side panel. It opens by itself the first time the pane is shown. --- +const guide = $('guide'); +for (const k of guide.querySelectorAll('[data-mod]')) k.textContent = mod; // Ctrl or Cmd +// One step at a time, with Back and Next; Next on the last step is Done. +const steps = [...guide.querySelectorAll('ol > li')]; +let gStep = 0; +function showStep(i) { + gStep = Math.min(Math.max(i, 0), steps.length - 1); + steps.forEach((li, n) => (li.hidden = n !== gStep)); + guide.querySelectorAll('.dots i').forEach((d, n) => d.classList.toggle('on', n === gStep)); + $('guideCount').textContent = `Step ${gStep + 1} of ${steps.length}`; + $('guideBack').hidden = gStep === 0; + $('guideNext').textContent = gStep === steps.length - 1 ? 'Done' : 'Next'; + guide.querySelector('ol').scrollTop = 0; +} +$('guideBack').onclick = () => showStep(gStep - 1); +$('guideNext').onclick = () => (gStep === steps.length - 1 ? closeGuide() : showStep(gStep + 1)); +function openGuide() { showStep(0); guide.classList.add('open'); $('guideNext').focus({ preventScroll: true }); } +function closeGuide() { guide.classList.remove('open'); $('guideOpen').focus({ preventScroll: true }); } +function firstGuide() { + try { if (localStorage.getItem('folderGuide')) return; localStorage.setItem('folderGuide', '1'); } catch { return; } // can't remember: don't pop up every time + openGuide(); +} +$('guideOpen').onclick = openGuide; +$('guideClose').onclick = closeGuide; + function openSettings() { if (dialog.open) return; dialog.showModal(); @@ -308,7 +382,11 @@ for (const b of document.querySelectorAll('.nav-item')) b.onclick = () => showPa $('openSettings').onclick = openSettings; $('closeSettings').onclick = () => dialog.close(); dialog.onclick = (e) => { if (e.target === dialog) dialog.close(); }; // a click on the backdrop -dialog.oncancel = (e) => { if (document.activeElement === $('shortcut')) { e.preventDefault(); $('shortcut').blur(); } }; // Esc while recording cancels only that +dialog.onclose = () => guide.classList.remove('open'); +dialog.oncancel = (e) => { + if (guide.classList.contains('open')) { e.preventDefault(); closeGuide(); } // Esc closes the guide first + else if (document.activeElement === $('shortcut')) { e.preventDefault(); $('shortcut').blur(); } +}; // Esc while recording cancels only that $('settingsKey').textContent = `${mod}+,`; document.addEventListener('keydown', (e) => { if (e.key === ',' && (MAC ? e.metaKey : e.ctrlKey)) { e.preventDefault(); openSettings(); } }); @@ -318,6 +396,7 @@ async function refresh() { data = d; render(); autoList(); + folderPane(); loadUsage(); } @@ -386,6 +465,11 @@ $('add').onsubmit = async (e) => { // Close the ⋯ menu on an outside click or Escape. document.addEventListener('click', () => { if (openMenu) { openMenu = null; render(); } }); document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && openMenu) { openMenu = null; render(); } }); +document.addEventListener('keydown', (e) => { // ← and → move through the guide's steps + if (!guide.classList.contains('open') || e.altKey || e.ctrlKey || e.metaKey) return; + if (e.key === 'ArrowRight' && gStep < steps.length - 1) showStep(gStep + 1); + if (e.key === 'ArrowLeft' && gStep > 0) showStep(gStep - 1); +}); window.onEvent('changed', () => { refresh(); loadSettings(); }); // switched from the tray or quick switcher setInterval(() => data.profiles.some((p) => !p.ready) && refresh(), 3000); diff --git a/styles.css b/styles.css index 450cdab..b0f16ac 100644 --- a/styles.css +++ b/styles.css @@ -121,6 +121,11 @@ button.link { background: transparent; border-color: transparent; padding: 0 8px .teal { --label: var(--label-teal); } .stone { --label: var(--label-stone); } +/* Folder accounts: where an account is used, as removable chips under its email */ +.row > div .folders { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font: 400 13px/1.4 var(--sans); color: var(--muted); } +.folder { display: inline-block; max-width: 160px; padding: 1px 10px; border-radius: 9999px; background: var(--pill); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.pane-intro { margin: 0 0 8px; color: var(--muted); font-size: 14px; } + /* Card ⋯ menu */ .row { position: relative; } button.more { padding: 0 10px; font-size: 18px; letter-spacing: 1px; } @@ -238,6 +243,49 @@ input:not([type=checkbox]):focus-visible { outline: none; border-color: var(--fo #msg { margin: 16px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; } #msg.err { color: var(--error); } +/* Settings → Folder accounts */ +/* A line chevron like the browser's own, but inset 10px from the edge (the native one hugs it); mid-grey works on both themes. */ +select { height: 40px; padding: 0 34px 0 12px; border: 1px solid var(--field-line); border-radius: 8px; color: var(--ink); font: 400 14px/1 var(--sans); cursor: pointer; + appearance: none; background: var(--canvas) url(assets/chevron.svg) no-repeat right 10px center / 16px; } +.folder-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px auto; align-items: center; gap: 12px; padding: 10px 0; } +.folder-row .path { min-width: 0; font: 500 15px/1.4 var(--sans); } +.folder-row .path small { display: block; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.folder-row .path small:empty { display: none; } +.folder-row select, .folder-add select { width: 128px; } +.folder-add { display: grid; grid-template-columns: minmax(0, 1fr) auto 128px auto; align-items: center; gap: 8px; padding: 12px 0 0; } +.folder-add input { min-width: 0; } +#folderMsg { display: block; min-height: 1.4em; } +#folderList + .setting { margin-top: 8px; border-top: 1px solid var(--hairline); } + +/* Folder accounts: the "Set up VS Code" side panel. Its pictures are real VS Code screenshots (assets/guide), each a short + before/after clip; reduced motion gets the still. */ +.settings-body { position: relative; overflow: hidden; } +.pane-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; } +.guide { position: absolute; top: 0; right: 0; bottom: 0; width: min(480px, 100%); display: flex; flex-direction: column; padding: 0; overflow: hidden; border-right: 0; border-left: 1px solid var(--hairline); background: var(--card); + box-shadow: -8px 0 24px rgb(20 20 19 / 0.10); transform: translateX(100%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; } +.settings-body:has(.guide.open) #paneFolders { opacity: .4; pointer-events: none; } +#paneFolders { transition: opacity .2s; } +.guide.open { transform: none; visibility: visible; transition: transform .22s ease, visibility 0s; } +.guide header { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px 12px 8px 20px; } +.guide h3 { margin: 0; font: 500 16px/1.4 var(--sans); } +.guide ol { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 8px 20px 16px; list-style: none; } +.guide li[hidden] { display: none; } +.guide h4 { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font: 500 15px/1.4 var(--sans); } +.guide h4 span { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; font: 500 12px/1 var(--sans); } +.guide li p { margin: 0 0 10px 32px; color: var(--muted); font-size: 14px; } +.guide li p b { color: var(--ink); font-weight: 500; } +.guide kbd { padding: 1px 6px; border: 1px solid var(--hairline); border-bottom-width: 2px; border-radius: 5px; background: var(--pill); color: var(--ink); font: 500 12px/1.4 var(--sans); } +.guide li p.guide-note { margin: 12px 0 0; font-size: 13px; } +.guide-nav { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--hairline); } +.dots { display: flex; gap: 6px; margin-right: auto; } +.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--track); } +.dots i.on { background: var(--primary); } +.guide li { padding: 0; border: 0; background: transparent; } +.guide picture { display: block; } +.guide li.tall img { max-width: 250px; } +.guide img { display: block; width: 100%; height: auto; border: 1px solid var(--hairline); border-radius: 10px; } +@media (prefers-reduced-motion: reduce) { .guide { transition: none; } } + /* Side panel: slides over the right of the window (What's new) */ .scrim { position: fixed; inset: 0; z-index: 4; background: rgb(20 20 19 / 0.25); opacity: 0; visibility: hidden; transition: opacity .22s ease, visibility 0s linear .22s; } .scrim.open { opacity: 1; visibility: visible; transition: opacity .22s ease, visibility 0s; }