Yeachan-Heo/oh-my-codex · error · Error

mode must not contain path separators

Error message

mode must not contain path separators

What it means

Thrown when the mode string contains a forward slash or backslash. Mode is used as a single filename segment, so path separators would create (or traverse into) subdirectories of the state directory.

Source

Thrown at src/mcp/state-paths.ts:142

    throw new Error('session_id must match ^[A-Za-z0-9_-]{1,64}$');
  }
  return sessionId;
}


export function validateStateModeSegment(mode: unknown): string {
  if (typeof mode !== 'string') {
    throw new Error('mode must be a string');
  }
  const normalized = mode.trim();
  if (!normalized) {
    throw new Error('mode must be a non-empty string');
  }
  if (normalized.includes('..')) {
    throw new Error('mode must not contain ".."');
  }
  if (normalized.includes('/') || normalized.includes('\\')) {
    throw new Error('mode must not contain path separators');
  }
  if (!STATE_MODE_SEGMENT_PATTERN.test(normalized)) {
    throw new Error('mode must match ^[A-Za-z0-9_-]{1,64}$');
  }
  return normalized;
}

export function getStateFilename(mode: string): string {
  return `${validateStateModeSegment(mode)}${STATE_FILE_SUFFIX}`;
}

export function validateStateFileName(fileName: unknown): string {
  if (typeof fileName !== 'string') {
    throw new Error('fileName must be a string');
  }
  const normalized = fileName.trim();
  if (!normalized) {
    throw new Error('fileName must be a non-empty string');

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Pass just the leaf segment name: "night" instead of "team/night"
  2. Replace separators with hyphens: mode.replace(/[\\/]+/g, "-")
  3. Keep mode values as simple slugs

Example fix

// before
getStateFilename("team/night");
// after
getStateFilename("team-night");
Defensive patterns

Strategy: validation

Validate before calling

mode = mode.replace(/[\\/]+/g, '-');

Type guard

function isSingleSegment(v: string): boolean { return !/[\\/]/.test(v); }

Prevention

When it happens

Trigger: mode: "team/night", mode: "a\\b", or Windows-style values copied from paths.

Common situations: Passing a relative file path where a mode name is expected; config keys derived from paths; backslashes on Windows clients.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/060a1a9bd1861e9e. Report an issue: GitHub.