Skip to content

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

fix(copilot): honor COPILOT_HOME for the session store (#878)

Rudy Mizrahi Celeklie6e27340c939
diff --git a/cli/beacon/cmd/endpoint_copilot.go b/cli/beacon/cmd/endpoint_copilot.go
index d0ff1dfc..e795660d 100644
--- a/cli/beacon/cmd/endpoint_copilot.go
+++ b/cli/beacon/cmd/endpoint_copilot.go
@@ -18,7 +18,7 @@ var endpointCopilotCmd = &cobra.Command{
Short: "Collect telemetry from GitHub Copilot CLI sessions",
Long: `Collect endpoint telemetry from GitHub Copilot CLI's native session store.
-Copilot CLI persists local session records under ~/.copilot/session-state. Beacon
+Copilot CLI persists local session records under $COPILOT_HOME/session-state (default ~/.copilot/session-state). Beacon
reads those records after the fact and maps them to endpoint events with
harness.collection_method=poll. This complements the live OTLP integration:
OTLP still provides live approvals and spans, while session sync backfills
@@ -58,7 +58,7 @@ func init() {
for _, c := range []*cobra.Command{endpointCopilotSyncCmd, endpointCopilotStatusCmd} {
f := c.Flags()
- f.StringVar(&endpointCopilotOpts.copilotDir, "copilot-dir", "", "GitHub Copilot CLI directory (default ~/.copilot)")
+ f.StringVar(&endpointCopilotOpts.copilotDir, "copilot-dir", "", "GitHub Copilot CLI directory (default $COPILOT_HOME when set, otherwise ~/.copilot)")
f.StringVar(&endpointCopilotOpts.statePath, "state", "", "Collector cursor file (default ~/.beacon/endpoint/state/copilot.json)")
f.StringVar(&endpointCopilotOpts.workspace, "workspace", "", "Only include sessions whose cwd matches this workspace")
f.StringVar(&endpointCopilotOpts.sessionID, "session-id", "", "Only include one GitHub Copilot CLI session id")
diff --git a/cli/beacon/internal/copilotsession/copilotsession_test.go b/cli/beacon/internal/copilotsession/copilotsession_test.go
index 93dfabed..302d470c 100644
--- a/cli/beacon/internal/copilotsession/copilotsession_test.go
+++ b/cli/beacon/internal/copilotsession/copilotsession_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func writeCopilotFixture(t *testing.T, root string) (string, string) {
@@ -319,3 +320,23 @@ func readFile(t *testing.T, path string) string {
}
return string(data)
}
+
+func TestDefaultCopilotDirHonorsCopilotHome(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Setenv("COPILOT_HOME", "")
+ got, err := DefaultCopilotDir()
+ if err != nil || got != filepath.Join(home, ".copilot") {
+ t.Fatalf("default dir = %q, %v", got, err)
+ }
+ custom := filepath.Join(t.TempDir(), "copilot-state")
+ t.Setenv("COPILOT_HOME", custom)
+ got, err = DefaultCopilotDir()
+ if err != nil || got != custom {
+ t.Fatalf("COPILOT_HOME dir = %q, %v; want %q", got, err, custom)
+ }
+ store, err := NewStore("")
+ if err != nil || store.SessionStateDir != filepath.Join(custom, "session-state") {
+ t.Fatalf("store = %+v, %v", store, err)
+ }
+}
diff --git a/cli/beacon/internal/copilotsession/store.go b/cli/beacon/internal/copilotsession/store.go
index 867be382..91a429db 100644
--- a/cli/beacon/internal/copilotsession/store.go
+++ b/cli/beacon/internal/copilotsession/store.go
@@ -22,7 +22,11 @@ type Store struct {
SessionStateDir string
}
+// DefaultCopilotDir is the Copilot CLI state directory: COPILOT_HOME when set, else ~/.copilot.
func DefaultCopilotDir() (string, error) {
+ if override := strings.TrimSpace(os.Getenv("COPILOT_HOME")); override != "" {
+ return override, nil
+ }
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolve home directory: %w", err)
diff --git a/cli/beacon/internal/endpoint/harness/copilot.go b/cli/beacon/internal/endpoint/harness/copilot.go
index 70304ada..da33bdb5 100644
--- a/cli/beacon/internal/endpoint/harness/copilot.go
+++ b/cli/beacon/internal/endpoint/harness/copilot.go
@@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/copilotsession"
)
func DiscoverCopilotCLI() Harness {
@@ -15,7 +17,7 @@ func discoverCopilotCLI(expectedEndpoint string) Harness {
h := Harness{Name: "copilot_cli", DisplayName: "GitHub Copilot CLI", Capability: "otel_env"}
detectExecutable(&h, "copilot")
home, _ := os.UserHomeDir()
- if !h.Detected && fileExists(filepath.Join(home, ".copilot", "config.json")) {
+ if dir, err := copilotsession.DefaultCopilotDir(); !h.Detected && err == nil && fileExists(filepath.Join(dir, "config.json")) {
h.Detected = true
}
h.ConfigPath = factoryProfilePath(home)
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index c46e7c8c..ea89ead0 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -731,6 +731,7 @@ func TestDiscoverCopilotCLIDetectsConfigFile(t *testing.T) {
home := t.TempDir()
testenv.SetHome(t, home)
t.Setenv("PATH", t.TempDir())
+ t.Setenv("COPILOT_HOME", "")
configPath := filepath.Join(home, ".copilot", "config.json")
if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
t.Fatalf("mkdir copilot config dir: %v", err)
@@ -745,6 +746,33 @@ func TestDiscoverCopilotCLIDetectsConfigFile(t *testing.T) {
}
}
+// With COPILOT_HOME set, the config file that marks Copilot CLI as present is the one under it; a
+// stale ~/.copilot/config.json does not count.
+func TestDiscoverCopilotCLIDetectsConfigFileUnderCopilotHome(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Setenv("PATH", t.TempDir())
+ copilotHome := t.TempDir()
+ t.Setenv("COPILOT_HOME", copilotHome)
+ if err := os.WriteFile(filepath.Join(copilotHome, "config.json"), []byte(`{}`), 0600); err != nil {
+ t.Fatalf("write copilot config: %v", err)
+ }
+ if h := DiscoverCopilotCLI(); !h.Detected {
+ t.Fatalf("DiscoverCopilotCLI did not detect $COPILOT_HOME/config.json: %#v", h)
+ }
+
+ t.Setenv("COPILOT_HOME", filepath.Join(copilotHome, "empty"))
+ if err := os.MkdirAll(filepath.Join(home, ".copilot"), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(home, ".copilot", "config.json"), []byte(`{}`), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if h := DiscoverCopilotCLI(); h.Detected {
+ t.Fatalf("DiscoverCopilotCLI detected ~/.copilot/config.json with COPILOT_HOME pointing elsewhere: %#v", h)
+ }
+}
+
func TestDiscoverDevinDetectsExecutableOnPath(t *testing.T) {
testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index 40e42846..3164eb09 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -17,6 +17,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
- **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`.
+- **Copilot CLI sessions follow `COPILOT_HOME`** · `beacon endpoint copilot status` and `sync`, the session backfill, `beacon handoff` and `beacon endpoint discover` now use `$COPILOT_HOME` when `COPILOT_HOME` is set, as Copilot CLI does. They previously always used `~/.copilot`, so with `COPILOT_HOME` set, session sync found no sessions. `--copilot-dir` still overrides.
### v1.3.40 · October 14, 2026
diff --git a/docs/cli/endpoint-copilot.mdx b/docs/cli/endpoint-copilot.mdx
index 77745900..41eb51ba 100644
--- a/docs/cli/endpoint-copilot.mdx
+++ b/docs/cli/endpoint-copilot.mdx
@@ -5,7 +5,7 @@ description: "Collect endpoint telemetry from GitHub Copilot CLI session records
## Command overview
-`beacon endpoint copilot` collects telemetry from [GitHub Copilot CLI](/runtimes/github-copilot-cli) by reading the session records Copilot commits under `~/.copilot/session-state` and converting them into Beacon [endpoint events](/concepts/core-concepts#endpoint-event).
+`beacon endpoint copilot` collects telemetry from [GitHub Copilot CLI](/runtimes/github-copilot-cli) by reading the session records Copilot commits under `$COPILOT_HOME/session-state` (default `~/.copilot/session-state`) and converting them into Beacon [endpoint events](/concepts/core-concepts#endpoint-event).
```bash title="Command syntax"
beacon endpoint copilot [command]
@@ -30,7 +30,7 @@ Both subcommands accept:
| Flag | Description |
|------|-------------|
-| `--copilot-dir <path>` | GitHub Copilot CLI directory. Defaults to `~/.copilot` |
+| `--copilot-dir <path>` | GitHub Copilot CLI directory. Defaults to `$COPILOT_HOME` when set, otherwise `~/.copilot` |
| `--state <path>` | Collector cursor file. Defaults to `~/.beacon/endpoint/state/copilot.json` |
| `--workspace <path>` | Only include sessions whose recorded cwd matches this workspace |
| `--session-id <id>` | Only include one Copilot CLI session id |
@@ -63,7 +63,7 @@ beacon endpoint copilot sync --print
beacon endpoint copilot sync --watch --interval 5m
```
-Nothing sweeps on its own. Run `sync` under whatever scheduler the platform already uses, or leave `--watch` running in the account that owns `~/.copilot`.
+Nothing sweeps on its own. Run `sync` under whatever scheduler the platform already uses, or leave `--watch` running in the account that owns the Copilot directory. A scheduler that starts `sync` without your shell's environment needs `COPILOT_HOME` set in it, or `--copilot-dir`.
## Status
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index 6b794395..dd8ed201 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -26,7 +26,7 @@ Sessions come from each runtime's own local session store, not from Beacon's run
| Pi | `~/.pi/agent/sessions` (or under `PI_CODING_AGENT_DIR`) | `pi` |
| Prime Agent | `~/.prime/agent`, both `sessions` and `session-artifacts` (or `PRIME_AGENT_CODING_AGENT_DIR`) | `prime` |
| Factory Droid | `~/.factory/sessions` | `droid` |
-| GitHub Copilot CLI | `~/.copilot/session-state` | `copilot` |
+| GitHub Copilot CLI | `$COPILOT_HOME/session-state` when set; otherwise `~/.copilot/session-state` | `copilot` |
| Hermes Agent | `$HERMES_HOME/state.db` when set; otherwise `~/.hermes/state.db` (Windows: `%LOCALAPPDATA%/hermes/state.db`) | `hermes` |
| DeepSeek Harness | `~/.dsh/sessions` (or under `DSH_HOME`) | `dsh` |
| fx | `~/.fx/sessions` | `fx` |
diff --git a/docs/runtimes/github-copilot-cli.mdx b/docs/runtimes/github-copilot-cli.mdx
index 131316f2..ab64ae8f 100644
--- a/docs/runtimes/github-copilot-cli.mdx
+++ b/docs/runtimes/github-copilot-cli.mdx
@@ -16,19 +16,19 @@ Before enabling GitHub Copilot CLI telemetry, make sure:
- The Copilot CLI launch environment sets `COPILOT_OTEL_ENABLED=true`.
- The Copilot CLI launch environment sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318` or `COPILOT_OTEL_ENDPOINT=http://127.0.0.1:4318`.
- Copilot CLI is restarted after launch-environment changes so new sessions use the updated settings.
-- For local session backfill, Copilot CLI has written sessions under `~/.copilot/session-state`.
+- For local session backfill, Copilot CLI has written sessions under `$COPILOT_HOME/session-state` (default `~/.copilot/session-state`).
## Collection path
GitHub Copilot CLI exports OTLP HTTP telemetry to Beacon's local collector. Beacon normalizes Copilot spans into endpoint events for prompt submission, session activity, tool invocation, and approval-like permission activity.
-Beacon can also read committed session records from `~/.copilot/session-state` through [`beacon endpoint copilot sync`](/cli/endpoint-copilot). Polling backfills assistant text, complete tool results, command and file activity, and Copilot's persisted token usage. Every event from that path is marked `harness.collection_method=poll`, so readers can tell it was observed after Copilot committed the record rather than during the live tool call.
+Beacon can also read committed session records from `$COPILOT_HOME/session-state` (default `~/.copilot/session-state`) through [`beacon endpoint copilot sync`](/cli/endpoint-copilot). Polling backfills assistant text, complete tool results, command and file activity, and Copilot's persisted token usage. Every event from that path is marked `harness.collection_method=poll`, so readers can tell it was observed after Copilot committed the record rather than during the live tool call.
Copilot CLI metrics are filtered from the local runtime JSONL log by default so endpoint timelines stay focused on user and agent activity. Use `--include-runtime-metrics` during install or repair only when you need low-level Copilot metrics for troubleshooting.
## Discovery and status
-Beacon detects GitHub Copilot CLI through the `copilot` executable or `~/.copilot/config.json`. Use `beacon endpoint discover` or `beacon endpoint status` to confirm that Copilot CLI is present and exporting to Beacon's local OTLP HTTP receiver.
+Beacon detects GitHub Copilot CLI through the `copilot` executable or `$COPILOT_HOME/config.json` (default `~/.copilot/config.json`). Use `beacon endpoint discover` or `beacon endpoint status` to confirm that Copilot CLI is present and exporting to Beacon's local OTLP HTTP receiver.
Use `beacon endpoint copilot status` to inspect local session files and see how far the poll cursor has collected them.