# How to Configure Twitter Cookies for Authentication in Agent-Reach

> Learn how to configure Twitter cookies for authentication in Agent-Reach. Store auth tokens manually or extract them automatically from your browser for seamless access.

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

---

**Agent-Reach stores Twitter authentication cookies (`auth_token` and `ct0`) in `~/.agent-reach/config.yaml`, supporting both manual CLI entry and automatic extraction from Chrome, Firefox, Edge, Brave, or Opera.**

To interact with Twitter/X through Agent-Reach, you must configure Twitter cookies for authentication. The **TwitterChannel** implementation in the Panniantong/Agent-Reach repository requires these credentials to authenticate API calls via `twitter-cli` or the OpenCLI backend. This guide demonstrates how to supply these cookies using either manual configuration or automatic browser extraction.

## Manual Configuration of Twitter Cookies

The `agent-reach configure twitter-cookies` command accepts authentication data in two formats. The CLI parses your input through `_parse_twitter_cookie_input` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 54-73) and persists the values via `config.set()` in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 24-27).

### Using the Cookie Header Format

Pass the full cookie string as a single quoted argument:

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

```

The parser splits on semicolons and spaces to extract the `auth_token` and `ct0` values.

### Using Space-Separated Values

Alternatively, provide the two token values separated by a space:

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

```

This format works when the input contains exactly two whitespace-separated values without `=` characters. Both methods trigger a health check against `twitter-cli` to confirm the credentials work before saving.

## Automatic Extraction of Twitter Cookies from Browser

Agent-Reach can extract cookies directly from your browser's cookie store, eliminating manual copy-pasting errors.

### Supported Browsers

The tool supports automatic extraction from:

- Chrome
- Firefox
- Edge
- Brave
- Opera

### Running the Extraction Command

Execute the following, replacing `chrome` with your browser:

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

```

This delegates to `configure_from_browser` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 26-34). The `extract_all` function in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (lines 14-22) scans the browser's SQLite cookie database, filters for domains matching `.x.com` and `.twitter.com`, and returns the `auth_token` and `ct0` cookies.

The values are written to your configuration via `config.set("twitter_auth_token", ...)` and `config.set("twitter_ct0", ...)` as implemented in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (lines 50-58).

## How Credentials Are Stored and Used

Understanding the storage mechanism ensures you can verify and troubleshoot your configuration.

### Configuration File Structure

Both manual and automatic methods store credentials in `~/.agent-reach/config.yaml` under the keys:

- `twitter_auth_token`
- `twitter_ct0`

### Downstream Tool Integration

Agent-Reach synchronizes these credentials for compatibility with multiple tools:

1. **Environment Variables**: Sets `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` for `twitter-cli` consumption during health checks.
2. **Legacy xfetch**: Writes to `~/.config/xfetch/session.json` via `_sync_xfetch_session` in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (lines 76-84).
3. **bird CLI**: Generates a `credentials.env` file for the bird tool as implemented in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (lines 104-112).

## Verification Steps

Confirm your configuration works before running automation tasks.

### Using the Built-in Doctor

Run the diagnostic command:

```bash
agent-reach doctor

```

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

### Manual Verification

If you have `twitter-cli` installed, export the environment variables and test:

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

```

Valid cookies return `ok: true` in the output.

## Summary

- **Manual configuration** uses `agent-reach configure twitter-cookies` with either a full cookie header or space-separated tokens, parsed by `_parse_twitter_cookie_input` in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py).
- **Automatic extraction** uses `agent-reach configure --from-browser <browser>` to scan Chrome, Firefox, Edge, Brave, or Opera cookie stores via [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py).
- **Storage location** is `~/.agent-reach/config.yaml` under `twitter_auth_token` and `twitter_ct0`.
- **Verification** requires running `agent-reach doctor` to check the Twitter channel status in [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py).
- **Downstream sync** includes environment variables, xfetch session files, and bird CLI credentials.

## Frequently Asked Questions

### Where does Agent-Reach store the Twitter authentication cookies?

Agent-Reach persists the `auth_token` and `ct0` values in `~/.agent-reach/config.yaml` under the keys `twitter_auth_token` and `twitter_ct0`. This file is managed by the configuration module in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 24-27).

### Can I use Firefox or Brave instead of Chrome for automatic extraction?

Yes. The `configure_from_browser` function in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 26-34) supports Chrome, Firefox, Edge, Brave, and Opera. Pass the browser name as an argument: `agent-reach configure --from-browser firefox` or `agent-reach configure --from-browser brave`.

### Why does my configuration show as invalid in `agent-reach doctor`?

The Twitter channel verification in [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py) (lines 59-67) checks both `twitter-cli` and OpenCLI backends. If cookies are expired or malformed, the health check fails. Re-run `agent-reach configure twitter-cookies` with fresh values extracted from a currently logged-in browser session.

### Does Agent-Reach share these credentials with other tools?

Yes. According to [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py), the tool synchronizes credentials to three locations: `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` environment variables for `twitter-cli`, `~/.config/xfetch/session.json` for legacy xfetch compatibility, and a generated `credentials.env` file for the bird CLI.