๐ cctx - Claude Context Switcher
โก Fast and intuitive way to switch between Claude Code contexts (
~/.claude/settings.json
)
cctx (Claude Context) is a kubectx-inspired command-line tool for managing multiple Claude Code configurations. Switch between different permission sets, environments, and settings with a single command.
โจ Features
- ๐ Instant context switching - Switch between configurations in milliseconds
- ๐ฏ Predictable UX - Default behavior always uses user-level contexts (no surprises!)
- ๐ก๏ธ Security-first - Separate permissions for work, personal, and project contexts
- ๐จ Beautiful CLI - Colorized output with helpful hints and visual indicators
- ๐ Shell completions - Tab completion for all major shells
- ๐ฆ Zero dependencies - Single binary, works everywhere
- ๐ Previous context - Quick switch back with
cctx -
- ๐ File-based - Simple JSON files you can edit manually
- ๐ญ Kubectx-inspired - Familiar UX for Kubernetes users
- ๐ก Progressive disclosure - Shows project/local contexts when available
๐ Quick Start
๐ฆ Installation
From crates.io (recommended):
From source:
Pre-built binaries: Download from GitHub Releases
โก 30-Second Setup
# 1. Create your first context from current settings
# 2. Create a restricted work context
# 3. Switch between contexts
๐ฏ Usage
๐ Basic Commands
# List all contexts (current highlighted in green)
# Switch to a context
# Switch to previous context
# Show current context
๐๏ธ Settings Level Management
cctx respects Claude Code's settings hierarchy with a simple, predictable approach:
- Enterprise policies (highest priority)
- Command-line arguments
- Local project settings (
./.claude/settings.local.json
) - Shared project settings (
./.claude/settings.json
) - User settings (
~/.claude/settings.json
) (lowest priority)
# Default: always uses user-level contexts (predictable)
# Explicit flags for project/local contexts
# All commands work with any level
๐ ๏ธ Context Management
# Create new context from current settings
# Delete a context
# Rename a context
# Edit context with $EDITOR
# Show context content (JSON)
# Unset current context
๐ฅ๐ค Import/Export
# Export context to file
# Import context from file
# Share contexts between machines
|
๐ Merge Permissions
Merge permissions from other contexts or files to build complex configurations:
# Merge user settings into current context
# Merge from another context
# Merge from a specific file
# Remove previously merged permissions
# View merge history
# Merge into a specific context (default is current)
Merge Features:
- ๐ Smart deduplication - Prevents duplicate permissions
- ๐ History tracking - See what was merged from where
- ๐ Reversible - Unmerge specific sources anytime
- ๐ฏ Granular control - Target specific contexts
๐ฅ๏ธ Shell Completions
Enable tab completion for faster workflow:
# Bash
# Zsh
# Fish
# PowerShell
๐๏ธ File Structure
Contexts are stored as individual JSON files at different levels:
๐ User Level (~/.claude/
):
๐ ~/.claude/
โโโ โ๏ธ settings.json # Active user context
โโโ ๐ settings/
โโโ ๐ผ work.json # Work context
โโโ ๐ personal.json # Personal context
โโโ ๐ .cctx-state.json # State tracking
๐ Project Level (./.claude/
):
๐ ./.claude/
โโโ โ๏ธ settings.json # Shared project context
โโโ ๐ settings.local.json # Local project context (gitignored)
โโโ ๐ settings/
โโโ ๐ staging.json # Staging context
โโโ ๐ญ production.json # Production context
โโโ ๐ .cctx-state.json # Project state
โโโ ๐ .cctx-state.local.json # Local state
๐ญ Interactive Mode
When no arguments are provided, cctx enters interactive mode:
- ๐ fzf integration - Uses fzf if available for fuzzy search
- ๐ฏ Built-in finder - Fallback fuzzy finder when fzf not installed
- ๐ Color coding - Current context highlighted in green
- โจ๏ธ Keyboard navigation - Arrow keys and type-ahead search
# Interactive context selection
๐ผ Common Workflows
๐ข Professional Setup
# Create restricted work context for safer collaboration
# - Read/Edit only in ~/work/** and current directory
# - Deny: docker, kubectl, terraform, ssh, WebFetch, WebSearch
# - Basic dev tools: git, npm, cargo, python only
๐ Project-Based Contexts
# Create project-specific contexts
# Switch based on current work
๐ Daily Context Switching
# Morning: start with work context
# Need full access for personal project
# Quick switch back to work
# Check current context anytime
๐ก๏ธ Security-First Approach
# Default restricted context for screen sharing
# Full permissions only when needed
# Project-specific minimal permissions
# Configure: only access to ~/projects/client/**
๐ฏ Settings Level Workflows
๐ค User-Level Development:
# Personal development with full permissions (default behavior)
# Work context with restrictions (default behavior)
๐ Project-Level Collaboration:
# Shared team settings (committed to git)
# Personal project overrides (gitignored)
๐ Multi-Level Management:
# Check current level (always shows helpful context)
# Switch levels in same directory
๐ง Advanced Usage
๐ Context Creation with Claude
Use Claude Code to help create specialized contexts:
# Create production-safe context
๐จ Custom Context Templates
# Create template contexts for different scenarios
๐ Context Synchronization
# Sync contexts across machines
# Or use git for version control
&& &&
๐ก๏ธ Security Best Practices
๐ Permission Isolation
- ๐ข Work context - Restricted permissions for professional use
- ๐ Personal context - Full permissions for personal projects
- ๐บ Demo context - Ultra-restricted for screen sharing/demos
- ๐งช Testing context - Isolated environment for experiments
๐ฏ Context Strategy
# Create permission hierarchy
๐ Regular Audits
# Review context permissions regularly
# Quick security check
|
๐ฏ Tips & Tricks
โก Productivity Boosters
- ๐ Use
cctx -
frequently - Quick toggle between two contexts - ๐ฏ Trust the defaults -
cctx
(no flags) handles 90% of use cases perfectly - ๐ก Follow the hints - When cctx shows hints, they're contextually relevant
- โจ๏ธ Set up aliases -
alias work='cctx work'
,alias home='cctx personal'
- ๐ Document your contexts - Add comments in JSON for future reference
๐ ๏ธ Environment Setup
# Add to your shell profile (~/.bashrc, ~/.zshrc)
# For cctx -e
# Shorter command
# Show context content
# Show current context
# Git hooks for automatic context switching
# Pre-commit hook to ensure proper context
#!/bin/bash
if ; then
fi
๐ง Integration Examples
# Tmux integration - show context in status bar
# VS Code integration - add to settings.json
# Fish shell prompt integration
๐ง Development & Release Tools
This project includes comprehensive automation tools:
๐ Release Management
Simple One-Command Release:
# Automatic release with all quality checks
The script automatically:
- โ Runs quality checks (fmt, clippy, test, build)
- โ Updates version in Cargo.toml
- โ Creates git commit and tag
- โ Pushes to GitHub
- โ Triggers GitHub Actions for binary builds and crates.io publishing
๐ ๏ธ Development Tasks
# Using justfile (install: cargo install just)
๐ค Contributing
We welcome contributions! This project includes:
- ๐ Automated CI/CD - GitHub Actions for testing and releases
- ๐งช Quality gates - Formatting, linting, and tests required
- ๐ฆ Multi-platform - Builds for Linux, macOS, and Windows
- ๐ Auto-releases - Semantic versioning with automated publishing
๐ Setting up crates.io Publishing (Maintainers)
To enable automatic publishing to crates.io:
-
Get your crates.io API token:
# Or visit https://crates.io/me โ New Token
-
Add to GitHub repository secrets:
Web UI method:
- Go to Settings โ Secrets and variables โ Actions
- Click "New repository secret"
- Name:
CARGO_REGISTRY_TOKEN
- Value: Your crates.io API token
CLI method (using gh):
# Store token securely and add to repository |
See CLAUDE.md for detailed development guidelines.
๐ License
MIT License - see LICENSE file for details.
๐ Complete Command Reference
Basic Operations
cctx
- List contexts (defaults to user-level)cctx <name>
- Switch to contextcctx -
- Switch to previous contextcctx -c
- Show current context namecctx -q
- Quiet mode (only show current context)
Context Management
cctx -n <name>
- Create new context from current settingscctx -d <name>
- Delete context (interactive if no name)cctx -r <old> <new>
- Rename contextcctx -e [name]
- Edit context with $EDITORcctx -s [name]
- Show context content (JSON)cctx -u
- Unset current context (removes settings file)
Import/Export
cctx --export [name]
- Export context to stdoutcctx --import <name>
- Import context from stdin
Merge Operations
cctx --merge-from <source> [target]
- Merge permissions from source into target (default: current)- Source can be:
user
, another context name, or file path
- Source can be:
cctx --merge-from <source> --merge-full [target]
- Merge ALL settings (not just permissions)cctx --unmerge <source> [target]
- Remove previously merged permissionscctx --unmerge <source> --merge-full [target]
- Remove ALL previously merged settingscctx --merge-history [name]
- Show merge history for context
Settings Levels
cctx
- User-level contexts (default:~/.claude/settings.json
)cctx --in-project
- Project-level contexts (./.claude/settings.json
)cctx --local
- Local project contexts (./.claude/settings.local.json
)
Other Options
cctx --completions <shell>
- Generate shell completionscctx --help
- Show help informationcctx --version
- Show version information
๐ฏ Design Philosophy (v0.1.1+)
cctx follows the principle of "Predictable defaults with explicit overrides":
- ๐ฏ Default behavior is always the same - uses user-level contexts (
~/.claude/settings.json
) - ๐ก Helpful discovery - shows hints when project/local contexts are available
- ๐ Simple when simple - 90% of usage needs zero flags
- ๐ง Explicit when needed -
--in-project
and--local
for specific cases
This approach eliminates surprises and cognitive overhead while maintaining full functionality.
โ ๏ธ Compatibility Notice
cctx is designed to work with Claude Code configuration files. As Claude Code is actively developed by Anthropic, configuration formats and file structures may change over time.
We are committed to maintaining compatibility:
- ๐ Active monitoring of Claude Code updates and changes
- ๐ Prompt updates when configuration formats change
- ๐ ๏ธ Backward compatibility whenever possible
- ๐ข Clear migration guides for breaking changes
If you encounter compatibility issues after a Claude Code update, please open an issue and we'll address it promptly.
๐ Acknowledgments
- ๐ฏ Inspired by kubectx - the amazing Kubernetes context switcher
- ๐ค Built for Claude Code - Anthropic's CLI for Claude
- ๐ฆ Powered by Rust - fast, safe, and beautiful
โญ Star this repo if cctx makes your Claude Code workflow better!
๐ Report Bug โข ๐ก Request Feature โข ๐ฌ Discussions