# How to Manually Configure Twitter Cookies Using auth_token and ct0 in Agent Reach

> Learn to manually configure Twitter cookies auth_token and ct0 in Agent Reach. Inject environment variables into config.yaml for seamless authentication with twitter-cli.

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

---

**Agent Reach stores Twitter authentication credentials in `~/.agent-reach/config.yaml` and validates them by injecting `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` environment variables into a subprocess that calls the `twitter-cli` tool.**

The open-source Agent Reach repository (`Panniantong/Agent-Reach`) provides a dedicated CLI command for manually configuring Twitter/X platform cookies without browser automation. This configuration enables the tool to authenticate API requests using static `auth_token` and `ct0` values extracted from your browser session.

## CLI Configuration Command Syntax

The entry point for manual cookie configuration is implemented in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) at lines 65-78. Use the following command structure:

```bash
agent-reach configure twitter-cookies [INPUT]

```

The `[INPUT]` argument accepts two distinct formats parsed by the `_parse_twitter_cookie_input` helper function (lines 24-41).

### Method 1: Space-Separated Token Values

Pass the `auth_token` and `ct0` values as separate space-delimited arguments:

```bash
agent-reach configure twitter-cookies abc123def456 ghi789jkl012

```

The CLI maps the first value to `auth_token` and the second to `ct0`.

### Method 2: Full Cookie Header String

Alternatively, supply a raw cookie header string containing semicolon-delimited key-value pairs:

```bash
agent-reach configure twitter-cookies "auth_token=abc123def456; ct0=ghi789jkl012; other=value"

```

The parser extracts only the `auth_token` and `ct0` fields, ignoring extraneous cookies.

## Configuration Storage and Persistence

When valid tokens are detected, the CLI invokes `Config.set` in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 79-84) to write the values to your local configuration file.

**Storage details:**
- **File location:** `~/.agent-reach/config.yaml`
- **YAML keys:** `twitter_auth_token` and `twitter_ct0`
- **Data format:** Plain text string values

Verify successful storage by inspecting the configuration file:

```bash
cat ~/.agent-reach/config.yaml

```

Expected output:

```yaml
twitter_auth_token: abc123def456
twitter_ct0: ghi789jkl012

```

## Runtime Environment Injection and Verification

After persisting the values to disk, the CLI performs an immediate validation check. As implemented in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 86-93), the process:

1. Creates a copy of the current environment
2. Sets `env["TWITTER_AUTH_TOKEN"]` and `env["TWITTER_CT0"]` to the extracted values
3. Spawns a subprocess executing `twitter status`
4. Checks the JSON output for `"ok": true`

If the subprocess returns a success indicator, the CLI prints **"✅ Twitter access works!"**; otherwise, it warns that the provided cookies may be invalid.

## Channel Integration and Environment Variable Access

The Twitter channel implementation in [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py) accesses these credentials through the same environment variable interface. The `_check_twitter_cli` method (lines 44-55) validates the `twitter-cli` binary by checking for the presence of `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` in the environment before executing read operations.

When you subsequently run commands like:

```bash
agent-reach read https://x.com/username/status/1234567890

```

The [`agent_reach/core.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/core.py) router dispatches to `TwitterChannel`, which spawns `twitter-cli` with the configured environment variables automatically injected.

## Legacy Bird CLI Support

For users of the legacy Bird CLI tool, Agent Reach includes compatibility helpers in [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) (specifically `_sync_bird_env`). While the manual `configure twitter-cookies` flow does not invoke this helper, you may manually export `AUTH_TOKEN` and `CT0` environment variables if using Bird instead of the modern `twitter-cli`.

## Summary

- **Command:** Use `agent-reach configure twitter-cookies` with either space-separated tokens or a full cookie header string.
- **Storage:** Credentials are saved to `~/.agent-reach/config.yaml` under the keys `twitter_auth_token` and `twitter_ct0` via the `Config.set` method.
- **Validation:** The CLI immediately tests cookies by spawning `twitter-cli` with `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` environment variables set.
- **Runtime:** [`agent_reach/channels/twitter.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py) references these environment variables for all subsequent Twitter operations.

## Frequently Asked Questions

### Where does Agent Reach store manually configured Twitter cookies?

Agent Reach persists the `auth_token` and `ct0` values to `~/.agent-reach/config.yaml`. The `Config` class in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) handles the YAML serialization, using the specific keys `twitter_auth_token` and `twitter_ct0` to identify the credentials.

### What input format should I use when configuring Twitter cookies manually?

The `_parse_twitter_cookie_input` function in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) accepts two formats: two space-separated strings (first is `auth_token`, second is `ct0`) or a single quoted string containing semicolon-separated cookie key-value pairs. Both methods extract only the required `auth_token` and `ct0` values.

### How does Agent Reach verify that the Twitter cookies are valid?

Immediately after storage, the CLI sets the `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` environment variables and spawns a `twitter status` subprocess. It inspects the command output for `"ok": true` to confirm successful authentication, displaying a success or warning message based on the result.

### Can I use these cookies with the legacy Bird CLI?

While the manual configuration flow targets the modern `twitter-cli`, you can manually export `AUTH_TOKEN` and `CT0` environment variables for Bird CLI compatibility. The [`agent_reach/cookie_extract.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cookie_extract.py) module contains the `_sync_bird_env` helper function for this legacy integration, though it is not automatically invoked during the standard configuration flow.