claudectx
CLAUDE.md142 starsChanged 2 months agoMITView on GitHub
[](https://securityscorecards.dev/viewer/?uri=github.com/foxj77/claudectx) claudectx is a Go CLI tool for fast, safe profile switching in Claude Code. It manages configuration profiles stored in ~/.claude/profiles/, enabling switching between different settings, CLAUDE.md files, and MCP servers. When modifying profile switching: 1. Backup first: Call backup.NewManager().Create() before switching 2. Validate: Use validator.ValidateSettings() before applying 3. Atomic writes: Write to temp file, then rename 4. Auto-sync: Save changes to current profile before switching 5. Rollback: Restore from backup if switch fails
The file
We split this CLAUDE.md into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 79
When modifying profile switching:
- Very specific: line 80
Backup first: Call backup.NewManager().Create() before switching
- Very specific: line 81
Validate: Use validator.ValidateSettings() before applying
- Distinctive: line 82
Atomic writes: Write to temp file, then rename
- Very specific: line 88
Don't hardcode paths - use internal/paths
- Very specific: line 89
Don't print directly to stdout - use internal/printer
- Distinctive: line 90
Don't skip validation before profile operations
- Distinctive: line 91
Don't modify profiles without creating backups
- Distinctive: line 92
Don't add external dependencies without strong justification
- Very specific: line 93
Don't add new top-level fields to settings.json by expanding the Settings struct — unknown fields are already preserved by the extras …
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
claudectx is a Go CLI tool for fast, safe profile switching in Claude Code. It manages configuration profiles stored in ~/.claude/profiles/, enabling switching between different settings, CLAUDE.md files, and MCP servers.
Build & Test Commands
make build # Build binary (outputs ./claudectx)
make install-user # Install to ~/go/bin (recommended, no sudo)
make test # Run all unit tests
make test-coverage # Run tests with coverage
go test ./... -v # Verbose test output
go vet ./... # Static analysisArchitecture
Core Data Flow
main.go (CLI argument routing)
→ cmd/*.go (command implementations)
→ internal/store (profile CRUD)
→ internal/config, internal/mcpconfig, internal/profile (data structures)
→ ~/.claude/ (filesystem)Key Packages
| Package | Purpose |
internal/store | Profile persistence, tracks current/previous profile |
internal/config | Settings struct (Env, Model, Permissions), JSON I/O — unknown fields are preserved transparently via extras map[string]json.RawMessage |
internal/mcpconfig | MCP server configs from ~/.claude.json |
internal/paths | Centralized path resolution for Claude files |
internal/printer | Colored terminal output (respects NO_COLOR) |
internal/backup | Timestamped backups before switching |
internal/validator | Settings and CLAUDE.md validation |
Key Paths
~/.claude/settings.json- Active settings~/.claude/CLAUDE.md- Global instructions~/.claude.json- MCP server configurations~/.claude/profiles/<name>/- Stored profiles~/.claude/.claudectx-current- Current profile tracker
Coding Conventions
Error Handling
if err != nil {
return fmt.Errorf("failed to load profile: %w", err)
}User Output
printer.Success("Created profile %q", name) // Green
printer.Warning("Warning: %v", err) // Yellow
printer.Error("Error: %v", err) // Red, stderr
printer.Info(" Model: %s", model) // BlueStore Pattern
s, err := store.NewStore()
if s.Exists(name) { /* ... */ }
prof, err := s.Load(name)
err = s.Save(prof)Safety Requirements
When modifying profile switching:
- Backup first: Call
backup.NewManager().Create()before switching - Validate: Use
validator.ValidateSettings()before applying - Atomic writes: Write to temp file, then rename
- Auto-sync: Save changes to current profile before switching
- Rollback: Restore from backup if switch fails
Don'ts
- Don't hardcode paths - use
internal/paths - Don't print directly to stdout - use
internal/printer - Don't skip validation before profile operations
- Don't modify profiles without creating backups
- Don't add external dependencies without strong justification
- Don't add new top-level fields to
settings.jsonby expanding theSettingsstruct — unknown fields are already preserved by theextrasmechanism, so this is only needed when a field requires programmatic access from Go code
Commands Reference
| Command | File |
claudectx (interactive) | cmd/list_interactive.go |
claudectx <name> (switch) | cmd/switch.go |
claudectx -n <name> | cmd/create.go |
claudectx -l | cmd/list.go |
claudectx -c | cmd/current.go |
claudectx -d <name> | cmd/delete.go |
claudectx - (toggle) | cmd/toggle.go |
claudectx export/import | cmd/export.go, cmd/import.go |
claudectx health | cmd/health.go |
claudectx sync | cmd/sync.go |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

