{"record":{"id":"9243c50f058abc79","repo":"mastra-ai/mastra","slug":"found-projects-length-existing-project-s-in-th-9243c5","errorCode":null,"errorMessage":"Found ${projects.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.","messagePattern":"Found (.+?) existing project\\(s\\) in this organization\\. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/studio/deploy.ts","lineNumber":324,"sourceCode":"      projectSlug: projectConfig.projectSlug ?? projectConfig.projectName ?? projectConfig.projectId,\n    };\n  }\n\n  // 3. Consult the list of existing projects in this org before defaulting to create-new.\n  const projects = await fetchProjects(token, orgId);\n  const nameMatches = defaultName\n    ? projects.filter(proj => proj.name === defaultName || proj.slug === defaultName)\n    : [];\n\n  if (projects.length > 0) {\n    if (autoAccept) {\n      // Non-interactive: only safe to auto-pick when there is exactly one\n      // project whose name/slug matches the package.json name.\n      if (nameMatches.length === 1) {\n        const m = nameMatches[0]!;\n        return { existing: true, projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };\n      }\n      throw new Error(\n        `Found ${projects.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.`,\n      );\n    }\n\n    const CREATE_NEW = '__create_new__';\n    const initialValue = nameMatches.length === 1 ? nameMatches[0]!.id : projects[0]!.id;\n    const selected = await p.select({\n      message: 'Select a project to deploy to',\n      initialValue,\n      options: [\n        ...projects.map(proj => ({\n          value: proj.id,\n          label: `${proj.name} (${proj.id})`,\n        })),\n        { value: CREATE_NEW, label: defaultName ? `＋ Create new project \"${defaultName}\"` : '＋ Create new project' },\n      ],\n    });\n","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/studio/deploy.ts#L306-L342","documentation":"In non-interactive (--yes) deploys, resolveProject only auto-selects an existing project when exactly one project's name/slug matches the local package.json name. When the org has other projects and none (or more than one) match, the command throws rather than deploying to the wrong project, and asks you to pass --project or run interactively.","triggerScenarios":"`mastra studio deploy --yes` against an org that already contains projects, where the local package.json `name` does not uniquely match one project's name or slug (zero matches, or the name matches multiple projects).","commonSituations":"Renaming package.json `name` after the project was created; reusing an org with many pre-existing projects; monorepo package names diverging from Studio project names; duplicate similarly-named projects causing ambiguous matches.","solutions":["Pass --project with the target project's id or slug: `mastra studio deploy --project my-project-slug`","Re-run without --yes and select the project interactively","Align package.json `name` with the existing Studio project name/slug so auto-matching succeeds","Delete obsolete projects in the Studio UI if the ambiguity comes from stale duplicates"],"exampleFix":"// before\nmastra studio deploy --yes\n// Error: Found 3 existing project(s) in this organization...\n// after\nmastra studio deploy --yes --project my-api","handlingStrategy":"validation","validationCode":"const pkg = JSON.parse(readFileSync('package.json', 'utf8'));\nconst projects = await fetchProjects(orgId);\nconst matches = projects.filter(p => p.name === pkg.name || p.slug === pkg.name);\nif (projects.length > 0 && matches.length !== 1 && !process.argv.includes('--project')) {\n  throw new Error('Pass --project <id-or-slug> or run interactively.');\n}","typeGuard":"function hasUniqueProjectMatch(projects: Project[], name: string): projects is [Project, ...Project[]] & { length: 1 } {\n  return projects.filter(p => p.name === name || p.slug === name).length === 1;\n}","tryCatchPattern":"try {\n  await studioDeploy({ yes: true });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('existing project(s) in this organization')) {\n    console.error('Run with --project <id-or-slug> or drop --yes to pick interactively.');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Keep package.json `name` identical to the Studio project name/slug","Always pass --project explicitly in CI/automation","Clean up stale projects in the Studio org to avoid ambiguous name matches","Avoid renaming package.json without updating the Studio project"],"tags":["cli","configuration","project-resolution"],"backgroundTag":"ambiguous-project-selection","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}