# @tryglen/cli

Glen CLI — shared team memory for coding agents.

## Install

```bash
npm install -g @tryglen/cli
glen login
```

## Commands

| Command                                              | Description                                                                                                                                                                                                                                                     |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `glen login`                                         | Connect via browser sign-in; writes credentials and initial session state.                                                                                                                                                                                      |
| `glen logout`                                        | Sign out and remove credentials + session state.                                                                                                                                                                                                                |
| `glen status`                                        | Show connection status, active org, incognito state, and CLI version.                                                                                                                                                                                           |
| `glen search "<query>"`                              | Search the team's shared glen memory.                                                                                                                                                                                                                           |
| `glen takeover <code>`                               | Redeem a transcript-page handoff into a fresh native Claude Code, Codex, Cursor, or Pi session, then open it. The complete transcript must fit; Glen never truncates or summarizes it.                                                                          |
| `glen import <path…> [--dry-run]`                    | Import old local agent transcripts (Claude Code `~/.claude/projects`, Codex `~/.codex/sessions`, Cursor `state.vscdb`, Pi `~/.pi/agent/sessions`) into glen memory. Idempotent — re-running skips already-imported turns. `--dry-run` previews without writing. |
| `glen incognito on\|off`                             | Toggle incognito mode: while on, nothing is recorded (recall keeps working).                                                                                                                                                                                    |
| `glen org list`                                      | List your organizations; active one is marked with `✓`.                                                                                                                                                                                                         |
| `glen org switch [slug]`                             | Switch the active organization for this machine (interactive picker without `slug`).                                                                                                                                                                            |
| `glen ingest [--agent <name>]`                       | Ingest a turn from stdin — used by agent hooks (`claude-code`, `codex`, `cursor`, or `pi`).                                                                                                                                                                     |
| `glen install [--agent <claude\|codex\|cursor\|pi>]` | Set up or update glen for detected coding agents (plugin + hooks); idempotent, so re-running repairs a broken setup. `--claude-path <path>` / `--codex-path <path>` / `--pi-path <path>` point at a binary when auto-detection fails.                           |
| `glen uninstall`                                     | Permanently remove Glen's local plugins, marketplaces, hooks, PATH entries, credentials, state, caches, and global npm CLI.                                                                                                                                     |
| `glen update`                                        | Update the glen CLI **and** any installed glen plugins, and re-verify the Codex hook registration. Never installs a plugin that isn't already installed — that's `glen install`'s job.                                                                          |
| `glen doctor [--auto]`                               | Print machine-readable `status:` lines (CLI version/latest/channel, login + org, per-agent plugin + hook state) plus `→` remedy lines — the setup skill branches on them. `--auto` runs background updates silently (used by hooks).                            |
| `glen statusline`                                    | Output a single status line for the agent's UI status bar — used by hooks.                                                                                                                                                                                      |
| `glen session-start [--agent <name>]`                | Output hook JSON for the agent's `SessionStart` event — used by hooks.                                                                                                                                                                                          |
| `glen version`                                       | Print the CLI version.                                                                                                                                                                                                                                          |

## Files

| File                       | Description                                                                                         |
| -------------------------- | --------------------------------------------------------------------------------------------------- |
| `~/.glen/credentials.json` | API key credential — mode `0600`, never logged or sent to anyone but `tryglen.com`.                 |
| `~/.glen/state.json`       | Client-owned session state: `{ activeOrgId, activeOrgSlug, activeOrgName, incognito }`. Non-secret. |

The state file is what the CLI sends as `x-glen-org-id` / `x-glen-incognito` headers on every request. The server validates org membership on every call — no state is stored server-side.

## Transcript takeover

Open a shared agent-session transcript in Glen, choose **Take over**, select the
destination agent, and run the generated command from the destination project:

```bash
glen takeover <code>
```

The code is bound to the signed-in recipient and active organization and expires
after 15 minutes. Glen checks the installed agent version, native history format,
launcher, and a conservative context-window budget before it writes anything. It
then stages a fresh session, parses that native session back, verifies the full
message digest, installs it without overwriting an existing session, records the
handoff, and launches the agent. The source transcript is never changed.

If any check fails, Glen prints what failed and how to retry. If installation
succeeds but launch fails, it prints the native resume command. Cursor takeover
requires Cursor 3.9.x to be fully closed and Node.js 22.5 or newer; Glen backs up
both Cursor SQLite stores and updates them in one transaction. Claude Code 2.1.x,
Codex CLI 0.143.x–0.144.x, and Pi v3 session trees are supported by this release.
Unknown versions, schemas, models, or context capacities fail closed. Running
tools, terminals, approvals, and other live runtime state do not transfer.

## Uninstall

`glen uninstall` permanently removes Glen's local agent plugins, marketplaces,
hooks, PATH entries, credentials, state, caches, and global npm CLI. It preserves
source repositories, agent transcripts, and cloud account/team data.

Cursor plugins must be removed in Cursor's plugin settings because Cursor does
not expose a supported plugin-removal CLI. If Cursor is detected, the command
reports the exact manual step and exits nonzero until that editor-managed residue
is addressed.

## Environment variables

| Variable                | Default                    | Description                                                                       |
| ----------------------- | -------------------------- | --------------------------------------------------------------------------------- |
| `GLEN_BASE_URL`         | `https://app.tryglen.com`  | Override the glen server URL (useful for local dev).                              |
| `GLEN_CREDENTIALS_PATH` | `~/.glen/credentials.json` | Override credentials file location.                                               |
| `GLEN_STATE_PATH`       | `~/.glen/state.json`       | Override state file location.                                                     |
| `GLEN_NO_AUTO_UPDATE`   | unset                      | Set to `1` to disable automatic background updates. Also disabled when `CI=true`. |

## Update behavior

The CLI uses layered silent auto-update so you stay current without thinking about it:

1. **Background TTL check (daily):** once per 24 hours, when installed via npm globally, the CLI spawns a detached `npm install -g @tryglen/cli@latest` process that doesn't block your turn. A `~/.glen/update-check.json` timestamp controls the cadence.
2. **SessionStart hook (`glen doctor --auto`):** on every agent session start, the hook also triggers background update + plugin upgrade hints. Same detached, non-blocking approach.
3. **Server-driven 426 floor:** if the server requires a newer CLI version (breaking API change), it responds with `HTTP 426 Upgrade Required`. The CLI then runs a synchronous self-update and re-execs your original command with `GLEN_REEXEC=1` set to prevent infinite loops. If the update fails or you are below the minimum after re-exec, it exits with a message to run `npm i -g @tryglen/cli@latest` manually.

Escape hatches:

- `GLEN_NO_AUTO_UPDATE=1` disables all background update attempts.
- `CI=true` (set automatically in GitHub Actions and most CI systems) also disables them.
- The CLI only self-updates when installed globally via npm (it detects this by comparing the binary's real path against `npm prefix -g`). If you installed via another package manager, you get a hint to update with your own tooling instead.

## Troubleshooting

**`glen status` shows "not connected"**
Run `glen login` to authenticate via browser.

**`glen search` / `glen ingest` prints "no active organization"**
Run `glen org switch` (or `glen login` if you've never connected) to pick an organization.

**426 error in CI or non-npm installs**
The server requires a newer CLI version. Run `npm i -g @tryglen/cli@latest` (or equivalent for your package manager) and retry.

**Stuck update lock**
If a previous update was interrupted, a stale lock can prevent future auto-updates:

```bash
rm -rf ~/.glen/update.lock
```

**`glen doctor` for a full picture**
Run `glen doctor` to see your version, the latest available, install channel, and session state in one place.
