cctx 0.1.6

Claude Code context manager for switching between multiple settings.json configurations
cctx-0.1.6 is not a library.

๐Ÿ”„ cctx - Claude Context Switcher

โšก Fast and intuitive way to switch between Claude Code contexts (~/.claude/settings.json)

Crates.io CI License: MIT Rust

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):

cargo install cctx

From source:

git clone https://github.com/nwiizo/cctx.git
cd cctx
cargo install --path .

Pre-built binaries: Download from GitHub Releases

โšก 30-Second Setup

# 1. Create your first context from current settings
cctx -n personal

# 2. Create a restricted work context
cctx -n work

# 3. Switch between contexts
cctx work      # Switch to work
cctx personal  # Switch to personal  
cctx -         # Switch back to previous

๐ŸŽฏ Usage

๐Ÿ” Basic Commands

# List all contexts (current highlighted in green)
cctx

# Switch to a context
cctx work

# Switch to previous context  
cctx -

# Show current context
cctx -c

๐Ÿ—๏ธ Settings Level Management

cctx respects Claude Code's settings hierarchy with a simple, predictable approach:

  1. Enterprise policies (highest priority)
  2. Command-line arguments
  3. Local project settings (./.claude/settings.local.json)
  4. Shared project settings (./.claude/settings.json)
  5. User settings (~/.claude/settings.json) (lowest priority)
# Default: always uses user-level contexts (predictable)
cctx                       # Manages ~/.claude/settings.json

# Explicit flags for project/local contexts
cctx --in-project          # Manages ./.claude/settings.json
cctx --local               # Manages ./.claude/settings.local.json

# All commands work with any level
cctx --in-project work     # Switch to 'work' in project contexts
cctx --local staging       # Switch to 'staging' in local contexts

๐Ÿ› ๏ธ Context Management

# Create new context from current settings
cctx -n project-alpha

# Delete a context
cctx -d old-project

# Rename a context
cctx -r old-name new-name

# Edit context with $EDITOR
cctx -e work

# Show context content (JSON)
cctx -s production

# Unset current context
cctx -u

๐Ÿ“ฅ๐Ÿ“ค Import/Export

# Export context to file
cctx --export production > prod-settings.json

# Import context from file
cctx --import staging < staging-settings.json

# Share contexts between machines
cctx --export work | ssh remote-host 'cctx --import work'

๐Ÿ”€ Merge Permissions

Merge permissions from other contexts or files to build complex configurations:

# Merge user settings into current context
cctx --merge-from user

# Merge from another context
cctx --merge-from personal work

# Merge from a specific file
cctx --merge-from /path/to/permissions.json staging

# Remove previously merged permissions
cctx --unmerge user

# View merge history
cctx --merge-history

# Merge into a specific context (default is current)
cctx --merge-from user production

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
cctx --completions bash > ~/.local/share/bash-completion/completions/cctx

# Zsh  
cctx --completions zsh > /usr/local/share/zsh/site-functions/_cctx

# Fish
cctx --completions fish > ~/.config/fish/completions/cctx.fish

# PowerShell
cctx --completions powershell > cctx.ps1

๐Ÿ—๏ธ 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
cctx

๐Ÿ’ผ Common Workflows

๐Ÿข Professional Setup

# Create restricted work context for safer collaboration
cctx -n work
cctx -e work  # Edit to add restrictions:
# - 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
cctx -n client-alpha    # For client work
cctx -n side-project    # For personal projects  
cctx -n experiments     # For trying new things

# Switch based on current work
cctx client-alpha       # Restricted permissions
cctx experiments        # Full permissions for exploration

๐Ÿ”„ Daily Context Switching

# Morning: start with work context
cctx work

# Need full access for personal project  
cctx personal

# Quick switch back to work
cctx -

# Check current context anytime
cctx -c

๐Ÿ›ก๏ธ Security-First Approach

# Default restricted context for screen sharing
cctx work

# Full permissions only when needed
cctx personal

# Project-specific minimal permissions
cctx -n client-project
# Configure: only access to ~/projects/client/** 

๐ŸŽฏ Settings Level Workflows

๐Ÿ‘ค User-Level Development:

# Personal development with full permissions (default behavior)
cctx personal

# Work context with restrictions (default behavior)
cctx work

๐Ÿ“ Project-Level Collaboration:

# Shared team settings (committed to git)
cctx --in-project staging
cctx --in-project production

# Personal project overrides (gitignored)
cctx --local development
cctx --local debug

๐Ÿ”„ Multi-Level Management:

# Check current level (always shows helpful context)
cctx                    # Shows: ๐Ÿ‘ค User contexts + hints for project/local if available

# Switch levels in same directory
cctx personal           # User level (default)
cctx --in-project staging  # Project level  
cctx --local debug      # Local level

๐Ÿ”ง Advanced Usage

๐Ÿ“ Context Creation with Claude

Use Claude Code to help create specialized contexts:

# Create production-safe context
claude --model opus <<'EOF'
Create a production.json context file with these restrictions:
- Read-only access to most files
- No docker/kubectl/terraform access  
- No system file editing
- Limited bash commands for safety
- Based on my current ~/.claude/settings.json but secured
EOF

๐ŸŽจ Custom Context Templates

# Create template contexts for different scenarios
cctx -n template-minimal     # Minimal permissions
cctx -n template-dev         # Development tools only
cctx -n template-ops         # Operations/deployment tools
cctx -n template-restricted  # Screen-sharing safe

๐Ÿ”„ Context Synchronization

# Sync contexts across machines
rsync -av ~/.claude/settings/ remote:~/.claude/settings/

# Or use git for version control
cd ~/.claude/settings
git init && git add . && git commit -m "Initial contexts"
git remote add origin git@github.com:user/claude-contexts.git
git push -u origin main

๐Ÿ›ก๏ธ Security Best Practices

๐Ÿ”’ Permission Isolation

  1. ๐Ÿข Work context - Restricted permissions for professional use
  2. ๐Ÿ  Personal context - Full permissions for personal projects
  3. ๐Ÿ“บ Demo context - Ultra-restricted for screen sharing/demos
  4. ๐Ÿงช Testing context - Isolated environment for experiments

๐ŸŽฏ Context Strategy

# Create permission hierarchy
cctx -n restricted   # No file write, no network, no system access
cctx -n development  # File access to ~/dev/**, basic tools only  
cctx -n full        # All permissions for personal use
cctx -n demo        # Read-only, safe for presentations

๐Ÿ” Regular Audits

# Review context permissions regularly
cctx -s work        # Check work context permissions
cctx -s personal    # Review personal context
cctx -s production  # Audit production context

# Quick security check
cctx -s restricted | grep -i "allow\|deny"

๐ŸŽฏ 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)
export EDITOR=code                    # For cctx -e
alias cx='cctx'                      # Shorter command
alias cxs='cctx -s'                  # Show context content
alias cxc='cctx -c'                  # Show current context

# Git hooks for automatic context switching
# Pre-commit hook to ensure proper context
#!/bin/bash
if [[ $(cctx -c) != "work" ]]; then
  echo "โš ๏ธ  Switching to work context for this repo"
  cctx work
fi

๐Ÿ”ง Integration Examples

# Tmux integration - show context in status bar
set -g status-right "Context: #(cctx -c) | %H:%M"

# VS Code integration - add to settings.json
"terminal.integrated.env.osx": {
  "CLAUDE_CONTEXT": "$(cctx -c 2>/dev/null || echo 'none')"
}

# Fish shell prompt integration
function fish_prompt
    set_color cyan
    echo -n (cctx -c 2>/dev/null || echo 'no-context')
    set_color normal
    echo -n '> '
end

๐Ÿ”ง Development & Release Tools

This project includes comprehensive automation tools:

๐Ÿš€ Release Management

Simple One-Command Release:

# Automatic release with all quality checks
./quick-release.sh patch      # 0.1.0 -> 0.1.1
./quick-release.sh minor      # 0.1.0 -> 0.2.0
./quick-release.sh major      # 0.1.0 -> 1.0.0

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)
just check              # Run all quality checks
just release-patch      # Same as ./quick-release.sh patch
just setup              # Setup development environment
just audit              # Security audit
just completions fish   # Generate shell completions

๐Ÿค 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:

  1. Get your crates.io API token:

    cargo login  # Opens browser to get token
    # Or visit https://crates.io/me โ†’ New Token
    
  2. 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
    echo "YOUR_TOKEN" | gh secret set CARGO_REGISTRY_TOKEN
    

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 context
  • cctx - - Switch to previous context
  • cctx -c - Show current context name
  • cctx -q - Quiet mode (only show current context)

Context Management

  • cctx -n <name> - Create new context from current settings
  • cctx -d <name> - Delete context (interactive if no name)
  • cctx -r <old> <new> - Rename context
  • cctx -e [name] - Edit context with $EDITOR
  • cctx -s [name] - Show context content (JSON)
  • cctx -u - Unset current context (removes settings file)

Import/Export

  • cctx --export [name] - Export context to stdout
  • cctx --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
  • cctx --merge-from <source> --merge-full [target] - Merge ALL settings (not just permissions)
  • cctx --unmerge <source> [target] - Remove previously merged permissions
  • cctx --unmerge <source> --merge-full [target] - Remove ALL previously merged settings
  • cctx --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 completions
  • cctx --help - Show help information
  • cctx --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