How to Manually Configure Twitter Cookies Without Browser Extraction in Agent-Reach

You can manually configure Twitter authentication in Agent-Reach by providing the auth_token and ct0 cookies via the CLI command agent-reach configure twitter-cookies or by setting the TWITTER_AUTH_TOKEN and TWITTER_CT0 environment variables directly.

Agent-Reach interfaces with Twitter/X through the twitter-cli tool (or its OpenCLI/bird CLI fallback), which requires two specific cookies to authenticate requests. According to the Panniantong/Agent-Reach source code, you can supply these credentials directly without extracting them from a browser session, enabling headless or automated deployments.

The Twitter integration relies on two essential cookies: auth_token and ct0. These values authenticate your requests to Twitter's API when using the underlying twitter-cli binary. The library stores these credentials in your user configuration file and injects them into the environment whenever spawning the Twitter CLI process.

Unlike browser-based authentication flows, Agent-Reach does not require you to export cookies from Chrome, Firefox, or Edge. Instead, you provide the raw cookie values directly through command-line arguments or environment variables.

Configuring Cookies via the Agent-Reach CLI

The primary method for manual configuration uses the configure twitter-cookies command. The parsing logic for this command resides in the _parse_twitter_cookie_input function within [agent_reach/cli.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py#L32-L49).

Method 1: Separate Arguments

Pass the two cookie values as distinct arguments to the CLI:

agent-reach configure twitter-cookies AUTH_TOKEN_VALUE CT0_VALUE

This format stores the first argument as the authentication token and the second as the CSRF token (ct0).

Alternatively, provide a complete cookie header string exactly as it appears in HTTP requests:

agent-reach configure twitter-cookies "auth_token=AUTH_TOKEN_VALUE; ct0=CT0_VALUE"

Both methods persist the values to your Agent-Reach configuration file and print a confirmation message upon success.

Alternative: Direct Environment Variable Configuration

If you prefer not to use the Agent-Reach CLI configuration command, you can export the variables directly in your shell. The underlying twitter-cli expects TWITTER_AUTH_TOKEN and TWITTER_CT0, which Agent-Reach also reads and passes to child processes.

In [agent_reach/cli.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py#L1070-L1078), the _configure_twitter_cookies block handles the injection of these variables into the subprocess environment before executing Twitter operations.

Set the variables manually as follows:

export TWITTER_AUTH_TOKEN="YOUR_AUTH_TOKEN"
export TWITTER_CT0="YOUR_CT0"

When Agent-Reach spawns the twitter-cli process, it automatically inherits these environment variables, allowing immediate authentication without modifying the Agent-Reach config file.

Verifying Your Configuration

To confirm that your cookies are valid and properly recognized, run the health check:

agent-reach doctor

This command invokes the validation logic in TwitterChannel._check_twitter_cli within [agent_reach/channels/twitter.py](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/twitter.py). A successful configuration displays ✅ Twitter‑CLI 完整可用, indicating that both cookies are present and the CLI can authenticate with Twitter's servers.

If the cookies are missing or invalid, the health check reports the specific environment variables it expects and warns you to configure them using the methods described above.

Summary

  • Agent-Reach requires two cookies—auth_token and ct0—to authenticate with Twitter via twitter-cli.
  • Use agent-reach configure twitter-cookies to store credentials permanently, accepting either separate values or a full cookie header string.
  • The parsing logic resides in _parse_twitter_cookie_input in agent_reach/cli.py (lines 32-49).
  • For temporary or script-based usage, export TWITTER_AUTH_TOKEN and TWITTER_CT0 environment variables directly.
  • Runtime injection occurs in _configure_twitter_cookies in agent_reach/cli.py (lines 1070-1078).
  • Verify functionality with agent-reach doctor, which leverages TwitterChannel._check_twitter_cli in agent_reach/channels/twitter.py.

Frequently Asked Questions

Agent-Reach and the underlying twitter-cli expect TWITTER_AUTH_TOKEN and TWITTER_CT0. These names are hardcoded in the environment injection logic at lines 1070-1078 of agent_reach/cli.py, where the _configure_twitter_cookies function prepares the subprocess environment.

Can I use cookies extracted from my browser's developer tools?

Yes. While the method described here avoids browser extraction, you can manually copy the auth_token and ct0 values from your browser's developer tools (Network tab or Application/Storage tab) and paste them into the agent-reach configure twitter-cookies command. The CLI accepts the raw string format auth_token=xxx; ct0=yyy directly.

How does Agent-Reach pass cookies to the underlying Twitter CLI?

When executing Twitter operations, Agent-Reach reads the stored configuration and injects the values into the environment variables TWITTER_AUTH_TOKEN and TWITTER_CT0 before spawning the twitter-cli child process. This implementation in _configure_twitter_cookies ensures the CLI receives authentication credentials without requiring a browser-based login flow.

What happens if the cookies are invalid or expired?

The TwitterChannel._check_twitter_cli method in agent_reach/channels/twitter.py (lines 84-89) validates the presence of required variables during the health check. If cookies are missing, you receive a warning message indicating which variables are required. If the cookies are present but invalid (expired or revoked), the underlying twitter-cli will fail to authenticate, and you must obtain fresh auth_token and ct0 values from Twitter and re-run the configuration command.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →