{"_id":"@fairy-pitta/cc-account-switcher","_rev":"7-f8ab4e758e7f90053de5ff4baa53540c","name":"@fairy-pitta/cc-account-switcher","dist-tags":{"latest":"0.7.0"},"versions":{"0.3.0":{"name":"@fairy-pitta/cc-account-switcher","version":"0.3.0","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.3.0","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"5d490a48f3bfde64dbc5389e672aef53e9028edf","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.3.0.tgz","fileCount":11,"integrity":"sha512-sSL58JbwPd1IRK2q0q3eqgSqIfvsuStUVG2xE3Fgj5/47X9YyZe62JkcQeCbmxbOtwQHAH58xO0gP1UGW8S5MQ==","signatures":[{"sig":"MEUCIDZGmSGjglgSlKU1tVutolxDLXyxn+BrKtrYCrPr5BkLAiEA5knFAn9ev1hEd5eCyxCgwI7Pq/4IRB3wcDQFv+nx7ps=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":102420},"engines":{"node":">=16"},"gitHead":"d0f59a8ba0d9dee8b4fc215bbc91a3eaa0a9b665","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"11.16.0","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.19.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.3.0_1780399437803_0.25760067714266466","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"name":"@fairy-pitta/cc-account-switcher","version":"0.3.1","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.3.1","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"6fec76042bb115bd187c29efb491430b464d91e3","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.3.1.tgz","fileCount":11,"integrity":"sha512-rvkG4udJCvXBN4AIvrQw+xXSE6YkOY2bvU5YtyhZo/SBgJpa+LO4HmCUPIEmYV7WxBOCj/zCITxvYEGBfe0fyw==","signatures":[{"sig":"MEUCIQDr9E+c672fq9E0X2f2YZw0kM72DEAaLYstE1xDJDoX1AIgJQx6IKt0gcJ1FChSXCwjvCwCTuvU1iWUdStlwHhuXlI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":103678},"engines":{"node":">=16"},"gitHead":"aca66f4519cd0b4639296434b9cb6bb4e38c0a09","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.3.1_1780466357770_0.8771429210753667","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"@fairy-pitta/cc-account-switcher","version":"0.4.0","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.4.0","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"20fd35ec59b36dd3dd0fea36f523bcad29ea7e7e","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.4.0.tgz","fileCount":13,"integrity":"sha512-ASzs5jKvB5MWBH527D4sJ7/jQpv8BbNZbOE/8OcyVSfJTdfoYd4Ho6tQqtMZn1PfcNaYOhEXgGQ74gQaptLGYQ==","signatures":[{"sig":"MEUCIQC5p2dfnQa/a9NTmLbW7viuAm8Qe8uLYK3xmv0EKAb0lAIgdMeYiPxLTXJXo0pxqcYzBoqAYercACZOepEqTN6bsH8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":131671},"engines":{"node":">=16"},"gitHead":"a9a727d8721097cdb57ec26ab71df8a788d0f970","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.4.0_1782368198570_0.3318994206845529","host":"s3://npm-registry-packages-npm-production"}},"0.4.1":{"name":"@fairy-pitta/cc-account-switcher","version":"0.4.1","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.4.1","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"3e924a0be3ba86750c160a1c81471580b41eca54","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.4.1.tgz","fileCount":13,"integrity":"sha512-2SQQusGGG27K2a1IwhKDs9tIqyCeoQQ+cbY4bk0DE9VJTLQco7S/41S6ekjM09XHssexzHZ/8wFFuTyF/gWM8Q==","signatures":[{"sig":"MEQCIApr4TnHBhLGd4OcqCBervzU0dXw1w/et87AwX/yXlF1AiBjT68UZ7/w6sl7xG6GmXVcVAn8MMraSFAL0H2NFRPZ+A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":136463},"engines":{"node":">=16"},"gitHead":"ac639956a5581e60bb31e5e4a1f1bf6ddacfff9d","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.4.1_1782377932332_0.21070516070657597","host":"s3://npm-registry-packages-npm-production"}},"0.5.0":{"name":"@fairy-pitta/cc-account-switcher","version":"0.5.0","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.5.0","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"f019ae9bb70047c879f3803b42515e5921cdf70e","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.5.0.tgz","fileCount":13,"integrity":"sha512-so5eft7wXLJa88JSYU77TvEYPoCW9byvN8xZrDd6v6MlSQ5D0Ro0DljaI9sthB3vOxS/y4ErXAzechC++gBj9A==","signatures":[{"sig":"MEUCID9lfJ8mbml/rV9a/7fs5w9oyTZ4tQhy08s1FnPR/BguAiEAk1aVcHCdM/e0YuZt5P/zIJUFIifjBQLmESgZCfHDgSs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":159804},"engines":{"node":">=16"},"gitHead":"54b516fdd5c6a55e6b1da65b50d0d9322aaca0ca","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.5.0_1785417847848_0.2081695237433272","host":"s3://npm-registry-packages-npm-production"}},"0.6.0":{"name":"@fairy-pitta/cc-account-switcher","version":"0.6.0","keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","_id":"@fairy-pitta/cc-account-switcher@0.6.0","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"os":["darwin","linux"],"bin":{"ccswitch":"bin/ccswitch"},"dist":{"shasum":"e5915c65090d02b17eb48e9adcb3e66d7f9670ef","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.6.0.tgz","fileCount":13,"integrity":"sha512-CQxpguVwJylEYHsVwebQAnA7g7hr8zNOjVErAhAZS8PQBtAFjouT1bE1R+nQea5btMP9HchFkyOSo1RTS3rUwQ==","signatures":[{"sig":"MEQCIBndO/FoRcXqNO3Tdm1FEptVM52kSNQAxOWzqtj7ySKRAiBKtFYLvGuK3jQL1Nc1zBbIpn+wRKWcEMn2T04PYEXJ3w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":179700},"engines":{"node":">=16"},"gitHead":"0e1d27f82d8bbffe5de7324c90a4f00564c961c6","_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"repository":{"url":"git+https://github.com/fairy-pitta/cc-account-switcher.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cc-account-switcher_0.6.0_1787123432507_0.8315608436824407","host":"s3://npm-registry-packages-npm-production"}},"0.7.0":{"name":"@fairy-pitta/cc-account-switcher","version":"0.7.0","description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","bin":{"ccswitch":"bin/ccswitch"},"keywords":["claude","claude-code","account-switcher","multi-account"],"license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/fairy-pitta/cc-account-switcher.git"},"bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","engines":{"node":">=16"},"os":["darwin","linux"],"_id":"@fairy-pitta/cc-account-switcher@0.7.0","gitHead":"43b13341f144c48143410eb42e9adb5f9973bf2e","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-JqXdZhycaGg6YlHjBLbOmq5hHOgsBJCmN3pj2X9Z0sUKaJk12D+tvyxdND75wjc+nAvkceF+pOlB4UkPm0EiGg==","shasum":"2fcb4228a1ae9ba85e019f4be5f4d36fca7887cb","tarball":"https://registry.npmjs.org/@fairy-pitta/cc-account-switcher/-/cc-account-switcher-0.7.0.tgz","fileCount":13,"unpackedSize":205263,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDfsgZjxtcmkCODVstReXmZSMYnVAM7dCMckRh95hnikAIgH3M9szTrXBw/U5oE3dsQPbmIY8rQEo4rS7jV3Ht7Wl0="}]},"_npmUser":{"name":"fairy-pitta","email":"shuna120700@gmail.com"},"directories":{},"maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cc-account-switcher_0.7.0_1787163258526_0.34219483210470836"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-02T11:23:57.586Z","modified":"2026-08-19T18:14:18.868Z","0.3.0":"2026-06-02T11:23:57.943Z","0.3.1":"2026-06-03T05:59:17.922Z","0.4.0":"2026-06-25T06:16:38.711Z","0.4.1":"2026-06-25T08:58:52.469Z","0.5.0":"2026-07-30T13:24:08.002Z","0.6.0":"2026-08-19T07:10:32.700Z","0.7.0":"2026-08-19T18:14:18.681Z"},"bugs":{"url":"https://github.com/fairy-pitta/cc-account-switcher/issues"},"license":"MIT","homepage":"https://github.com/fairy-pitta/cc-account-switcher#readme","keywords":["claude","claude-code","account-switcher","multi-account"],"repository":{"type":"git","url":"git+https://github.com/fairy-pitta/cc-account-switcher.git"},"description":"A simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL","maintainers":[{"name":"fairy-pitta","email":"shuna120700@gmail.com"}],"readme":"# Multi-Account Switcher for Claude Code\n\n**[日本語版はこちら](README.ja.md)**\n\n[![CI](https://github.com/fairy-pitta/cc-account-switcher/actions/workflows/ci.yml/badge.svg)](https://github.com/fairy-pitta/cc-account-switcher/actions/workflows/ci.yml)\n[![GitHub release](https://img.shields.io/github/v/release/fairy-pitta/cc-account-switcher?style=flat&color=blue)](https://github.com/fairy-pitta/cc-account-switcher/releases)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20WSL-brightgreen)](https://github.com/fairy-pitta/cc-account-switcher)\n[![Shell](https://img.shields.io/badge/shell-bash%203.2%2B-89e051)](https://github.com/fairy-pitta/cc-account-switcher)\n[![Tests](https://img.shields.io/badge/tests-85%20passing-success)](https://github.com/fairy-pitta/cc-account-switcher/actions)\n\n> Forked from [ming86/cc-account-switcher](https://github.com/ming86/cc-account-switcher) — thank you for the original work!\n\nA simple tool to manage and switch between multiple Claude Code accounts on macOS, Linux, and WSL.\n\n## Demo\n\n![demo](assets/demo.gif)\n\n## Features\n\n- **Multi-account management** — Add, remove, and list Claude Code accounts\n- **Quick switching** — Rotate accounts or switch to a specific one by number, email, or profile name\n- **Named profiles** — Give accounts friendly names like `work` or `personal`\n- **Directory-based auto-switching** — Map directories to accounts and auto-switch when you `cd`\n- **Dry-run mode** — Preview what a switch would do without making changes\n- **Rollback** — Automatic rollback if a switch fails mid-way\n- **Rate limit auto-switch** — Automatically switch accounts when usage limits are hit, via Claude Code hooks\n- **Custom endpoints** — Add `ANTHROPIC_BASE_URL` + API key/token providers (OpenRouter, gateways, proxies, self-hosted) as switchable accounts via `ccs add-endpoint`\n- **Conversation handoff** — `--resume` carries your current conversation across a switch, forking it or continuing the same session (`ccs resume-mode`)\n- **Parallel isolation** — Run commands as a specific account in their own `CLAUDE_CONFIG_DIR` (`ccs exec` / `config-dir`; Linux/WSL)\n- **Diagnostics** — Health checks, status, and per-account usage statistics\n- **Cross-platform** — Works on macOS, Linux, and WSL\n- **Secure storage** — Uses system keychain (macOS) or protected files (Linux/WSL)\n- **Settings preservation** — Only switches authentication; themes, settings, and preferences stay unchanged\n\n## Installation\n\n![install](assets/install.gif)\n\n### curl (quickest)\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/fairy-pitta/cc-account-switcher/main/ccswitch.sh -o /usr/local/bin/ccs\nchmod +x /usr/local/bin/ccs\n```\n\n### Homebrew (macOS)\n\n```bash\nbrew install fairy-pitta/tap/ccswitch\n```\n\n### npm / npx\n\n```bash\n# Install globally\nnpm install -g @fairy-pitta/cc-account-switcher\n\n# Or run without installing\nnpx @fairy-pitta/cc-account-switcher --help\n```\n\n### Make\n\n```bash\ngit clone https://github.com/fairy-pitta/cc-account-switcher.git\ncd cc-account-switcher\nsudo make install\n```\n\n### Manual\n\nDownload `ccswitch.sh` from the [latest release](https://github.com/fairy-pitta/cc-account-switcher/releases) and place it in your `$PATH` as `ccs`.\n\n## Quick Start\n\n![quickstart](assets/quickstart.gif)\n\n1. Log into Claude Code with your first account\n2. `ccs add` — save current credentials\n3. Log out, log into your second account\n4. `ccs add` — save the second set of credentials\n5. `ccs sw` — rotate between accounts\n6. Restart Claude Code after each switch\n\n> **What gets switched:** Only authentication credentials. Your themes, settings, preferences, and chat history remain unchanged.\n\n## Usage\n\n### Account Management\n\n```bash\nccs add                          # Add current account\nccs ls                           # List all managed accounts\nccs rm 2                         # Remove account by number\nccs rm user@example.com          # Remove account by email\n```\n\n### Switching\n\n```bash\nccs sw                           # Rotate to next account\nccs to 2                         # Switch to account #2\nccs to user@example.com          # Switch by email\nccs to work                      # Switch by profile name\nccs -n sw                        # Dry-run: preview what would happen\nccs sw -r                        # Switch and restart Claude Code\nccs sw --no-restart              # Switch without restart prompt\nccs to 2 --resume                # Switch to account 2 and resume the conversation\nccs to 2 --resume --no-fork-session   # Resume without forking (keeps the session id)\n```\n\n#### Resume your conversation after switching\n\n`ccs sw` / `ccs to` normally relaunch a fresh Claude Code session. Add `--resume` to\ncarry your current conversation across the switch:\n\n```bash\nccs to 2 --resume\n```\n\nThis captures the current directory's most recent session and relaunches Claude Code\nresuming it, so you continue the same conversation as the new account. If there's no\nprior conversation for the directory, it starts fresh.\n\n**Fork or same session.** There are two ways to come back into a conversation, and\n`--resume` can do either:\n\n| Mode | Relaunches with | Use it when |\n|------|-----------------|-------------|\n| `fork` (default) | `claude --resume <id> --fork-session` | You want the switched account to own a clean, isolated session. The fork gets a **new session id**. |\n| `same` | `claude --resume <id>` | You want to stay on one session id — so transcript watchers, orchestrators, and anything else keyed on the session keep following the same work trail. |\n\nPick per switch, or set a default:\n\n```bash\nccs to 2 --resume --fork-session      # force a fork for this switch\nccs to 2 --resume --no-fork-session   # force same-session for this switch\n\nccs resume-mode                       # show the current default\nccs resume-mode same                  # default to same-session from now on\nccs resume-mode fork                  # back to forking (the shipped default)\n```\n\nThe default is stored as `.resume.mode` in `~/.claude-switch-backup/sequence.json`.\nPrecedence is flag → stored default → `fork`. The same setting drives the message the\nrate-limit hook prints when it auto-switches (below).\n\n> **macOS note:** whether the resumed session authenticates under the new account depends\n> on Claude Code's session model. If it can't, the switch still succeeds and you land in\n> a fresh session. Forking sidesteps this by creating a session the new account owns, so\n> `same` is the mode more likely to hit it.\n\n### Custom endpoints\n\nAdd an Anthropic-compatible endpoint as a switchable account:\n\n```bash\n# API-key (x-api-key) provider, key read from a prompt (not shell history)\nccs add-endpoint openrouter --base-url https://openrouter.ai/api/v1 --token-header api_key\n\n# Bearer-token provider, key piped in\necho \"$MY_TOKEN\" | ccs add-endpoint gateway --base-url https://gw.corp/v1 --token-header auth_token --key-stdin --model claude-3-5-sonnet\n\nccs to openrouter        # switch (writes ANTHROPIC_* into ~/.claude/settings.json env)\nccs to 1                 # switch back to an OAuth account (removes those env vars)\n```\n\nSwitching to/from an endpoint changes Claude Code's `settings.json` `env`, which\nis read at startup — **restart Claude Code** (or use `-r` / `--resume`) for the\nchange to take effect.\n\nEndpoints also participate in rate-limit auto-switch: because they have no usage\nAPI, `ccs` probes the endpoint (`/models`, then `/messages`) and falls back to the\nnext account when it returns auth, rate-limit, server, or timeout errors.\n\n### Profiles\n\n```bash\nccs profile 1 work               # Name account 1 \"work\"\nccs profile 2 personal           # Name account 2 \"personal\"\nccs to work                      # Then switch by profile name\n```\n\n### Directory-based Auto-switching\n\n```bash\nccs dir ~/work 1                 # Map ~/work to account 1\nccs dir ~/personal 2             # Map ~/personal to account 2\nccs auto                         # Switch based on current directory\n```\n\n### Rate Limit Auto-switch\n\nAutomatically switch to the next account when your 5-hour usage exceeds a threshold. Uses Claude Code's [PreToolUse hook](https://docs.anthropic.com/en/docs/claude-code/hooks) system — no polling, no background processes.\n\n```bash\n# Set up (one-time) — installs a PreToolUse hook into ~/.claude/settings.json\nccs rate-setup                   # Enable with default 80% threshold\nccs rate-setup --threshold 70    # Custom threshold\n\n# Manual check\nccs rate-check                   # Check current usage vs threshold\nccs rate-check --auto-switch     # Check and switch if exceeded\nccs rate-check --max-age 30      # Treat the cache as stale after 30s\n\n# Disable\nccs rate-setup --disable         # Remove hook and disable\n```\n\n`rate-setup` looks for the hook script (`hooks/ccs-rate-hook.sh`) next to `ccswitch.sh` — source checkouts and the npm package — and then in `<prefix>/share/ccswitch/`, where `make install` and Homebrew put it. Set `$CCS_SHARE_DIR` to override the location. The same applies to the statusline script below.\n\n**How it works:**\n\n1. The usage cache lives at `$TMPDIR/claude-usage-cache.json` (falling back to `/tmp` when `$TMPDIR`/`$TMP`/`$TEMP` are unset; override with `$CCS_USAGE_CACHE`) with a `cached_at` timestamp.\n2. Before each tool call the PreToolUse hook checks the cache. If it's fresh (younger than the TTL) and under threshold, it returns immediately (~20ms, no API call).\n3. If the cache is missing, stale, or for a different account, the hook refreshes it from the [Anthropic OAuth Usage API](https://api.anthropic.com/api/oauth/usage) on demand — so it works in headless `claude -p` runs with no statusline.\n4. If usage exceeds the threshold, it switches to the next account and tells Claude Code to deny the tool call with a message naming the new account. A `PreToolUse` hook runs inside the live Claude Code process, so it can't relaunch it for you — instead the message hands you the exact command to come back with, honoring your resume mode: `Exit and run: claude --resume <id> --fork-session` (or without `--fork-session` when the mode is `same`). If the directory has no conversation to resume, it falls back to \"Please restart Claude Code.\"\n5. Switches take an exclusive lock, so concurrent agents (e.g. an orchestrator's heartbeats) can't race or thrash accounts.\n6. All errors fail open — a broken hook never blocks your work.\n\n**Cache TTL:** the cache is considered fresh for `DEFAULT_CACHE_TTL` (60s) by default. Override per-install with `.rateLimit.cacheTtl` in `~/.claude-switch-backup/sequence.json`, or per-invocation with `--max-age SECONDS`. A short TTL means fresher data at the cost of more API calls; a longer TTL means fewer calls.\n\n**Optional statusline:** for interactive sessions you can install a statusline that shows the active account and 5-hour usage while keeping the cache warm:\n\n```bash\nccs statusline-setup             # Install (writes .statusLine into ~/.claude/settings.json)\nccs statusline-setup --force     # Same, replacing a statusline you already configured\nccs statusline-setup --disable   # Remove it (leaves any other statusline untouched)\n```\n\nIf `~/.claude/settings.json` already sets a `statusLine` that isn't ours, `statusline-setup` stops and tells you — pass `--force` to replace it, or call `statusline/ccs-statusline.sh` from your own statusline script to render both.\n\nIt renders e.g. `ccs you@example.com · 5h 42%` and appends `(!)` once you cross the threshold. The cache refresh runs in the background, so it never blocks the prompt. The statusline is **not required** — headless runs refresh the cache on demand (above).\n\n> **Note (multi-account at the same time):** `ccswitch` rewrites a single machine-global credential store, so all Claude Code processes on the machine share one account at a time. Auto-switch is built for the *sequential* case — \"when this account is exhausted, rotate to the next.\" Running different accounts in parallel requires per-process isolation via `CLAUDE_CONFIG_DIR` — see below.\n\n### Reactive auto-switch (`ccs run`)\n\nFor headless orchestrators (e.g. Paperclip/Multica) running `claude -p`, the PreToolUse hook described above cannot see a 429 that arrives mid-turn. `ccs run` fills that gap: it runs a command on the active account and, when the command fails because the account is rate-limited, switches to the next healthy account and retries.\n\n```bash\nccs run -- claude -p \"summarize this repo\"\nccs run --max-attempts 3 --timeout 120 -- claude -p \"...\"\n```\n\n**Detection** is format-agnostic: `ccs run` greps the failed run's stderr and the final lines of its stdout for documented rate-limit markers (a `(429)` API error, `rate-limit`/`rate_limit`, `overloaded`, `usage limit`). When those are absent but the command still failed, it falls back to a usage-API check (max of the 5-hour and 7-day windows) to decide whether the account is actually exhausted.\n\n**Flags:**\n\n| Flag | Default | Description |\n|------|---------|-------------|\n| `--max-attempts N` | number of accounts | Maximum total attempts across all accounts |\n| `--limit-threshold N` | 95 | Usage % for the secondary/reactive limit confirmation and post-switch health check |\n| `--timeout SEC` | none | Per-attempt time limit; kills the child's process group. Also bounds the stdin read |\n| `--no-proactive` | — | Skip the pre-run usage check |\n| `--no-stdin` | — | Don't read stdin; feed the child `/dev/null` (see stdin note below) |\n\n**Exit codes:**\n\n| Code | Meaning |\n|------|---------|\n| 0 | Success |\n| command's own code | Non-rate-limit failure (no retry) |\n| 124 | Attempt killed by `--timeout` (or a stdin read that timed out) |\n| 3 | All accounts exhausted; a machine-readable `ccs-run: exhausted accounts=N attempts=M` line is printed to stderr |\n| 4 | `--max-attempts` reached after rotating to a healthy account that wasn't retried; prints `ccs-run: max-attempts accounts=N attempts=M`. Distinct from 3 so an orchestrator doesn't park work while a usable account remains |\n| 2 | Internal switch error |\n\n**stdin** is spooled to a temp file and replayed on each attempt (so a retry sees byte-identical input). Only the successful attempt's stdout is emitted.\n\n> **IMPORTANT — stdin can block:** because the spool is read to EOF up front, a command that never reads stdin but inherits a long-lived/open pipe (common when an orchestrator spawns children with inherited stdin) will make `ccs run` block before the first attempt. If you pass the prompt as an argument (`claude -p \"...\"`), use **`--no-stdin`** (or redirect `</dev/null`). `--timeout` also bounds the stdin read.\n\n> **IMPORTANT — Idempotency:** a rate-limited attempt may have already run tool calls with side effects before the limit was hit. The default retry re-runs the command from the beginning, so side effects can duplicate. Design your commands to be idempotent, or use `--max-attempts 1` (which still rotates once to a healthy account for your *next* invocation, but does not retry in-place).\n\n> **IMPORTANT — Buffered stdout:** only the successful attempt's stdout is emitted. This means `--output-format stream-json` events are not streamed live, which may trip an orchestrator's inactivity timeout.\n\n### Parallel / isolated accounts (`CLAUDE_CONFIG_DIR`)\n\nTo run multiple Claude Code processes as **different** accounts at the same time (e.g. an orchestrator like Paperclip/Multica fanning out agents), give each process its own config directory instead of switching the global store:\n\n```bash\n# Run a command as a specific account, isolated in its own config dir\nccs exec 2 -- claude -p \"summarize this repo\"\nccs exec work -- claude            # by profile name\n\n# Or just materialize the dir and wire the env yourself\neval \"$(ccs config-dir 2 | tail -1)\"   # exports CLAUDE_CONFIG_DIR\n```\n\n`ccs exec` materializes the account's `.claude.json` + credentials into `~/.claude-switch-backup/isolated/<n>-<email>/` (override with `--dir PATH`) and runs the command with `CLAUDE_CONFIG_DIR` pointed there. Because it never touches the global store, several `ccs exec` processes can run as different accounts concurrently with no locking. Put any ccs options before `exec`; everything after `--` is passed to the command verbatim.\n\n> ⚠️ **Platform support:** parallel isolation works on **Linux/WSL** (credentials are file-based, so a copied credential just works). It does **not** work on **macOS** with current Claude Code (2.1.x): Claude binds the OAuth token to the live session, so a *copied* token — whether written as a file or into the per-dir Keychain item — is rejected with `401` in an isolated config dir, even when fresh ([#29](https://github.com/fairy-pitta/cc-account-switcher/issues/29)). The only way to run different accounts in parallel on macOS is to `claude auth login` **inside each** `CLAUDE_CONFIG_DIR` so each owns its own credentials. Note: the **rate-limit auto-switch (sequential rotation) works on macOS** — it swaps the single active account rather than running parallel copies.\n\n### Diagnostics\n\n```bash\nccs check                        # Verify backup integrity (JSON, permissions, keychain)\nccs status                       # Current account, token expiry, last switch\nccs stats                        # Per-account usage statistics\n```\n\n### Other\n\n```bash\nccs version                      # Show version\nccs help                         # Show help\n```\n\n### Running as root\n\nBy default the script refuses to run as `root`, because credentials and backups are\nstored per-user (under `$HOME` and, on macOS, the user's Keychain). Running as root\ntargets a different home/Keychain and can leave root-owned files behind that break\nyour normal user.\n\nIf you understand the risks (e.g. sandbox or container testing), opt out with the\n`--allow-root` flag or the `CCSWITCH_ALLOW_ROOT=1` environment variable:\n\n```bash\nccs --allow-root ls              # Flag (can go before or after the command)\nCCSWITCH_ALLOW_ROOT=1 ccs ls     # Environment variable\n```\n\nContainers are detected automatically and allowed without the flag.\n\n### Shell Integration\n\nAdd to your shell profile to enable completions and the `ccs` alias:\n\n**Bash** (`~/.bashrc`):\n\n```bash\nsource \"$(command -v ccs)\" --shell-init bash 2>/dev/null\n```\n\n**Zsh** (`~/.zshrc`):\n\n```bash\nsource \"$(command -v ccs)\" --shell-init zsh 2>/dev/null\n```\n\n**Fish** (`~/.config/fish/config.fish`):\n\n```fish\nsource \"$(command -v ccs)\" --shell-init fish 2>/dev/null\n```\n\n## Requirements\n\n- Bash 3.2+\n- `jq` (JSON processor)\n\n### Installing Dependencies\n\n**macOS:**\n\n```bash\nbrew install jq\n```\n\n**Ubuntu/Debian:**\n\n```bash\nsudo apt install jq\n```\n\n## How It Works\n\nThe switcher stores account authentication data separately:\n\n- **macOS**: Credentials in Keychain, OAuth info in `~/.claude-switch-backup/`\n- **Linux/WSL**: Both credentials and OAuth info in `~/.claude-switch-backup/` with restricted permissions\n\nWhen switching accounts, it:\n\n1. Backs up the current account's authentication data\n2. Restores the target account's authentication data\n3. Updates Claude Code's authentication files\n4. Automatically rolls back if any step fails\n\n## Troubleshooting\n\nRun `ccs check` first — it verifies JSON validity, file permissions, and keychain entries.\n\n### Common Issues\n\n| Problem | Solution |\n|---------|----------|\n| Switch fails | Run `ccs check` to diagnose. Ensure Claude Code is closed. |\n| Can't add account | Ensure you're logged into Claude Code. Verify `jq` is installed. |\n| Claude Code doesn't recognize new account | Restart Claude Code after switching, or use `ccs sw -r`. |\n| Not sure which account is active | Run `ccs ls` — the active account is marked. |\n\n## Cleanup / Uninstall\n\n1. Note your current active account: `ccs ls`\n2. Remove the backup directory: `rm -rf ~/.claude-switch-backup`\n3. Uninstall:\n   - **make**: `sudo make uninstall`\n   - **npm**: `npm uninstall -g @fairy-pitta/cc-account-switcher`\n   - **manual**: `rm /usr/local/bin/ccs`\n\nYour current Claude Code login will remain active.\n\n## Contributing\n\nContributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## Security\n\n- macOS credentials stored in system Keychain\n- All backup files use `600` permissions (owner-only read/write)\n- Integrity checks via `ccs check`\n\n## Acknowledgments\n\nThis project is a fork of [ming86/cc-account-switcher](https://github.com/ming86/cc-account-switcher). Thanks to the original author for building the foundation of multi-account switching for Claude Code.\n\n## License\n\nMIT License — see [LICENSE](LICENSE) file for details.\n","readmeFilename":"README.md"}