jackwener/OpenCLI · error · ArgumentError
id not a valid Grok session ID (got "${input}"); expected a
Error message
id not a valid Grok session ID (got "${input}"); expected a UUID like "7c4197f2-10a1-4ebb-a84a-fea89f4f1d06" or a full https://grok.com/c/<id> URL What it means
After URL normalization (or if the input was not URL-shaped at all), parseGrokSessionId validates the candidate against GROK_SESSION_ID_RE, which requires a lowercase-hex UUID. If neither a valid UUID nor a valid grok.com /c/<uuid> URL was supplied, this ArgumentError is thrown with an example UUID to guide you.
Source
Thrown at clis/grok/utils.js:60
try {
parsed = new URL(raw);
} catch {
throw new ArgumentError('id', `not a valid Grok URL (got "${input}")`);
}
const host = parsed.hostname.toLowerCase();
const pathMatch = parsed.pathname.match(
/^\/c\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/?$/i,
);
if (parsed.protocol !== 'https:' || (host !== 'grok.com' && !host.endsWith('.grok.com')) || !pathMatch) {
throw new ArgumentError(
'id',
`not a valid Grok conversation URL (got "${input}"); expected https://grok.com/c/<id>`,
);
}
candidate = pathMatch[1];
}
if (!GROK_SESSION_ID_RE.test(candidate)) {
throw new ArgumentError(
'id',
`not a valid Grok session ID (got "${input}"); expected a UUID like "7c4197f2-10a1-4ebb-a84a-fea89f4f1d06" or a full https://grok.com/c/<id> URL`,
);
}
return candidate.toLowerCase();
}
export async function isOnGrok(page) {
const url = await page.evaluate('window.location.href').catch(() => '');
if (typeof url !== 'string' || !url) return false;
try {
const hostname = new URL(url).hostname;
return hostname === 'grok.com' || hostname.endsWith('.grok.com');
} catch {
return false;
}
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Get the real session UUID from the Grok conversation URL (/c/<uuid>) and pass that.
- Verify the id is 36 characters with 4 hyphens and only hex digits (UUID v4 style), e.g. 7c4197f2-10a1-4ebb-a84a-fea89f4f1d06.
- If you have a full grok.com/c/ URL, pass it as-is — the parser extracts the UUID for you.
- Run the UUID through a quick regex check /^[0-9a-f]{8}-[0-9a-f]{4}-...$/ before calling.
Example fix
// before
const id = parseGrokSessionId('7c4197f210a14ebba84afea89f4f1d06'); // no dashes
// after
const id = parseGrokSessionId('7c4197f2-10a1-4ebb-a84a-fea89f4f1d06'); Defensive patterns
Strategy: validation
Validate before calling
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (!UUID_RE.test(input) && !isGrokConversationUrl(input)) {
throw new Error(`id must be a UUID or grok.com/c/ URL, got: ${input}`);
} Type guard
function isUuid(s) {
return typeof s === 'string' &&
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s);
} Try / catch
try {
const id = parseGrokSessionId(raw);
} catch (e) {
if (/not a valid Grok session ID/.test(e.message)) {
console.error(`'${raw}' is not a UUID. Example: 7c4197f2-10a1-4ebb-a84a-fea89f4f1d06`);
process.exitCode = 2;
} else throw e;
} Prevention
- Always source ids from the /c/<uuid> URL rather than typing them
- Validate UUID shape before calling
- Lowercase and trim inputs
- Store ids in config in UUID form only
When it happens
Trigger: Passing a non-UUID string like 'my-session', a UUID with wrong formatting (missing dashes, wrong length, non-hex characters), an empty string after trimming, or a URL branch that never produced a valid UUID.
Common situations: Users pasting a conversation title, a database row id, or a shortened link; typing the UUID by hand and dropping a character; using an uppercase-hex id from another system that fails the strict regex.
Related errors
- ${e.message} (rethrown from assertMessageIdShape; e.g. taskI
- ${e.message} (rethrown from assertMessageIdShape; e.g. taskI
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4de0934db81911dd.
Report an issue: GitHub.