jackwener/OpenCLI · error · ArgumentError
id not a valid Grok URL (got "${input}")
Error message
id not a valid Grok URL (got "${input}") What it means
parseGrokSessionId accepts either a bare UUID session id or a full https://grok.com/c/<uuid> URL. When the input looks like a URL (matches a scheme prefix like https:// or http://) but cannot be parsed by the URL constructor at all, the function throws this ArgumentError naming the 'id' argument. This is the earliest of three validation failures in the same parser.
Source
Thrown at clis/grok/utils.js:45
const normalized = String(value).trim().toLowerCase();
return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';
}
// UUID v4-shape: 8-4-4-4-12 hex with dashes (the format Grok uses for /c/<id>)
const GROK_SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
export function parseGrokSessionId(input) {
const raw = String(input ?? '').trim();
if (!raw) {
throw new ArgumentError('id', 'must be a non-empty session ID or grok.com chat URL');
}
let candidate = raw;
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) {
let parsed;
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`,
);View on GitHub (pinned to 49907e53dc)
Solutions
- Check the id string: if it is a full URL, ensure it is a well-formed absolute URL that new URL() can parse (valid scheme like https://, no stray characters).
- Prefer passing just the UUID session id (e.g. 7c4197f2-10a1-4ebb-a84a-fea89f4f1d06) instead of a URL — that path skips URL parsing entirely.
- Quote the URL in your shell so special characters are not mangled.
- Validate with a try { new URL(input) } before calling.
Example fix
// before node cli.js grok delete 'https:/grok.com/c/7c4197f2-10a1-4ebb-a84a-fea89f4f1d06' // after node cli.js grok delete 'https://grok.com/c/7c4197f2-10a1-4ebb-a84a-fea89f4f1d06' // or simply node cli.js grok delete 7c4197f2-10a1-4ebb-a84a-fea89f4f1d06
Defensive patterns
Strategy: validation
Validate before calling
function looksLikeUrl(s) { return /^[a-z][a-z0-9+.-]*:\/\//i.test(s); }
function isParseableUrl(s) { try { new URL(s); return true; } catch { return false; } }
if (looksLikeUrl(id) && !isParseableUrl(id)) throw new Error(`malformed URL: ${id}`); Type guard
function isUsableGrokId(input) {
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(input)) return /^[0-9a-f-]{36}$/i.test(input);
try { new URL(input); return true; } catch { return false; }
} Try / catch
try {
const id = parseGrokSessionId(raw);
} catch (e) {
if (e instanceof ArgumentError && /not a valid Grok URL/.test(e.message)) {
console.error(`Fix the id URL syntax: ${raw}`);
} else throw e;
} Prevention
- Pass the bare UUID instead of a URL whenever possible
- Quote URLs in shell to avoid character mangling
- Validate with new URL(input) before invoking
- Trim the input of stray whitespace/newlines
When it happens
Trigger: Calling any grok CLI command that takes an id (delete id, detail sessionId, pin) with a malformed URL string such as 'https://grok.com/c/%zz' with invalid percent-encoding, or a truncated scheme like 'https:/grok.com/c/...' that makes new URL() throw.
Common situations: Pasting a URL from the browser and accidentally dropping a slash or adding shell-escaped characters; template string interpolation producing 'http://\example'; shell mangling of '#' or '%' characters in the URL.
Related errors
- --url must be a Discord channel URL like https://discord.com
- --url must be a Discord thread/post URL like https://discord
- Invalid Instagram URL: ${raw}
- job-id must be a Midjourney UUID or https://www.midjourney.c
- ${label} Midjourney job URL index must be 0..3: ${item}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/84dc2f47d25501e9.
Report an issue: GitHub.