{"record":{"id":"38488b30e5f421fe","repo":"google-gemini/gemini-cli","slug":"invalid-session-id-trimmed-only-alphanumeric","errorCode":null,"errorMessage":"Invalid session ID \"${trimmed}\": Only alphanumeric characters, dashes, and underscores are allowed.","messagePattern":"Invalid session ID \"(.+?)\": Only alphanumeric characters, dashes, and underscores are allowed\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/config/config.ts","lineNumber":435,"sourceCode":"            return trimmed;\n          },\n        })\n        .option('session-file', {\n          type: 'string',\n          nargs: 1,\n          description: 'Load a session from a JSON file',\n        })\n        .option('session-id', {\n          type: 'string',\n          nargs: 1,\n          description: 'Start a new session with a manually provided UUID.',\n          coerce: (value: string): string => {\n            const trimmed = value.trim();\n            if (!trimmed) {\n              throw new Error('The --session-id option cannot be empty.');\n            }\n            if (!/^[a-zA-Z0-9-_]+$/.test(trimmed)) {\n              throw new Error(\n                'Invalid session ID \"' +\n                  trimmed +\n                  '\": Only alphanumeric characters, dashes, and underscores are allowed.',\n              );\n            }\n            return trimmed;\n          },\n        })\n        .option('list-sessions', {\n          type: 'boolean',\n          description:\n            'List available sessions for the current project and exit.',\n        })\n        .option('delete-session', {\n          type: 'string',\n          description:\n            'Delete a session by index number (use --list-sessions to see available sessions).',\n        })","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/config/config.ts#L417-L453","documentation":"Thrown inside the yargs `coerce` hook for `--session-id` when the trimmed value contains characters outside the allowed set `[a-zA-Z0-9-_]`. The ID is used to build filesystem paths and resume tokens, so characters like slashes, spaces, dots, or colons would corrupt path resolution or break downstream lookups. The regex rejects anything but alphanumerics, dashes, and underscores.","triggerScenarios":"Passing a UUID with dots (`--session-id 01.abc`), slashes (`--session-id a/b`), colons, spaces, or any punctuation other than dash/underscore; passing a full UUID with curly braces; passing a file path.","commonSituations":"Treating session-id as a free-form label; pasting a UUID in a format that includes characters the regex forbids; using dots to separate version segments; non-ASCII characters.","solutions":["Use only `a-z`, `A-Z`, `0-9`, `-`, and `_`: `gemini --session-id my_session-2026-01`.","Strip or replace disallowed characters before passing the value.","If you need a UUID, use the hyphenated form (already valid): `gemini --session-id 550e8400-e29b-41d4-a716-446655440000`."],"exampleFix":"// before\ngemini --session-id \"my.session/01\"\n// after\ngemini --session-id \"my-session-01\"","handlingStrategy":"validation","validationCode":"const SESSION_ID_RE = /^[a-zA-Z0-9-_]+$/;\nfunction assertSessionId(raw: string): string {\n  const trimmed = raw.trim();\n  if (!SESSION_ID_RE.test(trimmed)) {\n    throw new Error(`Invalid session ID \"${trimmed}\": use a-z, A-Z, 0-9, -, _ only.`);\n  }\n  return trimmed;\n}","typeGuard":"function isValidSessionId(v: unknown): v is string {\n  return typeof v === 'string' && /^[a-zA-Z0-9-_]+$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Restrict generated IDs to `[A-Za-z0-9-_]`.","Replace dots, slashes, and colons with dashes before passing.","Hyphenated UUIDs are already valid; don't wrap them in braces."],"tags":["cli","yargs","session","validation","regex"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}