The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(gemini): resolve user settings through GEMINI_CLI_HOME (#880)
Rudy Mizrahi Celekli4667f96e7d87
diff --git a/cli/beacon/internal/endpoint/harness/gemini.go b/cli/beacon/internal/endpoint/harness/gemini.goindex 24ef7b77..72fba42e 100644--- a/cli/beacon/internal/endpoint/harness/gemini.go+++ b/cli/beacon/internal/endpoint/harness/gemini.go@@ -8,11 +8,21 @@ import ("strings")+// GeminiSettingsPath is the user-scope Gemini CLI settings file. Gemini CLI looks for its+// `.gemini` directory under GEMINI_CLI_HOME when that is non-empty, used as is, and under the OS+// home otherwise (homedir in packages/core/src/utils/paths.ts).+func GeminiSettingsPath(home string) string {+ if override := os.Getenv("GEMINI_CLI_HOME"); override != "" {+ home = override+ }+ return filepath.Join(home, ".gemini", "settings.json")+}+func DiscoverGemini() Harness {h := Harness{Name: "gemini_cli", DisplayName: "Gemini CLI", Capability: "otel_config"}detectExecutable(&h, "gemini")home, _ := os.UserHomeDir()- h.ConfigPath = filepath.Join(home, ".gemini", "settings.json")+ h.ConfigPath = GeminiSettingsPath(home)if fileExists(h.ConfigPath) {status, msg := geminiStatus(h.ConfigPath)h.TelemetryStatus = status@@ -29,7 +39,7 @@ func ConfigureGemini(opts ConfigureOptions) (string, error) {if err != nil {return "", err}- path := filepath.Join(home, ".gemini", "settings.json")+ path := GeminiSettingsPath(home)settings := map[string]interface{}{}if data, err := os.ReadFile(path); err == nil {if err := json.Unmarshal(data, &settings); err != nil {diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.goindex de388afc..c46e7c8c 100644--- a/cli/beacon/internal/endpoint/harness/harness_test.go+++ b/cli/beacon/internal/endpoint/harness/harness_test.go@@ -1072,3 +1072,29 @@ func TestDiscoverClineDoesNotFallBackToAProjectPluginWhenHomeIsUnresolvable(t *tt.Errorf("Message = %q, want it to name the unresolved directory", h.Message)}}++func TestGeminiSettingsHonorGeminiCLIHome(t *testing.T) {+ home := t.TempDir()+ testenv.SetHome(t, home)+ t.Setenv("GEMINI_CLI_HOME", "")+ if got, want := GeminiSettingsPath(home), filepath.Join(home, ".gemini", "settings.json"); got != want {+ t.Fatalf("default path = %q, want %q", got, want)+ }++ geminiHome := t.TempDir()+ t.Setenv("GEMINI_CLI_HOME", geminiHome)+ want := filepath.Join(geminiHome, ".gemini", "settings.json")+ written, err := ConfigureGemini(ConfigureOptions{Endpoint: "http://127.0.0.1:4317", UserMode: true})+ if err != nil {+ t.Fatalf("ConfigureGemini returned error: %v", err)+ }+ if written != want {+ t.Fatalf("ConfigureGemini path = %q, want %q", written, want)+ }+ if _, err := os.Stat(filepath.Join(home, ".gemini")); !os.IsNotExist(err) {+ t.Fatalf("settings were also written under the OS home: %v", err)+ }+ if got := DiscoverGemini().ConfigPath; got != want {+ t.Fatalf("DiscoverGemini config path = %q, want %q", got, want)+ }+}diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.goindex ba9afd28..9174363a 100644--- a/cli/beacon/internal/endpoint/inventory/inventory.go+++ b/cli/beacon/internal/endpoint/inventory/inventory.go@@ -17,6 +17,7 @@ import ("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""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks")@@ -301,7 +302,7 @@ func cursorCandidates(home, wd string) []candidate {}func geminiCandidates(home string) []candidate {- return []candidate{{runtime: "gemini_cli", path: filepath.Join(home, ".gemini", "settings.json"), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig}}+ return []candidate{{runtime: "gemini_cli", path: harness.GeminiSettingsPath(home), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig}}}func antigravityCandidates(home, wd string) []candidate {diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.goindex 5ddef3c7..f1de0864 100644--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go@@ -386,6 +386,24 @@ func TestScanReadsClinePluginFromClineDir(t *testing.T) {}}+// With GEMINI_CLI_HOME set, the Gemini CLI settings inventory reads are the ones Gemini reads.+func TestScanReadsGeminiSettingsFromGeminiCLIHome(t *testing.T) {+ home := t.TempDir()+ geminiHome := t.TempDir()+ t.Setenv("GEMINI_CLI_HOME", geminiHome)+ writeFile(t, filepath.Join(geminiHome, ".gemini", "settings.json"), `{"mcpServers":{"github":{"command":"gh"}}}`)+ writeFile(t, filepath.Join(home, ".gemini", "settings.json"), `{"mcpServers":{"stale":{"command":"old"}}}`)++ result := Scan(Options{HomeDir: home, SkipProjectScope: true, Runtimes: []string{"gemini_cli"}, Now: fixedNow})+ config := findConfig(result.Configs, "gemini_cli", filepath.Join(geminiHome, ".gemini", "settings.json"))+ if config == nil || !config.Exists || config.MCPServerCount != 1 {+ t.Fatalf("GEMINI_CLI_HOME settings.json = %#v, want it read with one MCP server", config)+ }+ if stale := findConfig(result.Configs, "gemini_cli", filepath.Join(home, ".gemini", "settings.json")); stale != nil {+ t.Fatalf("inventory reported ~/.gemini/settings.json, which Gemini does not read with GEMINI_CLI_HOME set: %#v", stale)+ }+}+func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {home := t.TempDir()work := t.TempDir()@@ -400,9 +418,11 @@ func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {// are cleared for the same reason.t.Setenv("OMO_CODING_AGENT_DIR", "")t.Setenv("SENPI_CODING_AGENT_DIR", "")- // Codex's and Cline's user-scope files follow CODEX_HOME and CLINE_DIR.+ // Codex's, Cline's and Gemini CLI's user-scope files follow CODEX_HOME, CLINE_DIR and+ // GEMINI_CLI_HOME.t.Setenv("CODEX_HOME", "")t.Setenv("CLINE_DIR", "")+ t.Setenv("GEMINI_CLI_HOME", "")result := Scan(Options{HomeDir: home,diff --git a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.goindex a010a24c..43732128 100644--- a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go+++ b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go@@ -133,6 +133,7 @@ func TestInventoryJobEnvRecordsCodexHomeForUserInstalls(t *testing.T) {}t.Chdir(work)t.Setenv("CLINE_DIR", "")+ t.Setenv("GEMINI_CLI_HOME", "")// Relative, so the job, which starts elsewhere, needs the absolute form.t.Setenv("CODEX_HOME", "codex-home")@@ -169,6 +170,7 @@ func TestInventoryJobEnvRecordsClineDirForUserInstalls(t *testing.T) {}t.Setenv("CODEX_HOME", codexHome)t.Setenv("CLINE_DIR", " cline-state ")+ t.Setenv("GEMINI_CLI_HOME", "")env := inventoryJobEnv(true)if want := filepath.Join(cwd, "cline-state"); env["CLINE_DIR"] != want {@@ -182,6 +184,35 @@ func TestInventoryJobEnvRecordsClineDirForUserInstalls(t *testing.T) {}}+// Gemini CLI uses a non-empty GEMINI_CLI_HOME as is, without requiring it to exist, so the job gets+// its absolute form whenever it is set. It is recorded beside CODEX_HOME, not instead of it.+func TestInventoryJobEnvRecordsGeminiCLIHomeForUserInstalls(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", "gemini-home")++ env := inventoryJobEnv(true)+ if want := filepath.Join(cwd, "gemini-home"); env["GEMINI_CLI_HOME"] != want {+ t.Fatalf("GEMINI_CLI_HOME = %q, want %q", env["GEMINI_CLI_HOME"], want)+ }+ if env["CODEX_HOME"] == "" || len(env) != 2 {+ t.Fatalf("env = %v, want both CODEX_HOME and GEMINI_CLI_HOME", 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.goindex ca79a03a..57fb44bf 100644--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go@@ -134,13 +134,14 @@ 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 or CLINE_DIR exported in a-// shell profile would not reach it and the scheduled scan would inventory ~/.codex or ~/.cline-// 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 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:// - 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.//// 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.@@ -159,6 +160,11 @@ func inventoryJobEnv(userMode bool) map[string]string {env["CLINE_DIR"] = dir}}+ if value := os.Getenv("GEMINI_CLI_HOME"); value != "" {+ if dir, err := filepath.Abs(value); err == nil {+ env["GEMINI_CLI_HOME"] = dir+ }+ }if len(env) == 0 {return nil}diff --git a/cli/beacon/internal/mcpconnect/harness_test.go b/cli/beacon/internal/mcpconnect/harness_test.goindex aa80f3ab..0cfab1d1 100644--- a/cli/beacon/internal/mcpconnect/harness_test.go+++ b/cli/beacon/internal/mcpconnect/harness_test.go@@ -433,6 +433,7 @@ func isolate(t *testing.T) string {t.Setenv("XDG_CONFIG_HOME", "")t.Setenv("CLAUDE_CONFIG_DIR", "")t.Setenv("CODEX_HOME", "")+ t.Setenv("GEMINI_CLI_HOME", "")// An explicitly empty OMP_PROFILE is Oh My Pi's default profile even when PI_PROFILE is set.for _, name := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} {t.Setenv(name, "")@@ -788,6 +789,16 @@ func TestCodexHonorsCodexHome(t *testing.T) {}}+func TestGeminiHonorsGeminiCLIHome(t *testing.T) {+ home := isolate(t)+ geminiHome := filepath.Join(home, "elsewhere")+ t.Setenv("GEMINI_CLI_HOME", geminiHome)+ connect(t, fileOptions(home), mustTarget(t, "gemini"))+ if !strings.Contains(readFile(t, filepath.Join(geminiHome, ".gemini", "settings.json")), "beacon-managed") {+ t.Fatal("GEMINI_CLI_HOME was not honored")+ }+}+func TestClaudeHonorsClaudeConfigDir(t *testing.T) {home := isolate(t)dir := filepath.Join(home, "claude-config")diff --git a/cli/beacon/internal/mcpconnect/targets.go b/cli/beacon/internal/mcpconnect/targets.goindex 4906454d..74493eec 100644--- a/cli/beacon/internal/mcpconnect/targets.go+++ b/cli/beacon/internal/mcpconnect/targets.go@@ -148,7 +148,7 @@ func Targets() []Target {},{Name: "gemini_cli", DisplayName: "Gemini CLI", Aliases: []string{"gemini", "gemini-cli"},- Automatic: true, format: formatJSON, path: homePath(".gemini", "settings.json"), container: []string{"mcpServers"},+ Automatic: true, format: formatJSON, path: func(home string) (string, error) { return harness.GeminiSettingsPath(home), nil }, container: []string{"mcpServers"},entry: func(url, tokenEnv string) ordered {e := ordered{{"url", url}, {"type", "http"}}if tokenEnv != "" {diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex de5e60fb..40e42846 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -16,6 +16,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.- **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.- **Cline plugin and sessions follow `CLINE_DIR`** · `beacon endpoint hooks install --harness cline`, `beacon endpoint discover`, inventory, `beacon endpoint cline status` and `sync`, and the session backfill now use `$CLINE_DIR` when `CLINE_DIR` is set, as Cline does. They previously always used `~/.cline`, so with `CLINE_DIR` set, the Beacon plugin went where Cline never loads it, live capture silently recorded nothing, and session sync found no sessions. A per-user install or repair also writes the resolved `CLINE_DIR` into the scheduled inventory job, as it does `CODEX_HOME`.+- **Gemini CLI settings follow `GEMINI_CLI_HOME`** · `beacon endpoint install`, `beacon endpoint discover`, inventory and `beacon mcp connect` now read and write `$GEMINI_CLI_HOME/.gemini/settings.json` when `GEMINI_CLI_HOME` is set, as Gemini CLI does. They previously always used `~/.gemini/settings.json`, so with `GEMINI_CLI_HOME` set, Gemini never saw Beacon's OTLP settings and live capture silently recorded nothing. A per-user install or repair also writes the resolved `GEMINI_CLI_HOME` into the scheduled inventory job, as it does `CODEX_HOME`.### v1.3.40 · October 14, 2026diff --git a/docs/cli/mcp-connect.mdx b/docs/cli/mcp-connect.mdxindex 143fb276..5bded846 100644--- a/docs/cli/mcp-connect.mdx+++ b/docs/cli/mcp-connect.mdx@@ -187,7 +187,7 @@ Connect writes these entries (OAuth mode shown, then what `--token-env NAME` add| Codex CLI | `~/.codex/config.toml` (`$CODEX_HOME`) | `[mcp_servers.beacon-managed]` `url = …` | `bearer_token_env_var = "NAME"` | `codex mcp login beacon-managed` || Cursor | `~/.cursor/mcp.json` | `mcpServers.beacon-managed = {"url": …}` | `"Bearer ${env:NAME}"` | Cursor Settings → MCP, then sign in where it says "Needs login" || VS Code | User-profile `mcp.json` (next to the user `settings.json`) | `servers.beacon-managed = {"type": "http", "url": …}` | `"Bearer ${input:beacon-managed-token}"` and a password prompt input | "MCP: List Servers", then start `beacon-managed` |-| Gemini CLI | `~/.gemini/settings.json` | `mcpServers.beacon-managed = {"url": …, "type": "http"}` | `"Bearer ${NAME}"` | `/mcp auth beacon-managed` |+| Gemini CLI | `~/.gemini/settings.json` (`$GEMINI_CLI_HOME/.gemini/settings.json`) | `mcpServers.beacon-managed = {"url": …, "type": "http"}` | `"Bearer ${NAME}"` | `/mcp auth beacon-managed` || OpenCode | `~/.config/opencode/opencode.json`, or `opencode.jsonc` | `mcp.beacon-managed = {"type": "remote", "url": …, "enabled": true}` | `"oauth": false`, `"Bearer {env:NAME}"` | `opencode mcp auth beacon-managed` || Oh My Pi | The active profile's `mcp.json`: `~/.omp/agent/mcp.json`, or `~/.omp/profiles/<name>/agent/mcp.json` under `OMP_PROFILE` (or `PI_PROFILE`). `PI_CODING_AGENT_DIR` replaces the default profile's directory, and `PI_CONFIG_DIR` renames `.omp` | `mcpServers.beacon-managed = {"type": "http", "url": …}` | `headers.Authorization: "Bearer ${NAME}"` | `/mcp reauth beacon-managed` |diff --git a/docs/runtimes/gemini-cli.mdx b/docs/runtimes/gemini-cli.mdxindex 4624d7b4..d7f893c0 100644--- a/docs/runtimes/gemini-cli.mdx+++ b/docs/runtimes/gemini-cli.mdx@@ -23,13 +23,15 @@ Gemini CLI exports local OpenTelemetry data to Beacon's localhost collector when## Discovery and status-Beacon detects Gemini CLI through the `gemini` executable and `~/.gemini/settings.json`. Use `beacon endpoint discover` or `beacon endpoint status` to confirm that Gemini CLI is present and configured.+Beacon detects Gemini CLI through the `gemini` executable and `$GEMINI_CLI_HOME/.gemini/settings.json` (default `~/.gemini/settings.json`). Use `beacon endpoint discover` or `beacon endpoint status` to confirm that Gemini CLI is present and configured.++Install, discovery, inventory, and `beacon mcp connect` honor `GEMINI_CLI_HOME` as Gemini CLI does: when it is set, its `.gemini` directory replaces `~/.gemini`. The scheduled inventory job starts without your shell's environment, so a per-user `beacon endpoint install` or `repair` writes the `GEMINI_CLI_HOME` it resolved into the job's launchd or systemd definition. If you change `GEMINI_CLI_HOME` later, run `beacon endpoint repair` from a shell that has the new value. System-mode installs do not record it.## Install or configuration supportThe default `beacon endpoint install` configures Gemini automatically when it is detected. Run `beacon endpoint install --harness claude,codex,gemini` to select it explicitly instead.-Beacon writes local OTLP settings to `~/.gemini/settings.json`, sets `target` to `local`, uses OTLP gRPC, enables collector mode, and removes `outfile` so telemetry flows to Beacon.+Beacon writes local OTLP settings to `$GEMINI_CLI_HOME/.gemini/settings.json` (default `~/.gemini/settings.json`), sets `target` to `local`, uses OTLP gRPC, enables collector mode, and removes `outfile` so telemetry flows to Beacon.Gemini CLI is not currently configured through Beacon's hook adapter.