# How to Manually Configure Twitter Cookies (auth_token, ct0) for Agent-Reach

> Learn to manually configure Twitter cookies auth_token and ct0 for Agent-Reach. Follow our simple guide to store them securely in your config file and ensure smooth operation.

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

---

**Manually configure Twitter cookies for Agent-Reach by running `agent-reach configure twitter-cookies "auth_token=AAA; ct0=BBB"`, which parses the input in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) and stores the values in `~/.agent-reach/config.yaml` under the keys `twitter_auth_token` and `twitter_ct0`.**

Agent-Reach is an open-source automation framework that requires valid Twitter session cookies to power its **TwitterChannel** implementation. The application reads `auth_token` and `ct0` from a local YAML configuration file (managed by [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py)) to authenticate calls to the `twitter-cli` or OpenCLI backend. You can supply these credentials either manually via the CLI or automatically from a logged-in browser.

## Configuration Storage and Key Names

Agent-Reach persists authentication data in `~/.agent-reach/config.yaml`. The **TwitterChannel** ([`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py)) expects two specific keys:

- `twitter_auth_token`: Maps to your Twitter `auth_token` cookie
- `twitter_ct0`: Maps to your Twitter `ct0` cookie

These values are written via `config.set()` calls defined in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 24-27) and retrieved during channel initialization to validate API access.

## Method 1: Manual CLI Configuration

The `configure twitter-cookies` command accepts your session cookies in two interchangeable formats, parsed by `_parse_twitter_cookie_input` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 54-73).

### Semicolon-Delimited Format

Provide the cookies as a single string matching the HTTP Cookie header format:

```bash
agent-reach configure twitter-cookies "auth_token=AAA; ct0=BBB"

```

The CLI splits the string on semicolons and spaces, extracts the key-value pairs, and persists them to your local config.

### Space-Separated Token Format

Alternatively, pass the raw token values as two separate arguments:

```bash
agent-reach configure twitter-cookies AAA BBB

```

This format is detected when the input contains no `=` characters and splits into exactly two components. After parsing, the command runs a health-check against `twitter-cli` to verify the credentials before saving.

## Method 2: Automatic Browser Extraction

If you are logged into Twitter/X in a supported browser, Agent-Reach can extract the cookies automatically without manual copy-pasting:

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

```

Supported browsers include Chrome, Firefox, Edge, Brave, and Opera. The handler `_cmd_configure` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 26-34) delegates to `configure_from_browser` in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (lines 14-22), which scans the browser’s SQLite cookie store for domains `.x.com` and `.twitter.com`. Valid cookies are written to the config via the setter methods (lines 50-58) and immediately synchronized to downstream tools.

## Downstream Credential Synchronization

Whether you configure manually or via browser extraction, Agent-Reach propagates the credentials to multiple consumers:

- **Environment Variables**: Temporarily exports `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` during the health-check phase
- **xfetch Legacy**: Writes the pair to `~/.config/xfetch/session.json` (handled in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), lines 76-84)
- **bird CLI**: Optionally generates a `credentials.env` file for the bird tool (lines 104-112)

## Verifying Twitter Authentication

After configuration, confirm the setup using the diagnostic command:

```bash
agent-reach doctor

```

Check the Twitter section in the output. A successful configuration displays **"Twitter CLI 完整可用"** or **"OpenCLI 可用"**, as implemented in [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py) (lines 59-67).

For manual verification, export the environment variables and query your status:

```bash
export TWITTER_AUTH_TOKEN=AAA
export TWITTER_CT0=BBB
twitter status

```

A JSON response containing `ok: true` confirms the session is valid.

## Technical Deep Dive: Cookie Parsing Implementation

The internal parsing logic in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) handles multiple input patterns robustly:

```python
def _parse_twitter_cookie_input(value: str):
    auth_token = ct0 = None
    if "auth_token=" in value and "ct0=" in value:
        for part in value.replace(";", " ").split():
            if part.startswith("auth_token="):
                auth_token = part.split("=", 1)[1]
            elif part.startswith("ct0="):
                ct0 = part.split("=", 1)[1]
    elif len(value.split()) == 2 and "=" not in value:
        auth_token, ct0 = value.split()
    return auth_token, ct0

```

This implementation supports both DevTools-style cookie headers and raw token strings, ensuring flexibility regardless of your copy source.

## Summary

- **Storage Location**: Twitter cookies reside in `~/.agent-reach/config.yaml` under `twitter_auth_token` and `twitter_ct0`
- **Manual Entry**: Use `agent-reach configure twitter-cookies` with either `"auth_token=X; ct0=Y"` or two space-separated values
- **Auto-Extraction**: The `--from-browser` flag supports chrome, firefox, edge, brave, and opera for automated retrieval
- **Validation**: Run `agent-reach doctor` to confirm the Twitter channel reports an "ok" status
- **Propagation**: Credentials automatically sync to environment variables, xfetch legacy paths, and optional bird CLI configurations

## Frequently Asked Questions

### Where does Agent-Reach store the Twitter auth_token and ct0 cookies?

Agent-Reach writes the cookie values to `~/.agent-reach/config.yaml` using the keys `twitter_auth_token` and `twitter_ct0`. This file is read by the TwitterChannel implementation in [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py) when initializing connections to the Twitter backend.

### Can I configure Twitter cookies without using the browser extraction feature?

Yes. If you have copied the values from browser DevTools, run `agent-reach configure twitter-cookies "auth_token=YOUR_TOKEN; ct0=YOUR_CT0"` to store them directly. The CLI parser in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) handles both semicolon-delimited strings and space-separated raw values.

### What happens if the Twitter cookies are invalid or expired?

During the configuration process, Agent-Reach executes a health-check against `twitter-cli`. If authentication fails, the CLI reports the error and aborts the configuration update, preventing invalid credentials from being saved to `~/.agent-reach/config.yaml`.

### Does Agent-Reach support cookie extraction from browsers other than Chrome?

Yes. The `--from-browser` flag supports Chrome, Firefox, Edge, Brave, and Opera. The extraction logic in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) reads each browser’s specific cookie store format and filters for Twitter/X domain cookies to retrieve the required `auth_token` and `ct0` values.