Skip to content

About

csm — pin Claude Code accounts per project, like nvm/fvm. Multi-account session manager using CLAUDE_CONFIG_DIR isolation.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

csm — Claude Session Manager

CI License: MIT

Pin a Claude Code account per project, the way nvm and fvm pin runtime versions.

If you use Claude Code with more than one account — personal and work, or one per client — you know the dance: log out, log back in, forget which account you're on, burn the wrong subscription's usage. csm ends it:

csm import personal         # adopt your existing ~/.claude login — no re-login needed
csm login client-acme       # log in additional accounts fresh

cd ~/projects/acme-app
csm use client-acme         # writes .csmrc — this folder is now pinned

claude                      # just works — runs as client-acme, here and in subfolders

Account names are labels you choose — csm never derives them from your email or reads anything inside the account. Pick names you'd be comfortable seeing in a committed .csmrc or your shell prompt (csm rename if you change your mind).

How it works

Claude Code officially supports the CLAUDE_CONFIG_DIR environment variable. csm gives each account its own config directory under ~/.csm/accounts/<name>/, so credentials, settings, and session history are fully isolated per account — each "account" is just a folder Claude Code is pointed at, and switching never touches credentials. The one component that does handle tokens is keepalive, which refreshes them directly against Anthropic's own OAuth endpoint and nowhere else (see SECURITY.md for the exact boundaries).

A tiny shell wrapper resolves which account applies whenever you run claude:

  1. $CSM_ACCOUNT environment variable, if set
  2. the nearest .csmrc file, walking up from the current directory (like .nvmrc)
  3. the global default (csm global <name>)

Install

Homebrew (macOS/Linux):

brew install imadrashid/tap/csm

Or the install script:

curl -fsSL https://raw.githubusercontent.com/ImadRashid/claude-session-manager/main/install.sh | bash

Or from a checkout: ./install.sh. Pin a release with CSM_INSTALL_REF=v0.1.0. Then enable the shell integration — add to ~/.zshrc or ~/.bashrc:

eval "$(csm shell)"

Verify with csm doctor. Update later with csm upgrade.

Platform status:

  • macOS — tested and used daily (bash and zsh; works on the stock bash 3.2). No dependencies beyond curl.
  • Linux — in progress: the full test suite passes in CI on Ubuntu, but it hasn't been field-tested on a real setup yet. Testing reports and fixes are very welcome — open an issue with what worked or broke.
  • Windows — untested. WSL should behave like Linux; native Windows (Git Bash, etc.) has no support yet. If you're on Windows and want this, contributions are welcome.

Commands

Command What it does
csm login <name> Add an account — opens Claude Code so you can /login, then exit
csm import <name> [<dir>] Adopt an existing login (default ~/.claude) as an account — no re-login; copies it, original untouched, then verifies it works
csm logout <name> Remove an account and its credentials/history (asks first; -f to skip)
csm rename <old> <new> Rename an account — stays logged in (update any .csmrc pins yourself)
csm ls List accounts, marking the one active in the current directory
csm use <name> Pin the current project to an account (writes .csmrc)
csm unuse Remove the current directory's pin
csm global [<name>] Show or set the global default account
csm current Show which account applies here, and why
csm exec <name> [args] One-off: run Claude Code with a specific account
csm env Print an export CLAUDE_CONFIG_DIR=... line (use with eval)
csm which [<name>] Print an account's config directory
csm keepalive Refresh every account's login token; report accounts that need re-login
csm doctor Check the installation
csm upgrade Self-update from GitHub

.csmrc

A plain-text file containing an account name, dropped in a project root by csm use. It applies to that directory and everything below it. Commit it if your teammates should use the same account name; gitignore it if the account name itself is sensitive (e.g. a client's name).

Keepalive (optional but recommended)

Claude Code's OAuth tokens are short-lived, and idle accounts can miss their refresh window — forcing a full re-login and killing any long-running session. csm keepalive checks every account and, when a token is within 30 minutes of expiry, refreshes it directly via Anthropic's OAuth token endpoint (the same refresh-token grant Claude Code performs internally), cooperating with Claude Code's own credential lock so it never races a running session. It consumes no usage and reports precisely: token fresh, token refreshed, endpoint unreachable (retry later), or refresh token rejected (that account genuinely needs /login). Accounts without file credentials fall back to a tiny claude --print "ok" ping.

It fires automatically from the shell integration (at most once per 24h, in the background, piggybacking on real usage). For coverage on days you don't touch a terminal, add a scheduled run:

macOS (launchd — catches up after sleep, unlike cron**):**

cp extras/com.csm.keepalive.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.csm.keepalive.plist

Linux (systemd user timer — Persistent=true catches up after downtime; untested on real hardware, feedback welcome**):**

mkdir -p ~/.config/systemd/user
cp extras/systemd/csm-keepalive.{service,timer} ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now csm-keepalive.timer

Known gap: if the machine is fully off for an extended period, nothing local can run — an always-on host (VPS/Pi) is the only fix, and isn't built yet.

Uninstall

rm "$(command -v csm)"                                  # the binary
# remove the `eval "$(csm shell)"` line from ~/.zshrc / ~/.bashrc
rm -rf ~/.csm                                           # ⚠️ deletes all account logins
# macOS, if you installed the launchd agent:
launchctl unload ~/Library/LaunchAgents/com.csm.keepalive.plist
rm ~/Library/LaunchAgents/com.csm.keepalive.plist
# Linux, if you installed the systemd timer:
systemctl --user disable --now csm-keepalive.timer
rm ~/.config/systemd/user/csm-keepalive.{service,timer}

Your original ~/.claude login is untouched by any of this — plain claude keeps working exactly as before csm.

Notes

  • Terminal only for now. The Claude Code VS Code/JetBrains extensions don't inherit shell functions. Workaround: set CLAUDE_CONFIG_DIR in the workspace (e.g. .vscode/settings.json → terminal.integrated.env.osx), pointing at $(csm which <name>).
  • csm never touches ~/.claude — your existing default login keeps working for directories with no pin and no global default.
  • Storage location is overridable via $CSM_DIR (default ~/.csm).

Contributing

PRs welcome — see CONTRIBUTING.md. Run the dependency-free test suite with bash test/run-tests.sh.

Disclaimer

csm is an independent community tool. It is not affiliated with, endorsed by, or supported by Anthropic. "Claude" and "Claude Code" are trademarks of Anthropic, PBC.

License

MIT

About

csm — pin Claude Code accounts per project, like nvm/fvm. Multi-account session manager using CLAUDE_CONFIG_DIR isolation.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages