agentleFS
foxj77foxj77/claudectx/CLAUDE.md

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
  1. Distinctive:

    When modifying profile switching:

    line 79
  2. Very specific:

    Backup first: Call backup.NewManager().Create() before switching

    line 80
  3. Very specific:

    Validate: Use validator.ValidateSettings() before applying

    line 81
  4. Distinctive:

    Atomic writes: Write to temp file, then rename

    line 82
  5. Very specific:

    Don't hardcode paths - use internal/paths

    line 88
  6. Very specific:

    Don't print directly to stdout - use internal/printer

    line 89
  7. Distinctive:

    Don't skip validation before profile operations

    line 90
  8. Distinctive:

    Don't modify profiles without creating backups

    line 91
  9. Distinctive:

    Don't add external dependencies without strong justification

    line 92
  10. Very specific:

    Don't add new top-level fields to settings.json by expanding the Settings struct — unknown fields are already preserved by the extras …

    line 93

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Image: OpenSSF Scorecard

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 analysis

Architecture

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

PackagePurpose
internal/storeProfile persistence, tracks current/previous profile
internal/configSettings struct (Env, Model, Permissions), JSON I/O — unknown fields are preserved transparently via extras map[string]json.RawMessage
internal/mcpconfigMCP server configs from ~/.claude.json
internal/pathsCentralized path resolution for Claude files
internal/printerColored terminal output (respects NO_COLOR)
internal/backupTimestamped backups before switching
internal/validatorSettings 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)           // Blue

Store Pattern

s, err := store.NewStore()
if s.Exists(name) { /* ... */ }
prof, err := s.Load(name)
err = s.Save(prof)

Safety Requirements

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

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.json by expanding the Settings struct — unknown fields are already preserved by the extras mechanism, so this is only needed when a field requires programmatic access from Go code

Commands Reference

CommandFile
claudectx (interactive)cmd/list_interactive.go
claudectx <name> (switch)cmd/switch.go
claudectx -n <name>cmd/create.go
claudectx -lcmd/list.go
claudectx -ccmd/current.go
claudectx -d <name>cmd/delete.go
claudectx - (toggle)cmd/toggle.go
claudectx export/importcmd/export.go, cmd/import.go
claudectx healthcmd/health.go
claudectx synccmd/sync.go

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.