{"record":{"id":"f606a75e6f29bdd8","repo":"upstash/context7","slug":"library-has-been-redirected","errorCode":null,"errorMessage":"Library has been redirected","messagePattern":"Library has been redirected","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cli/src/commands/docs.ts","lineNumber":158,"sourceCode":"    result = await getLibraryContext(libraryId, query, { type: outputType }, accessToken);\n  } catch (err) {\n    spinner?.fail(`Error: ${err instanceof Error ? err.message : String(err)}`);\n    if (!spinner) log.error(err instanceof Error ? err.message : String(err));\n    process.exitCode = 1;\n    return;\n  }\n\n  if (typeof result === \"string\") {\n    spinner?.stop();\n    console.log(result);\n    return;\n  }\n\n  const ctx = result as ContextResponse;\n\n  if (ctx.error) {\n    if (ctx.redirectUrl) {\n      spinner?.warn(\"Library has been redirected\");\n      if (!spinner) log.warn(\"Library has been redirected\");\n      log.info(`New ID: ${pc.cyan(ctx.redirectUrl)}`);\n      log.info(`Run: ${pc.cyan(`ctx7 docs \"${ctx.redirectUrl}\" \"${query}\"`)}`);\n      process.exitCode = 1;\n      return;\n    }\n\n    spinner?.fail(ctx.message || ctx.error);\n    if (!spinner) log.error(ctx.message || ctx.error);\n    process.exitCode = 1;\n    return;\n  }\n\n  const total = (ctx.codeSnippets?.length || 0) + (ctx.infoSnippets?.length || 0);\n  if (total === 0) {\n    spinner?.warn(`No documentation found for: \"${query}\"`);\n    if (!spinner) log.warn(`No documentation found for: \"${query}\"`);\n    return;","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/upstash/context7/blob/5284672feb575908efead6fcf1b5e542f8d607bb/packages/cli/src/commands/docs.ts#L140-L176","documentation":"The library-context lookup returned ctx.error together with a redirectUrl: the requested library ID has been renamed/migrated upstream. The spinner branch (spinner?.warn, line 158) prints the notice, the CLI then shows the new ID and a ready-to-copy `ctx7 docs <newId> <query>` command, sets process.exitCode=1, and stops without fetching docs.","triggerScenarios":"Requesting docs for an outdated library ID after the registry consolidated/moved it (package rename, org transfer, docs merge); hit when re-running old commands or using IDs saved earlier from search results.","commonSituations":"Stale IDs in shell history, scripts, or notes; libraries that renamed upstream; consolidated documentation pages replacing several old IDs.","solutions":["Re-run using the new ID printed on the 'New ID:' line","Resolve the canonical ID fresh with `context7 docs \"<name>\" search` and use that","Update any scripts/configs that hardcode the old library ID"],"exampleFix":"# before\nctx7 docs \"/old-org/old-lib\" \"hooks\"   # → Library has been redirected\n\n# after — use the printed New ID\nctx7 docs \"/new-org/new-lib\" \"hooks\"","handlingStrategy":"type-guard","validationCode":"// resolve the canonical ID right before fetching docs\nconst search = await searchLibraries(library, token);\nif (search.results?.length) library = search.results[0].id; // fresh canonical ID","typeGuard":"function isRedirect(ctx: { error?: string; redirectUrl?: string }): ctx is { error: string; redirectUrl: string } {\n  return !!ctx.error && typeof ctx.redirectUrl === \"string\" && ctx.redirectUrl.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Do not hardcode library IDs in long-lived scripts — resolve via search at runtime","When the 'New ID:' hint appears, update saved commands/configs immediately","Wrap docs fetches so a redirect (exitCode=1) triggers one automatic retry with the new ID"],"tags":["api","redirect","library-id","docs","cli"],"backgroundTag":"resource-moved-redirect","analyzedSha":"5284672feb575908efead6fcf1b5e542f8d607bb","analyzedAt":"2026-08-18T18:00:18.510Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}