{"record":{"id":"a1f458b238269721","repo":"google-gemini/gemini-cli","slug":"the-session-id-option-cannot-be-empty","errorCode":null,"errorMessage":"The --session-id option cannot be empty.","messagePattern":"The --session-id option cannot be empty\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/config/config.ts","lineNumber":432,"sourceCode":"            if (trimmed === '') {\n              return RESUME_LATEST;\n            }\n            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',","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/config/config.ts#L414-L450","documentation":"Thrown inside the yargs `coerce` hook for `--session-id` when the user-supplied value, after trimming whitespace, is empty. The coerce runs only when the flag is present, so this fires for `--session-id \"\"` or whitespace-only values. The session ID is later used to resume a specific session, so an empty value is meaningless and rejected early.","triggerScenarios":"Running `gemini --session-id \"\"`, `gemini --session-id \"   \"`, or passing the flag with an empty shell variable (`gemini --session-id \"$SID\"` with `SID` unset or empty).","commonSituations":"Scripted invocations that always pass the flag but forget to populate the variable; copy-paste templates that leave the value blank; CI jobs with an unbound `SESSION_ID` env var.","solutions":["Omit the flag entirely to let Gemini auto-generate a session ID.","Pass a concrete non-empty identifier: `gemini --session-id my-session-1`.","Guard the flag in scripts: `[ -n \"$SID\" ] && args+=(--session-id \"$SID\")`."],"exampleFix":"// before\ngemini --session-id \"\"\n// after\ngemini --session-id my-session-1","handlingStrategy":"validation","validationCode":"function normalizeSessionId(raw: string | undefined): string | undefined {\n  if (raw === undefined) return undefined;\n  const trimmed = raw.trim();\n  if (!trimmed) {\n    throw new Error('--session-id cannot be empty; omit the flag to auto-generate.');\n  }\n  return trimmed;\n}","typeGuard":"function isNonEmptyTrimmed(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Omit `--session-id` when you don't need a specific session.","In scripts, only add the flag when the backing variable is non-empty.","Treat an empty session id as a no-op rather than passing it through."],"tags":["cli","yargs","session","validation","argument"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}