---
name: drive-my-chrome
description: Use when browser automation must be signed in as the user — phrases like "use my chrome", "logged in as me", "browse as myself", or any site behind a login or SSO the user already holds. Drives real Google Chrome, headless, on a dedicated profile the user has signed in to. Reach for it instead of a plain `agent-browser open` whenever the task implies the user's own session.
---

# drive-my-chrome

Drive **real Google Chrome**, already signed in as the user, with agent-browser.
Headless, no prompts, and safe for several agents at once.

## How it works

- Agents get their own Chrome profile folder, `~/.agent-browser/agent-chrome`.
  The user signs in there once per site. It is separate from the user's
  everyday Chrome, which is never touched.
- The `agent-chrome` script next to this file starts real Chrome on that folder
  with a debugging port. agent-browser attaches to it with `--cdp`.
- Chrome is always started by `agent-chrome`, never by agent-browser. Chrome
  encrypts cookies with a key from the system keychain, and agent-browser
  launches Chrome with a stand-in key, which makes Chrome discard the saved
  sign-ins.

## The recipe

### 1. Start Chrome and open your own tab

```bash
PORT=$(~/.claude/skills/drive-my-chrome/agent-chrome start) || exit 1

AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab tab new "https://example.com/"
AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab get title
```

- `start` is safe to repeat. It starts Chrome if needed and prints the port.
- Put the session name, `--cdp "$PORT"` and `--pin-tab` on **every** command.
  `--pin-tab` keeps the session on the tab it opened.
- Begin with `tab new`. Each agent uses its own session name and its own tab,
  so several can share this Chrome at the same time. `tab list` shows every
  agent's tabs; touch only your own.
- For screenshots, set the size once after `tab new`: `set viewport 1440 1600`.

### 2. Check that you are signed in

Look at the page title, the address, or the account name in a snapshot before
relying on the session. A sign-in page means the profile has no session for
that site yet.

### 3. On a sign-in page, stop and ask

Never type credentials, and never go looking for a password. Open a visible
window on the same profile and ask the user to sign in:

```bash
~/.claude/skills/drive-my-chrome/agent-chrome login "https://example.com/"
```

Ask the user to:

1. Sign in on that page.
2. Choose **Use Chrome Without an Account** if Chrome offers to sign the
   browser itself in.
3. Quit that window when done.

Then run `agent-chrome start` again and reopen your tab.

`login` stops the headless Chrome first, which disconnects any other agent
using it, so run it only when nothing else is in progress.

### 4. Clean up

```bash
AGENT_BROWSER_SESSION=my-task agent-browser --cdp "$PORT" --pin-tab tab close
AGENT_BROWSER_SESSION=my-task agent-browser close
```

- Close the tab you opened, then disconnect. Chrome keeps running for other
  agents.
- Use plain `close`. `agent-browser close --all` ends every agent-browser
  session on the machine.
- `agent-chrome stop` shuts Chrome down when nothing else needs it.

## The script

| Command | What it does |
|---|---|
| `agent-chrome start` | Starts headless Chrome if it is not running, and prints the port |
| `agent-chrome status` | Says whether Chrome is running, and whether headless or visible |
| `agent-chrome stop` | Stops it |
| `agent-chrome login [url...]` | Stops it, then opens a visible window for signing in |

`AGENT_CHROME_DIR` changes the profile folder and `AGENT_CHROME_PORT` the port
(9333 by default).

## Good to know

- **Sign-ins are per site and they expire.** A site the user is signed in to in
  their everyday Chrome is not signed in here until they do step 3 for it, and
  each site ends its sessions on its own schedule.
- **One Chrome per profile folder.** While the visible `login` window is open,
  `start` refuses to run, and the other way round.
- **Sign-in is always done by the user, in the `login` window.** Identity
  providers often refuse a browser that is being automated.
- **Start with the flags.** If a session was first used without `--cdp`, close
  that session and begin again with the flags on the first command.
