jackwener/OpenCLI · error · AuthRequiredError
Not logged into x.com (no ct0 cookie)
Error message
Not logged into x.com (no ct0 cookie)
What it means
Same guard as list-tweets but in the `twitter lists` command: enumerating your lists requires the ct0 CSRF cookie from an authenticated x.com session. If page.getCookies({url:'https://x.com'}) finds no ct0, the command throws AuthRequiredError immediately.
Source
Thrown at clis/twitter/lists.js:126
export const command = cli({
site: 'twitter',
name: 'lists',
access: 'read',
description: 'Get Twitter/X lists for the logged-in user (owned + subscribed)',
domain: 'x.com',
strategy: Strategy.COOKIE,
browser: true,
args: [
{ name: 'limit', type: 'int', default: 50, help: 'Maximum number of lists to return (default 50).' },
],
columns: ['id', 'name', 'members', 'followers', 'mode'],
func: async (page, kwargs) => {
const limit = kwargs.limit || 50;
const cookies = await page.getCookies({ url: 'https://x.com' });
const ct0 = cookies.find((c) => c.name === 'ct0')?.value || null;
if (!ct0)
throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');
// opencli >=1.7.x wraps primitive page.evaluate returns as { session, data: <value> }.
const unwrap = (v) => (v && typeof v === 'object' && 'session' in v && 'data' in v ? v.data : v);
const queryIdRaw = await page.evaluate(`async () => {
try {
const ghResp = await fetch('https://raw.githubusercontent.com/fa0311/twitter-openapi/refs/heads/main/src/config/placeholder.json');
if (ghResp.ok) {
const data = await ghResp.json();
const entry = data['${OPERATION_NAME}'];
if (entry && entry.queryId) return entry.queryId;
}
} catch {}
try {
const scripts = performance.getEntriesByType('resource')
.filter(r => r.name.includes('client-web') && r.name.endsWith('.js'))
.map(r => r.name);
for (const scriptUrl of scripts.slice(0, 15)) {
try {
const text = await (await fetch(scriptUrl)).text();View on GitHub (pinned to 49907e53dc)
Solutions
- Log into x.com in the controlled browser/profile, then re-run `opencli twitter lists`
- Check for both ct0 and auth_token cookies via page.getCookies({url:'https://x.com'})
- Use/point to the persistent profile that holds your X session
- Automate a pre-flight auth check before batches of twitter commands
Example fix
// before
const lists = await run('twitter', 'lists', {}); // AuthRequiredError if logged out
// after
const cookies = await page.getCookies({ url: 'https://x.com' });
const authed = cookies.some(c => c.name === 'ct0') && cookies.some(c => c.name === 'auth_token');
if (!authed) throw new Error('Not logged into x.com; log in first.');
const lists = await run('twitter', 'lists', {}); Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://x.com' });
if (!cookies.some(c => c.name === 'ct0')) throw new Error('Log into x.com before running `twitter lists`.'); Type guard
const hasCt0 = (cookies) => Array.isArray(cookies) && cookies.some(c => c.name === 'ct0' && c.value);
Try / catch
try {
const lists = await run('twitter', 'lists', { limit: 50 });
} catch (e) {
if (e.name === 'AuthRequiredError' || /no ct0 cookie/.test(e.message)) {
console.error('x.com session missing — log in with the automation profile, then retry.');
} else throw e;
} Prevention
- Keep one persistent, logged-in profile for all twitter commands
- Run `twitter lists` (a cheap read) as an auth probe before heavier flows
- Don't wipe cookies between commands
- Refresh login when auth_token/ct0 disappear
When it happens
Trigger: Running `twitter lists` with a logged-out browser profile, expired session, cleared cookies, or a profile where x.com cookies were never stored.
Common situations: Fresh automation profile never logged in; X invalidated the session server-side; a script clears cookies between runs; pointing at the wrong user-data-dir.
Related errors
- Bilibili ${label} API requires login or permission: ${messag
- Pinterest did not set a csrftoken cookie for this page
- Not logged into x.com (no ct0 cookie)
- Not logged into x.com (no ct0 cookie)
- Not logged into x.com (no ct0 cookie)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5017326ebd031311.
Report an issue: GitHub.