Skip to content

Feature Request: Support CLAUDE_SQUAD_HOME environment variable for custom config directory #245

@zimathon

Description

@zimathon

Problem

Currently, claude-squad stores all configuration and state in a hardcoded path ~/.claude-squad. This causes issues when working with multiple git repositories:

  1. Session mixing: All sessions from different repositories are displayed together, making it difficult to manage when working across multiple projects
  2. State corruption risk: If claude-squad crashes or terminates abnormally, the single state.json can become corrupted, affecting all repositories
  3. No isolation: There's no way to have separate configurations per repository or project

Proposed Solution

Add support for a CLAUDE_SQUAD_HOME environment variable that allows users to customize the configuration directory location.

Implementation

Modify config/config.go's GetConfigDir() function to check for the environment variable first:

func GetConfigDir() (string, error) {
    // Check for environment variable override
    if envDir := os.Getenv("CLAUDE_SQUAD_HOME"); envDir != "" {
        // Expand ~ if present
        if strings.HasPrefix(envDir, "~") {
            homeDir, err := os.UserHomeDir()
            if err != nil {
                return "", fmt.Errorf("failed to expand home directory: %w", err)
            }
            envDir = filepath.Join(homeDir, envDir[1:])
        }
        return envDir, nil
    }
    
    // Default behavior
    homeDir, err := os.UserHomeDir()
    if err != nil {
        return "", fmt.Errorf("failed to get config home directory: %w", err)
    }
    return filepath.Join(homeDir, ".claude-squad"), nil
}

Use Cases

1. Per-repository isolation via wrapper script:

#!/bin/bash
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
if [[ -z "$REPO_ROOT" ]]; then
    echo "Error: Not in a git repository"
    exit 1
fi
REPO_NAME=$(basename "$REPO_ROOT")
export CLAUDE_SQUAD_HOME="$HOME/.claude-squad/repos/$REPO_NAME"
exec claude-squad "$@"

2. Project-specific configurations:

# In .envrc or project setup script
export CLAUDE_SQUAD_HOME="$PWD/.claude-squad"

3. Testing/development:

CLAUDE_SQUAD_HOME=/tmp/cs-test claude-squad

Benefits

  • Backwards compatible: Default behavior unchanged when env var is not set
  • Simple implementation: Minimal code change required
  • Flexible: Users can implement their own isolation strategies
  • Reduces state corruption impact: Issues in one config dir don't affect others

Related Issues

Environment

  • claude-squad version: 1.0.14
  • OS: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions