How to Manually Configure Twitter Cookies Using auth_token and ct0 in Agent Reach
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 at lines 65-78. Use the following command structure:
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:
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:
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 (lines 79-84) to write the values to your local configuration file.
Storage details:
- File location:
~/.agent-reach/config.yaml - YAML keys:
twitter_auth_tokenandtwitter_ct0 - Data format: Plain text string values
Verify successful storage by inspecting the configuration file:
cat ~/.agent-reach/config.yaml
Expected output:
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 (lines 86-93), the process:
- Creates a copy of the current environment
- Sets
env["TWITTER_AUTH_TOKEN"]andenv["TWITTER_CT0"]to the extracted values - Spawns a subprocess executing
twitter status - 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 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:
agent-reach read https://x.com/username/status/1234567890
The 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 (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-cookieswith either space-separated tokens or a full cookie header string. - Storage: Credentials are saved to
~/.agent-reach/config.yamlunder the keystwitter_auth_tokenandtwitter_ct0via theConfig.setmethod. - Validation: The CLI immediately tests cookies by spawning
twitter-cliwithTWITTER_AUTH_TOKENandTWITTER_CT0environment variables set. - Runtime:
agent_reach/channels/twitter.pyreferences 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 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 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 module contains the _sync_bird_env helper function for this legacy integration, though it is not automatically invoked during the standard configuration flow.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →