# How the Agent-Reach Configure Command Extracts Cookies from Browsers Automatically

> Discover how the Agent-Reach configure command automatically extracts browser cookies using rookiepy or browser_cookie3, filtering them for seamless integration into your configuration.

- Repository: [Pnant/Agent-Reach](https://github.com/Panniantong/Agent-Reach)
- Tags: how-to-guide
- Published: 2026-06-06

---

**The `agent-reach configure --from-browser` sub-command calls `configure_from_browser`, which reads local browser cookie stores via `rookiepy` or `browser_cookie3`, filters the results against platform-specific rules in `PLATFORM_SPECS`, and persists the extracted values to `~/.agent-reach/config.yaml` without manual copying.**

The open-source `Panniantong/Agent-Reach` repository automates social-media agent authentication by enabling users to import session cookies directly from their desktop browsers. Understanding how the configure command extracts cookies from browsers automatically shows why the tool can bootstrap Twitter, XiaoHongShu, Bilibili, and Xueqiu channels with zero manual token entry.

## How the Configure Command Automatically Extracts Browser Cookies

### CLI Parsing and Dispatch in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py)

When you run `agent-reach configure --from-browser chrome`, the CLI handler `_cmd_configure` parses the flag and forwards the browser name to [configure_from_browser](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). The relevant dispatch logic resides in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) around lines [78–86](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py#L78-L86) and [1017–1044](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py#L1017-L1044). The handler instantiates a `Config` object that points to the user’s local YAML configuration file before invoking the extractor.

### Browser Cookie Extraction via `extract_all`

The core extraction happens in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) inside `extract_all`. This helper first attempts to import the Rust-based `rookiepy` library for high-performance cookie reading. If that module is unavailable, it falls back to the pure-Python `browser_cookie3` package. Either backend returns the full cookie jar from the selected browser profile, which `extract_all` then scans linearly. This fallback chain is implemented around lines [55–69](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py#L55-L69) of [agent_reach/cookie_extract.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py).

### Platform Specification Matching

Before scanning, `extract_all` loads `PLATFORM_SPECS`, a table defined near lines [15–41](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py#L15-L41) of [agent_reach/cookie_extract.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). Each entry declares a target platform—Twitter/X, XiaoHongShu, Bilibili, or Xueqiu—along with the required cookie domains and specific cookie names. As the iterator walks the browser cookie jar, it compares every cookie’s domain against these specs. For Twitter, it isolates `auth_token` and `ct0`; for XiaoHongShu, it assembles the full header-style cookie string. The matching loop appears around lines [122–148](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py#L122-L148) of [agent_reach/cookie_extract.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py).

### Persisting Extracted Cookies to the Config Store

Once `extract_all` returns a dictionary of platform credentials, `configure_from_browser` updates the in-memory `Config` instance. Twitter tokens are stored individually via `config.set`; XiaoHongShu receives the bundled cookie string as `xhs_cookie`; Bilibili gets `SESSDATA` and optionally `bili_jct`; Xueqiu is written only if `xq_a_token` is present. The method returns a list of `(platform, success, message)` tuples so the CLI can print human-readable results. This persistence logic spans roughly lines [202–267](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py#L202-L267) of [agent_reach/cookie_extract.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). After the call returns, `_cmd_configure` flushes the YAML file, completing the automatic extraction pipeline.

## Supported Platforms and Required Cookies

- **Twitter/X** – requires `auth_token` and `ct0` for Bearer session negotiation.
- **XiaoHongShu** – requires the full cookie header string for the domain.
- **Bilibili** – requires `SESSDATA` for API authentication and optionally `bili_jct` for write operations.
- **Xueqiu** – requires the full cookie string but only if `xq_a_token` is detected.

## Code Examples

**Auto-extract from the terminal**

```bash
agent-reach configure --from-browser chrome

```

**Programmatic extraction in Python**

```python
from agent_reach.cookie_extract import configure_from_browser
from agent_reach.config import Config

cfg = Config()  # loads ~/.agent-reach/config.yaml

results = configure_from_browser("chrome", cfg)

for platform, ok, msg in results:
    status = "✅" if ok else "❌"
    print(f"{platform}: {status} {msg}")

```

**Typical dictionary returned by `extract_all`**

```python
{
    "twitter": {"auth_token": "abc123", "ct0": "def456"},
    "xhs": {"cookie_string": "a=1; b=2; ..."},
    "bilibili": {"SESSDATA": "xyz", "bili_jct": "pqr"},
}

```

## Key Source Files

- [agent_reach/cookie_extract.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) – houses `PLATFORM_SPECS`, `extract_all`, and `configure_from_browser`.
- [agent_reach/cli.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) – defines the `configure` sub-command, flag parsing, and the `_cmd_configure` handler.
- [agent_reach/config.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) – lightweight YAML wrapper where extracted cookies are permanently stored.

## Summary

- The `configure --from-browser` flag triggers `_cmd_configure` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py), which delegates to `configure_from_browser`.
- `extract_all` attempts `rookiepy` and falls back to `browser_cookie3` to read the raw browser cookie jar.
- Cookies are filtered against `PLATFORM_SPECS` to isolate domain-specific credentials for Twitter, XiaoHongShu, Bilibili, and Xueqiu.
- Valid tokens are written immediately to `~/.agent-reach/config.yaml` via the `Config` class, eliminating manual copy-pasting.

## Frequently Asked Questions

### Which browsers does the configure command support for automatic cookie extraction?

The exact set depends on the underlying backends. Because `extract_all` tries `rookiepy` first and falls back to `browser_cookie3`, any browser profile accessible to those libraries—commonly Chrome, Edge, Firefox, and Safari—can be targeted by passing the appropriate name to `--from-browser`.

### Do I need to install rookiepy separately for the configure command to work?

No. The code around lines 55–69 of [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) wraps the import in a try/except block. If `rookiepy` is missing, the module automatically falls back to `browser_cookie3`, so extraction still succeeds as long as one of the two packages is present in your environment.

### How does the tool know which cookies belong to Twitter or XiaoHongShu?

`extract_all` references the `PLATFORM_SPECS` table defined near lines 15–41 of [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py). This table maps platform names to their respective domains and required cookie keys, allowing the scanner to distinguish `auth_token` for Twitter from `SESSDATA` for Bilibili without user intervention.

### Is the extracted cookie data stored securely?

The cookies are persisted as plain text in the user’s local `~/.agent-reach/config.yaml` file through the `Config` class in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py). The tool itself does not encrypt the file, so you should ensure that your home directory permissions restrict access to the configuration.