Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 86 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ jobs:
- name: Outside a cloud environment cloud.bash installs nothing
run: |
set -euo pipefail
out=$(cat ./cloud.bash | env -u CLAUDE_CODE_REMOTE bash 2>&1) || { echo "$out"; echo "cloud.bash exited non-zero"; exit 1; }
out=$(cat ./cloud.bash | env -u CLAUDE_CODE_REMOTE -u CURSOR_CLOUD -u CURSOR_BACKGROUND_AGENT -u SHELLTIME_CLOUD bash 2>&1) || { echo "$out"; echo "cloud.bash exited non-zero"; exit 1; }
echo "$out"
echo "$out" | grep -q "only runs in Claude Code cloud environments" || { echo "missing the refusal"; exit 1; }
echo "$out" | grep -q "only runs in cloud agent environments" || { echo "missing the refusal"; exit 1; }
[ ! -e "$HOME/.shelltime" ] || { echo "~/.shelltime was created"; exit 1; }

- name: Run cloud.bash the way a setup script does, twice
- name: Run cloud.bash for Claude Code cloud, twice
run: |
set -euo pipefail
for run in 1 2; do
Expand All @@ -130,7 +130,7 @@ jobs:
echo "$out" | grep -q "ShellTime is installed" || { echo "run $run did not finish"; exit 1; }
done

- name: Verify installation
- name: Verify Claude Code cloud installation
run: |
set -euo pipefail
hook="$HOME/.shelltime/bin/cloud-session-start.sh"
Expand Down Expand Up @@ -159,3 +159,85 @@ jobs:
grep -qx "token: proxy-injected" "$config" || { echo "expected the proxy-injected token again"; cat "$config"; exit 1; }
[ "$(pgrep -fxc "$daemon")" = 1 ] || { echo "expected one daemon"; pgrep -fxa "$daemon"; exit 1; }
pkill -fx "$daemon"

- name: Run cloud.bash for Antigravity cloud, twice
run: |
set -euo pipefail
AGY_HOME=$(mktemp -d)
# Preserve an existing unrelated hook group in hooks.json
mkdir -p "$AGY_HOME/.gemini/config"
echo '{"custom-hook":{"SessionStart":[{"type":"command","command":"echo {}"}]}}' >"$AGY_HOME/.gemini/config/hooks.json"

for run in 1 2; do
out=$(cat ./cloud.bash | env -u CLAUDE_CODE_REMOTE HOME="$AGY_HOME" SHELLTIME_CLOUD=true SHELLTIME_TOKEN=st_v1_agy_setup bash 2>&1) || { echo "$out"; echo "cloud.bash exited non-zero"; exit 1; }
echo "$out"
echo "$out" | grep -q "ShellTime is installed; Antigravity sessions" || { echo "run $run did not finish"; exit 1; }
done

hook="$AGY_HOME/.shelltime/bin/agy-cloud-session-start.sh"
hooks_json="$AGY_HOME/.gemini/config/hooks.json"
config="$AGY_HOME/.shelltime/config.yaml"
daemon="$AGY_HOME/.shelltime/bin/shelltime-daemon"

[ -x "$AGY_HOME/.shelltime/bin/shelltime" ] || { echo "shelltime missing"; exit 1; }
[ -x "$daemon" ] || { echo "shelltime-daemon missing"; exit 1; }
[ -x "$hook" ] || { echo "agy SessionStart hook missing"; exit 1; }
grep -qx "token: st_v1_agy_setup" "$config" || { echo "expected baked setup token"; cat "$config"; exit 1; }

# Verify strict JSON, separate "shelltime-cloud" group, no "shelltime" group, existing hook preserved
jq -e '."custom-hook".SessionStart | length == 1' "$hooks_json"
jq -e 'has("shelltime") | not' "$hooks_json"
jq -e --arg cmd "$hook" '."shelltime-cloud".SessionStart | length == 1 and .[0].command == $cmd' "$hooks_json"

# Hook prints {} (required by Antigravity), keeps baked token when env var is absent, and starts daemon once
out=$(env -u SHELLTIME_TOKEN HOME="$AGY_HOME" "$hook")
[ "$out" = "{}" ] || { echo "expected '{}', got: $out"; exit 1; }
grep -qx "token: st_v1_agy_setup" "$config" || { echo "baked token was overwritten"; cat "$config"; exit 1; }
for _ in 1 2 3 4 5; do pgrep -fx "$daemon" >/dev/null && [ -S /tmp/shelltime.sock ] && break; sleep 1; done
[ -S /tmp/shelltime.sock ] || { echo "daemon socket not created"; cat "$AGY_HOME/.shelltime/logs/shelltime-daemon.log"; exit 1; }
pgrep -fx "$daemon" >/dev/null || { echo "daemon not started"; cat "$AGY_HOME/.shelltime/logs/shelltime-daemon.log"; exit 1; }

# Runtime SHELLTIME_TOKEN overrides baked token and doesn't start a second daemon
out=$(SHELLTIME_TOKEN=st_v1_agy_runtime HOME="$AGY_HOME" "$hook")
[ "$out" = "{}" ] || { echo "expected '{}', got: $out"; exit 1; }
grep -qx "token: st_v1_agy_runtime" "$config" || { echo "expected runtime token"; cat "$config"; exit 1; }
[ "$(pgrep -fxc "$daemon")" = 1 ] || { echo "expected one daemon"; pgrep -fxa "$daemon"; exit 1; }
pkill -fx "$daemon"
rm -rf "$AGY_HOME"

- name: Run cloud.bash for Cursor Cloud Agents, twice
run: |
set -euo pipefail
CURSOR_HOME=$(mktemp -d)
mkdir -p "$CURSOR_HOME/.cursor"

# 1. Install step (no token yet, SHELLTIME_CLOUD=true + ~/.cursor present)
out=$(cat ./cloud.bash | env -u CLAUDE_CODE_REMOTE -u SHELLTIME_TOKEN HOME="$CURSOR_HOME" SHELLTIME_CLOUD=true bash 2>&1) || { echo "$out"; echo "cloud.bash exited non-zero"; exit 1; }
echo "$out"
echo "$out" | grep -q "ShellTime is installed; Cursor Cloud Agent sessions" || { echo "install step did not finish"; exit 1; }

start_hook="$CURSOR_HOME/.shelltime/bin/cloud-start.sh"
config="$CURSOR_HOME/.shelltime/config.yaml"
daemon="$CURSOR_HOME/.shelltime/bin/shelltime-daemon"

[ -x "$CURSOR_HOME/.shelltime/bin/shelltime" ] || { echo "shelltime missing"; exit 1; }
[ -x "$daemon" ] || { echo "shelltime-daemon missing"; exit 1; }
[ -x "$start_hook" ] || { echo "cloud-start.sh missing"; exit 1; }
# Cursor Cloud Agents ignore ~/.cursor/hooks.json and should not get ~/.gemini/config/hooks.json
[ ! -e "$CURSOR_HOME/.cursor/hooks.json" ] || { echo "should not write ~/.cursor/hooks.json"; exit 1; }
[ ! -e "$CURSOR_HOME/.gemini/config/hooks.json" ] || { echo "should not write ~/.gemini/config/hooks.json"; exit 1; }

# 2. Start step with CURSOR_CLOUD=true and SHELLTIME_TOKEN starts the daemon immediately
out=$(cat ./cloud.bash | env -u CLAUDE_CODE_REMOTE -u SHELLTIME_CLOUD HOME="$CURSOR_HOME" CURSOR_CLOUD=true SHELLTIME_TOKEN=st_v1_cursor_token bash 2>&1) || { echo "$out"; echo "cloud.bash exited non-zero"; exit 1; }
echo "$out"
echo "$out" | grep -q "ShellTime is installed; Cursor Cloud Agent sessions" || { echo "start step did not finish"; exit 1; }
grep -qx "token: st_v1_cursor_token" "$config" || { echo "expected cursor token"; cat "$config"; exit 1; }
for _ in 1 2 3 4 5; do pgrep -fx "$daemon" >/dev/null && [ -S /tmp/shelltime.sock ] && break; sleep 1; done
pgrep -fx "$daemon" >/dev/null || { echo "daemon not started"; cat "$CURSOR_HOME/.shelltime/logs/shelltime-daemon.log"; exit 1; }

# Re-running cloud-start.sh rotates token without starting a second daemon
SHELLTIME_TOKEN=st_v1_cursor_rotated HOME="$CURSOR_HOME" "$start_hook"
grep -qx "token: st_v1_cursor_rotated" "$config" || { echo "expected rotated cursor token"; cat "$config"; exit 1; }
[ "$(pgrep -fxc "$daemon")" = 1 ] || { echo "expected one daemon"; pgrep -fxa "$daemon"; exit 1; }
pkill -fx "$daemon"
rm -rf "$CURSOR_HOME"
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is the **shelltime installation** repository - a collection of shell script
## Repository Structure

- `install.bash` - Main installation script that downloads shelltime CLI binaries and sets up shell hooks
- `cloud.bash` - Setup for Claude Code cloud environments, run from an environment's setup script with `curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash`. Installs the Linux CLI and daemon into `~/.shelltime/bin`, runs `shelltime cc install`, and adds a Claude Code SessionStart hook (`~/.shelltime/bin/cloud-session-start.sh`, embedded in the script) that signs in and starts the daemon in each session. The token is a network secret of the environment (host `api.shelltime.xyz`, header `Authorization`, prefix `CLI`) that Anthropic's agent proxy adds to requests outside the VM, so the hook signs in with the placeholder `proxy-injected` (the CLI then sends no `Authorization` header; needs a CLI release with `model.ProxyInjectedToken`). `SHELLTIME_TOKEN` in the environment variables, for environments without network secrets, replaces the placeholder. Setup scripts get neither. It installs nothing unless `CLAUDE_CODE_REMOTE` is `true`, which cloud environments set (the setup script inherits it from `environment-manager`) and which is never true on a user's own machine. A setup script that exits non-zero stops sessions from starting, so it always exits 0 (its `EXIT` trap reports a failure instead), and nothing runs before the final `main` call, so a truncated download installs nothing. The guide that documents it is `content/blogs/track-claude-code-cloud-sessions/` in the web repo; keep the two in step
- `cloud.bash` - Setup for cloud agent environments (Claude Code cloud, Google Antigravity cloud, and Cursor Cloud Agents), run from an environment's setup/install script with `curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash`. Detects Claude Code cloud (`CLAUDE_CODE_REMOTE=true`), Antigravity cloud (OS user `antigravity`, including when setup runs as `root` on behalf of `antigravity`), Cursor Cloud Agents (`CURSOR_CLOUD=true`/`1`, `CURSOR_BACKGROUND_AGENT=true`/`1`), or an explicit `SHELLTIME_CLOUD=true` (matching `~/.cursor`/`.cursor/*`/`cursor-agent` vs `~/.gemini`/`.agents/hooks.json`/`agy`, or both in a fresh VM); outside those it installs nothing (ignoring `CURSOR_CODE_REMOTE` and `CURSOR_AGENT`, which local/SSH machines also set). Installs the Linux CLI and daemon into `$TARGET_HOME/.shelltime/bin` (and symlinks into `/usr/local/bin` when writable). For Claude Code cloud, runs `shelltime cc install` and adds a Claude Code SessionStart hook (`~/.shelltime/bin/cloud-session-start.sh`) that signs in with `proxy-injected` (or `SHELLTIME_TOKEN`) and starts the daemon in each session. For Antigravity and Cursor cloud, installs `~/.shelltime/bin/cloud-start.sh` (signs in when `SHELLTIME_TOKEN` is in the env, clears stale `/tmp/shelltime.sock`, starts `shelltime-daemon` with `SHELLTIME_CLOUD=true`) and saves `SHELLTIME_TOKEN` to `config.yaml` if present during setup. For Antigravity, also adds `~/.shelltime/bin/agy-cloud-session-start.sh` under the separate `"shelltime-cloud"` group in `~/.gemini/config/hooks.json` (so `.agents/hooks.json` never yields to it) and fixes ownership to `antigravity` when setup ran as `root`. For Cursor Cloud Agents (which ignore `~/.cursor/hooks.json`), also runs `cloud-start.sh` immediately when `SHELLTIME_TOKEN` is already set. A setup script that exits non-zero stops sessions from starting, so it always exits 0 (its `EXIT` trap reports a failure instead), and nothing runs before the final `main` call, so a truncated download installs nothing. The guides that document it are `content/blogs/track-claude-code-cloud-sessions/` and `content/blogs/track-cursor-and-antigravity/` in the web repo; keep them in step
- `hooks/` - Shell-specific hook scripts that track command execution. They are copies of the CLI's embedded hooks (`model/hooks/` in shelltime/cli, which `shelltime hooks install` and `shelltime init` write over these), so change both together:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (optional): the Testing section of this file still says "The test-cloud job checks that cloud.bash installs nothing without CLAUDE_CODE_REMOTE=true, then runs it twice ... SessionStart hook is registered exactly once ... signs in with proxy-injected". This PR adds Antigravity and Cursor steps to that job, and the refusal now covers more env vars. The Testing paragraph was not updated, so it no longer describes what the job verifies.

Fix: update the test-cloud paragraph to list the Antigravity and Cursor checks.

- `zsh.zsh` - Uses zsh's native `preexec` and `precmd` hooks
- `bash.bash` - Uses `bash-preexec` library for preexec/precmd functionality
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ You can install shelltime tools by running the following command in your termina
curl -sSL https://shelltime.xyz/i | bash
```

## Claude Code Cloud Environments
## Cloud Agent Environments (Claude Code, Google Antigravity & Cursor)

To track Claude Code sessions that run in the cloud ([claude.ai/code](https://claude.ai/code)), add this line to the cloud environment's setup script:
To track cloud sessions in **Claude Code** ([claude.ai/code](https://claude.ai/code)), **Google Antigravity** ([antigravity.google.com](https://antigravity.google.com)), or **Cursor Cloud Agents** ([cursor.com](https://cursor.com/docs/cloud-agent/setup)), add this line to the environment's setup/install script:

```bash
curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash
```

Then add your ShellTime API token to the environment as a network secret: allowed website `api.shelltime.xyz`, header `Authorization`, prefix `CLI`. Anthropic's agent proxy adds it to the daemon's requests outside the session's VM, so sessions never see the token, and the host needs no network access setting. [cloud.bash](cloud.bash) installs the CLI and daemon, connects Claude Code, and adds a SessionStart hook that signs in and starts the daemon in every session. An environment without network secrets can hold the token as `SHELLTIME_TOKEN` in its environment variables instead, with `api.shelltime.xyz` allowed by its network access; the hook uses it when it's set. It never fails the setup script, and outside a cloud environment (where `CLAUDE_CODE_REMOTE` isn't `true`) it installs nothing. The full guide: [Track your Claude Code cloud sessions](https://shelltime.xyz/blogs/track-claude-code-cloud-sessions).
- **Claude Code cloud (`CLAUDE_CODE_REMOTE=true`)**: Add your ShellTime API token to the environment as a network secret: allowed website `api.shelltime.xyz`, header `Authorization`, prefix `CLI`. Anthropic's agent proxy adds it to the daemon's requests outside the session's VM, so sessions never see the token, and the host needs no network access setting. [cloud.bash](cloud.bash) installs the CLI and daemon, connects Claude Code, and adds a SessionStart hook that signs in and starts the daemon in every session. An environment without network secrets can hold the token as `SHELLTIME_TOKEN` in its environment variables instead, with `api.shelltime.xyz` allowed by its network access; the hook uses it when it's set. Guide: [Track your Claude Code cloud sessions](https://shelltime.xyz/blogs/track-claude-code-cloud-sessions).
- **Google Antigravity cloud (OS user `antigravity`, or `SHELLTIME_CLOUD=true`)**: Commit `.agents/hooks.json` to your repository (`shelltime agy install`) and pass your ShellTime API token via `SHELLTIME_TOKEN` (exported in the setup script or set in the project's environment variables). [cloud.bash](cloud.bash) installs the CLI and daemon (automatically targeting the `antigravity` user when setup runs as `root`), saves `SHELLTIME_TOKEN` into `~/.shelltime/config.yaml` when present, and registers a SessionStart hook in `~/.gemini/config/hooks.json` (`shelltime-cloud`) that starts `shelltime-daemon` in every live session. Guide: [Track Cursor and Antigravity with ShellTime](https://shelltime.xyz/blogs/track-cursor-and-antigravity).
- **Cursor Cloud Agents (`CURSOR_CLOUD=true` / `CURSOR_BACKGROUND_AGENT=true`, or `SHELLTIME_CLOUD=true`)**: Commit `.cursor/hooks.json` to your repository (`shelltime cursor install`) and add `SHELLTIME_TOKEN` + `SHELLTIME_CLOUD=true` to the environment's secrets. Run `cloud.bash` in the install step and `~/.shelltime/bin/cloud-start.sh` in the start step (or run `cloud.bash` in the start step directly — when `SHELLTIME_TOKEN` is set, it signs in and starts `shelltime-daemon` immediately). Guide: [Track Cursor and Antigravity with ShellTime](https://shelltime.xyz/blogs/track-cursor-and-antigravity).

[cloud.bash](cloud.bash) never fails the setup script, and outside a cloud environment (no `CLAUDE_CODE_REMOTE=true`, no `antigravity` user, no `CURSOR_CLOUD`/`CURSOR_BACKGROUND_AGENT`, and no `SHELLTIME_CLOUD=true`) it installs nothing.

## What Next?

Expand Down
Loading
Loading