https://github.com/grammeaway/claudectx
CLI tool for easily managing and switching between Claude Code accounts in your local environment.
https://github.com/grammeaway/claudectx
claude claude-code cli rust
Last synced: 14 days ago
JSON representation
CLI tool for easily managing and switching between Claude Code accounts in your local environment.
- Host: GitHub
- URL: https://github.com/grammeaway/claudectx
- Owner: grammeaway
- License: gpl-3.0
- Created: 2026-03-26T13:15:54.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-30T11:14:16.000Z (about 2 months ago)
- Last Synced: 2026-04-30T13:12:36.617Z (about 2 months ago)
- Topics: claude, claude-code, cli, rust
- Language: Rust
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# claudectx
Easily switch between multiple Claude Code contexts.
Use an account for work, but another for personal use? No problem. With claudectx, you can quickly switch between different Claude Code contexts, all from the comfort of your terminal.
Inspired by `kubectx`.
```
$ claudectx list
✓ work
personal
client-acme
$ claudectx personal
✓ Switched to context personal (~/.claude.json, ~/.claude/settings.json)
Restart Claude Code for changes to take effect.
```
## Table of Contents
- [Why?](#why)
- [Installation](#installation)
- [Usage](#usage)
- [How it works](#how-it-works)
- [Tips](#tips)
- [Security](#security)
- [AI usage disclaimer](#ai-usage-disclaimer)
## Why?
Claude Code stores your identity, OAuth session, MCP servers, and settings in two files:
| File | Contains |
|------|----------|
| `~/.claude.json` | OAuth session, account, MCP server configs, preferences (theme, editor mode) |
| `~/.claude/settings.json` | Model selection, tool permissions, env vars, hooks |
If you use Claude Code with a work account **and** a personal account (or multiple API keys / subscriptions), swapping between them means manually editing those files each time. `claudectx` automates that.
## Installation
### Install from source (requires Rust / cargo)
Pressuming you have Rust installed, and the repository cloned:
```bash
cd claudectx
cargo install --path .
```
### Build from source (requires Rust / cargo)
Pressuming you have Rust installed, and the repository cloned:
```bash
cd claudectx
cargo build --release
# copy binary somewhere on your PATH
cp target/release/claudectx /usr/local/bin/
```
### Pre-built binary
Download from the releases page and place on your `$PATH`.
## Usage
```
claudectx [CONTEXT] [COMMAND]
```
### Quick switch (kubectx style)
```bash
claudectx work # switch to the "work" context
claudectx personal # switch to the "personal" context
```
### Commands
| Command | Alias | Description |
|---------|-------|-------------|
| `claudectx` | | List all contexts (default when no args) |
| `claudectx list` | `ls` | List all contexts |
| `claudectx save ` | | Snapshot current config as a named context |
| `claudectx use ` | | Restore a saved context (same as bare `claudectx `) |
| `claudectx current` | | Print the active context name |
| `claudectx delete ` | `rm` | Delete a saved context |
| `claudectx rename ` | | Rename a context |
| `claudectx copy ` | | Duplicate a context |
| `claudectx inspect ` | | Show files + top-level JSON keys stored in a context |
| `claudectx version` | | Print the version (also available as `--version`) |
### Typical workflow
```bash
# 1. Log into your work account in Claude Code, configure it how you like
claudectx save work
# 2. Log into your personal account, set it up
claudectx save personal
# 3. From now on, switching is instant
claudectx work
claudectx personal
```
### Shell prompt integration
Show the active context in your prompt (bash/zsh):
```bash
# Add to ~/.bashrc or ~/.zshrc
claudectx_prompt() {
local ctx
ctx=$(claudectx current 2>/dev/null)
[[ -n "$ctx" ]] && echo "(%ctx%)" | sed "s/%ctx%/$ctx/"
}
PS1='$(claudectx_prompt) \$ '
```
## How it works
Contexts are stored in `~/.claudectx/`:
```
~/.claudectx/
├── current ← name of active context
└── contexts/
├── work/
│ ├── claude.json ← snapshot of ~/.claude.json
│ └── settings.json ← snapshot of ~/.claude/settings.json
└── personal/
├── claude.json
└── settings.json
```
When you **save** a context, both files are copied in. When you **use** a context, they are copied back out (the previous live files are backed up as `.bak` first, just in case).
## Tips
- **Partial contexts are fine.** If you only have `~/.claude.json` and no `settings.json`, that's saved and restored correctly.
- **MCP servers per-account.** Since `~/.claude.json` stores user-scoped MCP servers, switching context also switches which MCP servers are active.
- **Backups.** Before overwriting your live files, the previous versions are saved as `~/.claude.json.bak` and `~/.claude/settings.json.bak`.
- **Restart Claude Code** after switching — it reads config at startup.
## Security
Context files are stored unencrypted in `~/.claudectx/`. On macOS, OAuth tokens inside `~/.claude.json` may actually be references to Keychain entries, not raw secrets. On Linux/Windows, they may be stored in plaintext — keep `~/.claudectx/` permissions tight:
```bash
chmod 700 ~/.claudectx
```
Never commit your `~/.claudectx/` directory to version control.
## AI usage disclaimer
This tool was built using Claude Code, and may contain inaccuracies or bugs. Use with caution and verify critical actions manually. Feedback and contributions are welcome to improve the tool!