Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(claude): honor CLAUDE_CONFIG_DIR for settings, hooks, sessions and inventory (#876)

Rudy Mizrahi Celeklicdabadb70549
diff --git a/cli/beacon/cmd/endpoint_claude.go b/cli/beacon/cmd/endpoint_claude.go
index 0c858796..5af16010 100644
--- a/cli/beacon/cmd/endpoint_claude.go
+++ b/cli/beacon/cmd/endpoint_claude.go
@@ -20,7 +20,7 @@ var endpointClaudeCmd = &cobra.Command{
Long: `Collect endpoint telemetry from Claude Code's local session transcripts.
Beacon's normal Claude Code integration uses hooks and OpenTelemetry for live capture.
-This command reads Claude's committed JSONL session files under ~/.claude/projects so
+This command reads Claude's committed JSONL session files under $CLAUDE_CONFIG_DIR/projects (default ~/.claude/projects) so
historical sessions and sessions that ran without Beacon hooks can still be represented
in the local endpoint log. Every emitted event is marked harness.collection_method=poll:
Beacon sees what Claude already wrote, so nothing here can hold or deny a tool call.`,
@@ -65,7 +65,7 @@ func init() {
for _, c := range []*cobra.Command{endpointClaudeSyncCmd, endpointClaudeStatusCmd} {
f := c.Flags()
- f.StringVar(&endpointClaudeOpts.projectsDir, "projects-dir", "", "Claude projects directory (default ~/.claude/projects)")
+ f.StringVar(&endpointClaudeOpts.projectsDir, "projects-dir", "", "Claude projects directory (default $CLAUDE_CONFIG_DIR/projects, else ~/.claude/projects)")
f.StringVar(&endpointClaudeOpts.statePath, "state", "", "Collector cursor file (default ~/.beacon/endpoint/state/claude.json)")
f.BoolVar(&endpointOpts.jsonOutput, "json", false, "Print the result as JSON")
f.BoolVar(&endpointOpts.userMode, "user", true, "Use per-user endpoint paths")
diff --git a/cli/beacon/cmd/handoff.go b/cli/beacon/cmd/handoff.go
index 5440c7d9..10cc72b5 100644
--- a/cli/beacon/cmd/handoff.go
+++ b/cli/beacon/cmd/handoff.go
@@ -356,7 +356,7 @@ func addHandoffStoreFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVar(&handoffOpts.harness, "harness", "", "Only this runtime: "+strings.Join(handoff.RuntimeNames(), ", "))
f.StringArrayVar(&handoffOpts.storeDirs, "store-dir", nil, "Read a runtime's sessions from this directory, as <runtime>=<path> (repeatable)")
- f.StringVar(&handoffOpts.claudeDir, "claude-projects-dir", "", "Claude projects directory (default ~/.claude/projects)")
+ f.StringVar(&handoffOpts.claudeDir, "claude-projects-dir", "", "Claude projects directory (default $CLAUDE_CONFIG_DIR/projects, else ~/.claude/projects)")
f.StringVar(&handoffOpts.codexDir, "codex-dir", "", "Codex directory (default ~/.codex)")
f.StringVar(&handoffOpts.openCodeDir, "opencode-dir", "", "OpenCode data directory or opencode.db path")
f.StringVar(&handoffOpts.clineDir, "cline-dir", "", "Cline directory (default ~/.cline)")
diff --git a/cli/beacon/internal/agentskills/agentskills.go b/cli/beacon/internal/agentskills/agentskills.go
index a048f63b..8381ab54 100644
--- a/cli/beacon/internal/agentskills/agentskills.go
+++ b/cli/beacon/internal/agentskills/agentskills.go
@@ -19,6 +19,8 @@ import (
"path/filepath"
"sort"
"strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
)
//go:embed skills
@@ -64,15 +66,12 @@ func Names() []string {
// Roots are the user-level skill directories Beacon installs into: ~/.agents/skills, the
// cross-runtime location (Codex CLI, Gemini CLI, OpenCode, Pi and others read it), and Claude
-// Code's own ~/.claude/skills when Claude Code is set up on this machine. Claude Code does not
-// read ~/.agents/skills.
+// Code's own skills directory (under CLAUDE_CONFIG_DIR, or ~/.claude) when Claude Code is set up on
+// this machine. Claude Code does not read ~/.agents/skills.
func Roots(home string) []string {
roots := []string{filepath.Join(home, ".agents", "skills")}
- claudeDir := strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR"))
- if claudeDir == "" {
- claudeDir = filepath.Join(home, ".claude")
- }
- if info, err := os.Stat(claudeDir); err == nil && info.IsDir() {
+ claudeDir := claudesession.ConfigDir(home)
+ if info, err := os.Stat(claudeDir); claudeDir != "" && err == nil && info.IsDir() {
roots = append(roots, filepath.Join(claudeDir, "skills"))
}
return roots
diff --git a/cli/beacon/internal/claudesession/claudesession_test.go b/cli/beacon/internal/claudesession/claudesession_test.go
index 929fa83d..132d04c4 100644
--- a/cli/beacon/internal/claudesession/claudesession_test.go
+++ b/cli/beacon/internal/claudesession/claudesession_test.go
@@ -326,3 +326,53 @@ func TestListUsesRecordedWorkspaceWhenIndexDoesNotNameIt(t *testing.T) {
})
}
}
+
+func TestDefaultProjectsDirFollowsClaudeConfigDir(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+
+ t.Setenv("CLAUDE_CONFIG_DIR", "")
+ got, err := DefaultProjectsDir()
+ if err != nil {
+ t.Fatalf("DefaultProjectsDir: %v", err)
+ }
+ if want := filepath.Join(home, ".claude", "projects"); got != want {
+ t.Fatalf("default projects dir = %q, want %q", got, want)
+ }
+
+ config := filepath.Join(t.TempDir(), "claude-alt")
+ t.Setenv("CLAUDE_CONFIG_DIR", config)
+ got, err = DefaultProjectsDir()
+ if err != nil {
+ t.Fatalf("DefaultProjectsDir with CLAUDE_CONFIG_DIR: %v", err)
+ }
+ if want := filepath.Join(config, "projects"); got != want {
+ t.Fatalf("projects dir with CLAUDE_CONFIG_DIR = %q, want %q", got, want)
+ }
+
+ // An explicit directory still wins over the environment.
+ explicit := t.TempDir()
+ store, err := NewStore(explicit)
+ if err != nil {
+ t.Fatalf("NewStore: %v", err)
+ }
+ if store.ProjectsDir != explicit {
+ t.Fatalf("explicit dir = %q, want %q", store.ProjectsDir, explicit)
+ }
+
+ // With no explicit directory the store reads sessions from the relocated config directory.
+ project := filepath.Join(config, "projects", "-tmp-repo")
+ writeFile(t, filepath.Join(project, "sess-1.jsonl"), userLine("sess-1", "u1", "ship it")+"\n")
+ store, err = NewStore("")
+ if err != nil {
+ t.Fatalf("NewStore: %v", err)
+ }
+ refs, err := store.List()
+ if err != nil {
+ t.Fatalf("List: %v", err)
+ }
+ if len(refs) != 1 || refs[0].ID != "sess-1" {
+ t.Fatalf("List under CLAUDE_CONFIG_DIR = %+v, want sess-1", refs)
+ }
+}
diff --git a/cli/beacon/internal/claudesession/store.go b/cli/beacon/internal/claudesession/store.go
index 131de87a..7f34843e 100644
--- a/cli/beacon/internal/claudesession/store.go
+++ b/cli/beacon/internal/claudesession/store.go
@@ -47,7 +47,40 @@ type Stats struct {
FirstError error
}
+// ConfigDir is Claude Code's config directory: a trimmed, non-empty CLAUDE_CONFIG_DIR, as Claude
+// Code resolves it, otherwise <home>/.claude. settings.json, skills and projects live under it.
+// It is empty when CLAUDE_CONFIG_DIR is unset and home is empty, rather than a relative ".claude"
+// that would name a project's directory.
+func ConfigDir(home string) string {
+ if dir := strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR")); dir != "" {
+ return dir
+ }
+ if strings.TrimSpace(home) == "" {
+ return ""
+ }
+ return filepath.Join(home, ".claude")
+}
+
+// StateFile is Claude Code's user state file, the one `claude mcp add --scope user` writes:
+// <home>/.claude.json, or .claude.json inside CLAUDE_CONFIG_DIR when that is set. Unlike the
+// config directory's other files it sits beside .claude, not in it, by default. Empty under the
+// same condition as ConfigDir.
+func StateFile(home string) string {
+ if dir := strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR")); dir != "" {
+ return filepath.Join(dir, ".claude.json")
+ }
+ if strings.TrimSpace(home) == "" {
+ return ""
+ }
+ return filepath.Join(home, ".claude.json")
+}
+
+// DefaultProjectsDir is where Claude Code keeps session transcripts: <config dir>/projects.
func DefaultProjectsDir() (string, error) {
+ if strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR")) != "" {
+ // No home directory is needed when the config directory is named outright.
+ return filepath.Join(ConfigDir(""), "projects"), nil
+ }
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolve home directory: %w", err)
@@ -55,7 +88,7 @@ func DefaultProjectsDir() (string, error) {
if strings.TrimSpace(home) == "" {
return "", errors.New("home directory is empty")
}
- return filepath.Join(home, ".claude", "projects"), nil
+ return filepath.Join(ConfigDir(home), "projects"), nil
}
func NewStore(dir string) (*Store, error) {
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.go
index 0478d854..6c985f01 100644
--- a/cli/beacon/internal/endpoint/harness/harness.go
+++ b/cli/beacon/internal/endpoint/harness/harness.go
@@ -11,6 +11,7 @@ import (
"strings"
"time"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/integrations/cowork"
@@ -114,14 +115,18 @@ func DiscoverClaude() Harness {
h := Harness{Name: "claude_code", DisplayName: "Claude Code", Capability: "otel_env"}
detectExecutable(&h, "claude")
home, _ := os.UserHomeDir()
- userConfig := filepath.Join(home, ".claude", "settings.json")
+ configDir := claudesession.ConfigDir(home)
+ userConfig := ""
+ if configDir != "" {
+ userConfig = filepath.Join(configDir, "settings.json")
+ }
managedConfig := "/Library/Application Support/ClaudeCode/managed-settings.json"
if fileExists(managedConfig) {
h.ConfigPath = managedConfig
status, msg := claudeStatus(managedConfig)
h.TelemetryStatus = status
h.Message = msg
- } else if fileExists(userConfig) {
+ } else if userConfig != "" && fileExists(userConfig) {
h.ConfigPath = userConfig
status, msg := claudeStatus(userConfig)
h.TelemetryStatus = status
@@ -131,7 +136,7 @@ func DiscoverClaude() Harness {
h.TelemetryStatus = TelemetryMissing
h.Message = "Claude settings file was not found"
}
- if !h.Detected && dirExists(filepath.Join(home, ".claude")) {
+ if !h.Detected && configDir != "" && dirExists(configDir) {
h.Detected = true
}
return h
@@ -373,7 +378,7 @@ func ConfigureClaude(opts ConfigureOptions) (string, error) {
if err != nil {
return "", err
}
- path := filepath.Join(home, ".claude", "settings.json")
+ path := filepath.Join(claudesession.ConfigDir(home), "settings.json")
settings := map[string]interface{}{}
if data, err := os.ReadFile(path); err == nil {
_ = json.Unmarshal(data, &settings)
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index ea89ead0..7a780775 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -1126,3 +1126,29 @@ func TestGeminiSettingsHonorGeminiCLIHome(t *testing.T) {
t.Fatalf("DiscoverGemini config path = %q, want %q", got, want)
}
}
+
+func TestClaudeConfigFollowsClaudeConfigDir(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ config := filepath.Join(t.TempDir(), "claude-alt")
+ t.Setenv("CLAUDE_CONFIG_DIR", config)
+
+ written, err := ConfigureClaude(ConfigureOptions{Endpoint: "http://127.0.0.1:4317", UserMode: true})
+ if err != nil {
+ t.Fatalf("ConfigureClaude returned error: %v", err)
+ }
+ if want := filepath.Join(config, "settings.json"); written != want {
+ t.Fatalf("ConfigureClaude path = %q, want %q", written, want)
+ }
+ if _, err := os.Stat(filepath.Join(home, ".claude", "settings.json")); !os.IsNotExist(err) {
+ t.Fatalf("~/.claude/settings.json must be left alone, stat err = %v", err)
+ }
+
+ h := DiscoverClaude()
+ if want := filepath.Join(config, "settings.json"); h.ConfigPath != want {
+ t.Fatalf("DiscoverClaude config path = %q, want %q", h.ConfigPath, want)
+ }
+ if h.TelemetryStatus != TelemetryEnabled {
+ t.Fatalf("DiscoverClaude status = %q (%s), want enabled", h.TelemetryStatus, h.Message)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/harness/main_test.go b/cli/beacon/internal/endpoint/harness/main_test.go
new file mode 100644
index 00000000..b12228b6
--- /dev/null
+++ b/cli/beacon/internal/endpoint/harness/main_test.go
@@ -0,0 +1,13 @@
+package harness
+
+import (
+ "os"
+ "testing"
+)
+
+// TestMain clears CLAUDE_CONFIG_DIR, which a developer's shell may set. Claude Code's settings
+// path follows it, and the tests here assume ~/.claude unless they set it themselves.
+func TestMain(m *testing.M) {
+ _ = os.Unsetenv("CLAUDE_CONFIG_DIR")
+ os.Exit(m.Run())
+}
diff --git a/cli/beacon/internal/endpoint/hooks/claude.go b/cli/beacon/internal/endpoint/hooks/claude.go
index b338dffe..d6f77fe8 100644
--- a/cli/beacon/internal/endpoint/hooks/claude.go
+++ b/cli/beacon/internal/endpoint/hooks/claude.go
@@ -4,6 +4,8 @@ import (
"fmt"
"os"
"path/filepath"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
)
type ClaudeOptions struct {
@@ -133,7 +135,11 @@ func claudeSettingsPath(level Level) (string, error) {
if err != nil {
return "", err
}
- return filepath.Join(home, ".claude", "settings.json"), nil
+ dir := claudesession.ConfigDir(home)
+ if dir == "" {
+ return "", fmt.Errorf("home directory is empty")
+ }
+ return filepath.Join(dir, "settings.json"), nil
case LevelProject:
cwd, err := os.Getwd()
if err != nil {
diff --git a/cli/beacon/internal/endpoint/hooks/claude_test.go b/cli/beacon/internal/endpoint/hooks/claude_test.go
index 31264fdf..e8f78308 100644
--- a/cli/beacon/internal/endpoint/hooks/claude_test.go
+++ b/cli/beacon/internal/endpoint/hooks/claude_test.go
@@ -147,3 +147,37 @@ func TestClaudeHookStatusDetectsInstalled(t *testing.T) {
t.Fatalf("SettingsPath = %q, want %q", status.SettingsPath, path)
}
}
+
+func TestClaudeSettingsPathUserLevelFollowsClaudeConfigDir(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+
+ t.Setenv("CLAUDE_CONFIG_DIR", "")
+ got, err := claudeSettingsPath(LevelUser)
+ if err != nil {
+ t.Fatalf("claudeSettingsPath returned error: %v", err)
+ }
+ if want := filepath.Join(home, ".claude", "settings.json"); got != want {
+ t.Fatalf("default user settings path = %q, want %q", got, want)
+ }
+
+ config := filepath.Join(t.TempDir(), "claude-alt")
+ t.Setenv("CLAUDE_CONFIG_DIR", config)
+ got, err = claudeSettingsPath(LevelUser)
+ if err != nil {
+ t.Fatalf("claudeSettingsPath returned error: %v", err)
+ }
+ if want := filepath.Join(config, "settings.json"); got != want {
+ t.Fatalf("user settings path with CLAUDE_CONFIG_DIR = %q, want %q", got, want)
+ }
+
+ cwd := t.TempDir()
+ t.Chdir(cwd)
+ got, err = claudeSettingsPath(LevelProject)
+ if err != nil {
+ t.Fatalf("claudeSettingsPath returned error: %v", err)
+ }
+ if want := filepath.Join(cwd, ".claude", "settings.json"); got != want {
+ t.Fatalf("project settings path = %q, want %q (CLAUDE_CONFIG_DIR must not move it)", got, want)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/hooks/main_test.go b/cli/beacon/internal/endpoint/hooks/main_test.go
new file mode 100644
index 00000000..9e38469f
--- /dev/null
+++ b/cli/beacon/internal/endpoint/hooks/main_test.go
@@ -0,0 +1,13 @@
+package hooks
+
+import (
+ "os"
+ "testing"
+)
+
+// TestMain clears CLAUDE_CONFIG_DIR, which a developer's shell may set. Claude Code's user-level
+// settings path follows it, and the tests here assume ~/.claude unless they set it themselves.
+func TestMain(m *testing.M) {
+ _ = os.Unsetenv("CLAUDE_CONFIG_DIR")
+ os.Exit(m.Run())
+}
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.go
index 9174363a..23e44317 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory.go
@@ -15,6 +15,7 @@ import (
"github.com/pelletier/go-toml/v2"
"gopkg.in/yaml.v3"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/clinesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/harness"
@@ -266,13 +267,20 @@ func candidates(home, wd string) []candidate {
return out
}
+// claudeCandidates resolves the user-scope files through CLAUDE_CONFIG_DIR, as Claude Code does.
+// Project and managed scope are unaffected.
func claudeCandidates(home, wd string) []candidate {
- return []candidate{
- {runtime: "claude_code", path: filepath.Join(home, ".claude.json"), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig, volatile: true},
- {runtime: "claude_code", path: filepath.Join(home, ".claude", "settings.json"), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig},
- {runtime: "claude_code", path: filepath.Join(wd, ".claude", "settings.json"), scope: ScopeProject, format: formatJSON, kind: KindNativeConfig},
- {runtime: "claude_code", path: "/Library/Application Support/ClaudeCode/managed-settings.json", scope: ScopeManaged, format: formatJSON, kind: KindManagedConfig},
+ items := []candidate{}
+ if state := claudesession.StateFile(home); state != "" {
+ items = append(items, candidate{runtime: "claude_code", path: state, scope: ScopeUser, format: formatJSON, kind: KindNativeConfig, volatile: true})
+ }
+ if dir := claudesession.ConfigDir(home); dir != "" {
+ items = append(items, candidate{runtime: "claude_code", path: filepath.Join(dir, "settings.json"), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig})
}
+ return append(items,
+ candidate{runtime: "claude_code", path: filepath.Join(wd, ".claude", "settings.json"), scope: ScopeProject, format: formatJSON, kind: KindNativeConfig},
+ candidate{runtime: "claude_code", path: "/Library/Application Support/ClaudeCode/managed-settings.json", scope: ScopeManaged, format: formatJSON, kind: KindManagedConfig},
+ )
}
// codexCandidates resolves the user-scope files through CODEX_HOME, as Codex does, and leaves them
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index f1de0864..22e5c23b 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -404,6 +404,40 @@ func TestScanReadsGeminiSettingsFromGeminiCLIHome(t *testing.T) {
}
}
+// With CLAUDE_CONFIG_DIR set, the Claude Code files inventory reads are the ones Claude Code reads:
+// settings.json, .claude.json and skills all move with it.
+func TestScanReadsClaudeUserFilesFromClaudeConfigDir(t *testing.T) {
+ home := t.TempDir()
+ configDir := t.TempDir()
+ t.Setenv("CLAUDE_CONFIG_DIR", configDir)
+ writeFile(t, filepath.Join(configDir, "settings.json"), `{"mcpServers":{"github":{"command":"gh"}}}`)
+ writeFile(t, filepath.Join(configDir, ".claude.json"), `{"mcpServers":{"memory":{"command":"npx"}}}`)
+ writeFile(t, filepath.Join(configDir, "skills", "demo", "SKILL.md"), "---\nname: demo\ndescription: demo skill\n---\n")
+ writeFile(t, filepath.Join(home, ".claude", "settings.json"), `{"mcpServers":{"stale":{"command":"old"}}}`)
+ writeFile(t, filepath.Join(home, ".claude.json"), `{"mcpServers":{"stale":{"command":"old"}}}`)
+
+ result := Scan(Options{HomeDir: home, SkipProjectScope: true, Runtimes: []string{"claude_code"}, Now: fixedNow})
+ for _, path := range []string{filepath.Join(configDir, "settings.json"), filepath.Join(configDir, ".claude.json")} {
+ if config := findConfig(result.Configs, "claude_code", path); config == nil || !config.Exists || config.MCPServerCount != 1 {
+ t.Fatalf("%s = %#v, want it read with one MCP server", path, config)
+ }
+ }
+ for _, stale := range []string{filepath.Join(home, ".claude", "settings.json"), filepath.Join(home, ".claude.json")} {
+ if config := findConfig(result.Configs, "claude_code", stale); config != nil {
+ t.Fatalf("inventory reported %s, which Claude Code does not read with CLAUDE_CONFIG_DIR set: %#v", stale, config)
+ }
+ }
+ found := false
+ for _, skill := range result.Skills {
+ if skill.Runtime == "claude_code" && skill.SkillName == "demo" {
+ found = true
+ }
+ }
+ if !found {
+ t.Fatalf("skills = %#v, want the demo skill under CLAUDE_CONFIG_DIR/skills", result.Skills)
+ }
+}
+
func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {
home := t.TempDir()
work := t.TempDir()
diff --git a/cli/beacon/internal/endpoint/inventory/main_test.go b/cli/beacon/internal/endpoint/inventory/main_test.go
new file mode 100644
index 00000000..ac945133
--- /dev/null
+++ b/cli/beacon/internal/endpoint/inventory/main_test.go
@@ -0,0 +1,13 @@
+package inventory
+
+import (
+ "os"
+ "testing"
+)
+
+// TestMain clears CLAUDE_CONFIG_DIR, which a developer's shell may set. Claude Code's user-scope
+// candidates follow it, and the tests here assume ~/.claude unless they set it themselves.
+func TestMain(m *testing.M) {
+ _ = os.Unsetenv("CLAUDE_CONFIG_DIR")
+ os.Exit(m.Run())
+}
diff --git a/cli/beacon/internal/endpoint/inventory/skills.go b/cli/beacon/internal/endpoint/inventory/skills.go
index d3568d9c..9268d98e 100644
--- a/cli/beacon/internal/endpoint/inventory/skills.go
+++ b/cli/beacon/internal/endpoint/inventory/skills.go
@@ -6,6 +6,7 @@ import (
"sort"
"time"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
)
@@ -69,8 +70,11 @@ func filterSkillRoots(items []skillRoot, runtimes []string) []skillRoot {
}
func skillRoots(home, wd string) []skillRoot {
- items := []skillRoot{
- {runtime: "claude_code", path: filepath.Join(home, ".claude", "skills"), scope: ScopeUser},
+ items := []skillRoot{}
+ if dir := claudesession.ConfigDir(home); dir != "" {
+ items = append(items, skillRoot{runtime: "claude_code", path: filepath.Join(dir, "skills"), scope: ScopeUser})
+ }
+ items = append(items, []skillRoot{
{runtime: "claude_code", path: filepath.Join(wd, ".claude", "skills"), scope: ScopeProject},
{runtime: "cursor", path: filepath.Join(home, ".cursor", "skills"), scope: ScopeUser},
{runtime: "cursor", path: filepath.Join(wd, ".cursor", "skills"), scope: ScopeProject},
@@ -78,7 +82,7 @@ func skillRoots(home, wd string) []skillRoot {
{runtime: "cursor", path: filepath.Join(wd, ".cursor", "skills-cursor"), scope: ScopeProject},
{runtime: "agent_skills", path: filepath.Join(home, ".agents", "skills"), scope: ScopeUser},
{runtime: "agent_skills", path: filepath.Join(wd, ".agents", "skills"), scope: ScopeProject},
- }
+ }...)
seen := map[string]bool{}
out := make([]skillRoot, 0, len(items))
for _, item := range items {
diff --git a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
index 43732128..12284e6c 100644
--- a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
@@ -213,6 +213,36 @@ func TestInventoryJobEnvRecordsGeminiCLIHomeForUserInstalls(t *testing.T) {
}
}
+// Claude Code uses a trimmed, non-empty CLAUDE_CONFIG_DIR as is, so the job gets its absolute form
+// whenever it is set. It is recorded beside CODEX_HOME, not instead of it.
+func TestInventoryJobEnvRecordsClaudeConfigDirForUserInstalls(t *testing.T) {
+ work := t.TempDir()
+ t.Chdir(work)
+ cwd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ codexHome := filepath.Join(work, "codex-home")
+ if err := os.Mkdir(codexHome, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("CODEX_HOME", codexHome)
+ t.Setenv("CLINE_DIR", "")
+ t.Setenv("GEMINI_CLI_HOME", "")
+ t.Setenv("CLAUDE_CONFIG_DIR", " claude-alt ")
+
+ env := inventoryJobEnv(true)
+ if want := filepath.Join(cwd, "claude-alt"); env["CLAUDE_CONFIG_DIR"] != want {
+ t.Fatalf("CLAUDE_CONFIG_DIR = %q, want %q", env["CLAUDE_CONFIG_DIR"], want)
+ }
+ if env["CODEX_HOME"] == "" || len(env) != 2 {
+ t.Fatalf("env = %v, want both CODEX_HOME and CLAUDE_CONFIG_DIR", env)
+ }
+ if got := inventoryJobEnv(false); got != nil {
+ t.Fatalf("system mode env = %v, want none", got)
+ }
+}
+
func TestReconcileInventoryJobWritesWithoutLoadingWhenAsked(t *testing.T) {
testenv.SetHome(t, t.TempDir())
calls := installFakeInventoryJob(t, true)
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index 57fb44bf..dda54609 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -134,14 +134,15 @@ func reconcileInventoryJobWith(job inventoryJobController, opts InventoryJobOpti
}
// inventoryJobEnv is the environment written into a per-user inventory job. launchd and systemd
-// start the job without the user's shell environment, so a CODEX_HOME, CLINE_DIR or GEMINI_CLI_HOME
-// exported in a shell profile would not reach it and the scheduled scan would inventory ~/.codex,
-// ~/.cline or ~/.gemini while the runtime reads the moved directory. Each value is resolved now,
-// from the install's shell, as its runtime resolves it, and recorded as an absolute path so a
-// relative value still means the directory it named at install time:
+// start the job without the user's shell environment, so a CODEX_HOME, CLINE_DIR, GEMINI_CLI_HOME
+// or CLAUDE_CONFIG_DIR exported in a shell profile would not reach it and the scheduled scan would
+// inventory ~/.codex, ~/.cline, ~/.gemini or ~/.claude while the runtime reads the moved directory.
+// Each value is resolved now, from the install's shell, as its runtime resolves it, and recorded as
+// an absolute path so a relative value still means the directory it named at install time:
// - CODEX_HOME must name an existing directory, as Codex requires; otherwise nothing is recorded.
// - CLINE_DIR is used whenever it is non-empty after trimming, as Cline uses it.
// - GEMINI_CLI_HOME is used whenever it is non-empty, as Gemini CLI uses it.
+// - CLAUDE_CONFIG_DIR is used whenever it is non-empty after trimming, as Claude Code uses it.
//
// A variable that is unset records nothing, and the job falls back to the default as before.
// System mode records nothing: this process's environment is root's, not the console user's.
@@ -165,6 +166,11 @@ func inventoryJobEnv(userMode bool) map[string]string {
env["GEMINI_CLI_HOME"] = dir
}
}
+ if value := strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR")); value != "" {
+ if dir, err := filepath.Abs(value); err == nil {
+ env["CLAUDE_CONFIG_DIR"] = dir
+ }
+ }
if len(env) == 0 {
return nil
}
diff --git a/cli/beacon/internal/endpoint/lifecycle/main_test.go b/cli/beacon/internal/endpoint/lifecycle/main_test.go
index 4f54518b..8cc62ec2 100644
--- a/cli/beacon/internal/endpoint/lifecycle/main_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/main_test.go
@@ -17,7 +17,11 @@ import (
//
// The stand-ins answer as a machine with nothing installed, which is what CI sees, and refuse
// anything that would register or start a service.
+//
+// It also clears CLAUDE_CONFIG_DIR, which a developer's shell may set: tests that write Claude Code
+// settings assume ~/.claude unless they set the variable themselves.
func TestMain(m *testing.M) {
+ _ = os.Unsetenv("CLAUDE_CONFIG_DIR")
os.Exit(runWithServiceManagerStandIns(m))
}
diff --git a/cli/beacon/internal/mcpconnect/targets.go b/cli/beacon/internal/mcpconnect/targets.go
index 74493eec..168e40e1 100644
--- a/cli/beacon/internal/mcpconnect/targets.go
+++ b/cli/beacon/internal/mcpconnect/targets.go
@@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/harness"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
@@ -302,13 +303,13 @@ func homePath(parts ...string) func(string) (string, error) {
}
}
-// claudeConfigPath is the file `claude mcp add --scope user` writes: ~/.claude.json, or
-// .claude.json inside CLAUDE_CONFIG_DIR when that is set.
+// claudeConfigPath is the file `claude mcp add --scope user` writes: claudesession.StateFile.
func claudeConfigPath(home string) (string, error) {
- if dir := strings.TrimSpace(os.Getenv("CLAUDE_CONFIG_DIR")); dir != "" {
- return filepath.Join(dir, ".claude.json"), nil
+ path := claudesession.StateFile(home)
+ if path == "" {
+ return "", errors.New("home directory is empty")
}
- return filepath.Join(home, ".claude.json"), nil
+ return path, nil
}
// codexConfigPath resolves CODEX_HOME exactly as Codex and Beacon's session reader do.
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index 3164eb09..1afe3f48 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -12,6 +12,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
## October 2026
- **Concurrent hooks no longer clobber the per-session state file** · The hook adapter keeps a small `state.json` (session model, prompt-emitted flag, reprompt counts) that every hook process reads and rewrites. Two hooks running at once shared one temporary file, so one could fail with `rename ...: no such file or directory` and a surviving write could drop the other's change. Access is now serialized with a file lock and each write uses its own temporary file.
+- **Claude Code settings, sessions and inventory follow `CLAUDE_CONFIG_DIR`** · `beacon endpoint install`, `beacon endpoint hooks install --harness claude`, `beacon endpoint discover`, inventory, `beacon endpoint claude status` and `sync`, the session backfill and `beacon handoff` now use `$CLAUDE_CONFIG_DIR` when `CLAUDE_CONFIG_DIR` is set, as Claude Code does: `settings.json`, `.claude.json`, `skills` and `projects` all move with it. They previously always used `~/.claude` (and `~/.claude.json`), so with the variable set Claude Code never saw Beacon's OTLP settings or hooks, live capture silently recorded nothing, and session sync found no transcripts. A per-user install or repair also writes the resolved `CLAUDE_CONFIG_DIR` into the scheduled inventory job, as it does `CODEX_HOME`. Project-level `.claude/settings.json` is unchanged, and `--projects-dir` and `--claude-projects-dir` still override.
- **Codex install, hooks and inventory follow `CODEX_HOME`** · `beacon endpoint install`, `beacon endpoint hooks install --harness codex`, `beacon endpoint discover` and inventory now read and write `$CODEX_HOME/config.toml` and `$CODEX_HOME/hooks.json` when `CODEX_HOME` is set, as Codex does. They previously always used `~/.codex`, so with `CODEX_HOME` set, Codex never saw the OTLP exporter or the SessionStart hook and live capture silently recorded nothing. A per-user install or repair also writes the resolved `CODEX_HOME` into the scheduled inventory job, which launchd and systemd start without your shell's environment. A `CODEX_HOME` that is not an existing directory is now an install error rather than a silent write to `~/.codex`. Project-level `.codex` files are unchanged.
- **Oversized session events no longer stall a sync** · An event still over the 64 KB limit after its raw payload was dropped, such as a tool call with many large edit hunks, made session sync fail at that line on every sweep, so nothing later in that session was recorded. The writer now drops the event's retained content and marks it truncated, as the hook and collector writers already did, keeping the tool name, call ID and file path.
- **Cursor sync keeps prompts in compacted conversations** · In a Cursor conversation with a context summary, `beacon endpoint cursor sync` and the session backfill skipped the first new record on every sync that found new activity, often the next prompt, and recorded the compaction again each time. New records are now kept and each compaction is recorded once. A compaction already recorded by an older release is recorded one more time after upgrading.
diff --git a/docs/cli/endpoint-paths.mdx b/docs/cli/endpoint-paths.mdx
index fcf894c1..dd9ad6b6 100644
--- a/docs/cli/endpoint-paths.mdx
+++ b/docs/cli/endpoint-paths.mdx
@@ -54,7 +54,7 @@ Hook and plugin configuration is written to:
| Runtime | Global config path | Project-local config path |
|---|---|---|
| Antigravity CLI | `~/.gemini/config/hooks.json` | `./.agents/hooks.json` |
-| Claude Code | `~/.claude/settings.json` | `./.claude/settings.json` |
+| Claude Code | `~/.claude/settings.json` (`$CLAUDE_CONFIG_DIR/settings.json` when set) | `./.claude/settings.json` |
| Cline | `~/.cline/plugins/beacon.ts` | `./.cline/plugins/beacon.ts` |
| Cursor | `~/.cursor/hooks.json` | `./.cursor/hooks.json` |
| Devin CLI | `~/.config/devin/config.json` | `./.devin/hooks.v1.json` |
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index dd8ed201..b91a57d9 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -19,7 +19,7 @@ Sessions come from each runtime's own local session store, not from Beacon's run
| Runtime | Session store | `--harness` |
|---------|---------------|-------------|
-| Claude Code | `~/.claude/projects` | `claude` |
+| Claude Code | `~/.claude/projects` (`$CLAUDE_CONFIG_DIR/projects` when set) | `claude` |
| Codex CLI | `$CODEX_HOME/sessions` when set; otherwise `~/.codex/sessions` | `codex` |
| OpenCode | `~/.local/share/opencode` (or `$XDG_DATA_HOME/opencode`, and `OPENCODE_DB` when set; SQLite and the legacy file store) | `opencode` |
| Cline | `~/.cline/data` | `cline` |
diff --git a/docs/cli/hooks.mdx b/docs/cli/hooks.mdx
index 13daa220..6f6af24f 100644
--- a/docs/cli/hooks.mdx
+++ b/docs/cli/hooks.mdx
@@ -30,7 +30,7 @@ beacon endpoint hooks [command]
| Runtime | User-level config | Project-level config | Hook binary | Runtime log |
|---------|-------------------|----------------------|-------------|-------------|
| Antigravity CLI | `~/.gemini/config/hooks.json` | `./.agents/hooks.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
-| Claude Code | `~/.claude/settings.json` | `./.claude/settings.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
+| Claude Code | `~/.claude/settings.json` (`$CLAUDE_CONFIG_DIR/settings.json` when set) | `./.claude/settings.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
| Codex CLI | `$CODEX_HOME/hooks.json` (default `~/.codex/hooks.json`) | `./.codex/hooks.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
| Cursor | `~/.cursor/hooks.json` | `./.cursor/hooks.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
| Devin CLI | `~/.config/devin/config.json` | `./.devin/hooks.v1.json` | `~/.beacon/endpoint/hooks/beacon-hooks` | `~/.beacon/endpoint/logs/runtime.jsonl` |
diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdx
index 9218dcef..c48c638f 100644
--- a/docs/runtimes/claude-code.mdx
+++ b/docs/runtimes/claude-code.mdx
@@ -27,13 +27,13 @@ beacon endpoint hooks status --harness claude
beacon endpoint hooks uninstall --harness claude
```
-User-level hooks are written to `~/.claude/settings.json`. Project-level hooks are written to `./.claude/settings.json`:
+User-level hooks are written to `~/.claude/settings.json`, or to `$CLAUDE_CONFIG_DIR/settings.json` when `CLAUDE_CONFIG_DIR` is set, as Claude Code reads it. Project-level hooks are written to `./.claude/settings.json`:
```bash title="User-level hooks are written to ~/.claude/settings.json. Project-level hooks are written to ./.claude/settings.json"
beacon endpoint hooks install --harness claude --level project
```
-For backfill, Beacon can also read Claude Code's committed JSONL session files under `~/.claude/projects`:
+For backfill, Beacon can also read Claude Code's committed JSONL session files under `~/.claude/projects` (`$CLAUDE_CONFIG_DIR/projects` when `CLAUDE_CONFIG_DIR` is set, as Claude Code does):
```bash title="Sync Claude Code session files"
beacon endpoint claude status
@@ -42,6 +42,8 @@ beacon endpoint claude sync
The sync path is local and offline. It appends mapped events to the runtime log with `harness.collection_method=poll`, so it can recover historical sessions or sessions that ran before hooks were installed, but it cannot hold, approve, deny, or delay tool calls. Use `beacon endpoint claude sync --print` to preview mapped events without writing the runtime log or advancing the cursor.
+Install, hook install, discovery, inventory, session sync, `beacon handoff`, `beacon mcp connect` and Beacon's skills install honor `CLAUDE_CONFIG_DIR` as Claude Code does: when it is set, `settings.json`, `.claude.json`, `skills` and `projects` are read and written there instead of `~/.claude` and `~/.claude.json`. The scheduled inventory job starts without your shell's environment, so a per-user `beacon endpoint install` or `repair` writes the `CLAUDE_CONFIG_DIR` it resolved into the job's launchd or systemd definition. If you change `CLAUDE_CONFIG_DIR` later, run `beacon endpoint repair` from a shell that has the new value. System-mode installs do not record it.
+
## Claude Code Cloud Agents
Beacon also supports proof-of-concept telemetry capture from Claude Code