How to Configure Twitter Cookies for Agent-Reach: Manual and Automatic Methods
Agent-Reach stores Twitter authentication credentials (auth_token and ct0) in ~/.agent-reach/config.yaml and supports both manual CLI input and automatic extraction from Chrome, Firefox, Edge, Brave, or Opera browsers.
Agent-Reach is an open-source automation framework maintained at Panniantong/Agent-Reach that integrates with Twitter through the TwitterChannel implementation. To enable Twitter functionality, you must configure Twitter cookies for Agent-Reach by providing the auth_token and ct0 values from an active browser session. According to the source code in agent_reach/config.py (lines 24-27), these credentials are persisted under the keys twitter_auth_token and twitter_ct0 in the configuration file.
Understanding the Required Authentication Cookies
The Twitter integration requires two specific cookies from an active Twitter/X session:
- auth_token: The primary session identifier that authenticates your account
- ct0: The CSRF token required for API call validation
The TwitterChannel implementation in agent_reach/channels/twitter.py (lines 59-67) uses these values to communicate with either the twitter-cli backend or the OpenCLI interface. Without both tokens, the channel cannot establish an authenticated connection.
Method 1: Manual Configuration via CLI
The fastest way to configure Twitter cookies for Agent-Reach is using the configure twitter-cookies command, which accepts multiple input formats.
Supported Input Formats
The CLI handler in agent_reach/cli.py (lines 54-73) implements _parse_twitter_cookie_input to handle two input styles. You can provide the cookies as a single header string or as separate space-separated values:
# Format 1: Cookie header style with semicolons
agent-reach configure twitter-cookies "auth_token=AAA; ct0=BBB"
# Format 2: Space-separated raw values
agent-reach configure twitter-cookies AAA BBB
The parser automatically detects which format you provided by checking for the presence of = characters and semicolons.
What Happens After Configuration
When you execute the configuration command, Agent-Reach performs the following steps:
- Parses the input using
_parse_twitter_cookie_inputinagent_reach/cli.py - Stores values via
config.set()calls totwitter_auth_tokenandtwitter_ct0inagent_reach/config.py - Exports environment variables
TWITTER_AUTH_TOKENandTWITTER_CT0for subprocess access - Runs a health check against the installed
twitter-clibinary to validate the credentials
Method 2: Automatic Extraction from Browser
For convenience, Agent-Reach can extract cookies directly from your browser's cookie store, eliminating the need to manually copy values from developer tools.
Supported Browsers
The configure_from_browser function in agent_reach/cli.py (lines 26-34) delegates to agent_reach/cookie_extract.py, which supports:
- Chrome
- Firefox
- Edge
- Brave
- Opera
Extraction Command
Run the following to automatically pull cookies from your logged-in browser session:
agent-reach configure --from-browser chrome
The extraction logic in agent_reach/cookie_extract.py (lines 14-22) scans the browser's SQLite cookie database for domains matching .x.com and .twitter.com, then filters for the auth_token and ct0 entries. The values are written back to the configuration via the setter calls in lines 50-58.
Synchronization with External Tools
The automatic extraction process also maintains compatibility with related tooling. According to agent_reach/cookie_extract.py:
- xfetch legacy support: Writes the cookie pair to
~/.config/xfetch/session.json(lines 76-84) - bird CLI support: Can generate a
credentials.envfile for the bird tool (lines 104-112) - Environment export: Sets
TWITTER_AUTH_TOKENandTWITTER_CT0for immediate use bytwitter-cli
Verifying Your Configuration
After you configure Twitter cookies for Agent-Reach, verify the setup before running automated tasks.
Using the Doctor Command
Run the built-in diagnostic tool:
agent-reach doctor
The health check in agent_reach/channels/twitter.py (lines 59-67) validates the stored credentials against available backends. A successful configuration shows "Twitter CLI 完整可用" (Twitter CLI fully available) or "OpenCLI 可用" (OpenCLI available) in the output report.
Manual Verification with twitter-cli
If you have twitter-cli installed, you can verify the cookies directly by exporting the environment variables that Agent-Reach uses:
export TWITTER_AUTH_TOKEN="your_auth_token"
export TWITTER_CT0="your_ct0"
twitter status
A response containing ok: true confirms that the extracted or manually entered cookies are valid and active.
Summary
- Agent-Reach requires
auth_tokenandct0cookies stored in~/.agent-reach/config.yamlunder the configuration keystwitter_auth_tokenandtwitter_ct0 - Manual configuration uses
agent-reach configure twitter-cookieswith support for both header-style and space-separated input formats, parsed by_parse_twitter_cookie_inputinagent_reach/cli.py - Automatic extraction uses
agent-reach configure --from-browser [chrome|firefox|edge|brave|opera], implemented inconfigure_from_browserandagent_reach/cookie_extract.py - Both methods automatically synchronize credentials to environment variables and maintain compatibility with legacy tools like xfetch and bird
- Verify your setup using
agent-reach doctoror by manually runningtwitter statuswith the exported environment variables
Frequently Asked Questions
Where does Agent-Reach store Twitter authentication data?
Agent-Reach persists Twitter cookies in the YAML configuration file located at ~/.agent-reach/config.yaml. The Config class in agent_reach/config.py (lines 24-27) handles reading and writing the twitter_auth_token and twitter_ct0 keys.
Which browsers are supported for automatic cookie extraction?
The automatic extraction feature in agent_reach/cookie_extract.py supports Chrome, Firefox, Edge, Brave, and Opera. The extraction logic scans each browser's specific cookie store location to find active sessions from .x.com or .twitter.com domains, then filters for the required auth_token and ct0 values.
Why does Agent-Reach need both auth_token and ct0 cookies?
The auth_token identifies your Twitter session to the API, while the ct0 token provides CSRF (Cross-Site Request Forgery) protection required by Twitter's internal endpoints. The TwitterChannel implementation in agent_reach/channels/twitter.py passes both values to the underlying twitter-cli or OpenCLI backends to make authenticated requests.
How do I troubleshoot if the Twitter channel shows as unavailable?
First, regenerate your cookies by logging into Twitter/X in your browser again, then re-run the configuration command. Ensure that twitter-cli is installed and available in your system PATH, or verify that the OpenCLI backend is properly configured. Run agent-reach doctor to view specific error messages from the health check logic in agent_reach/channels/twitter.py (lines 59-67), which will indicate whether the issue is with credential validity or backend availability.
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 →