{"record":{"id":"eaa7aa95fd2ea0d5","repo":"yamadashy/repomix","slug":"failed-to-copy-output-file-to-targetpath-permi","errorCode":null,"errorMessage":"Failed to copy output file to ${targetPath}: Permission denied.\n\nThe current directory may be protected or require elevated permissions.\nPlease try one of the following:\n  • Run from a different directory (e.g., your home directory or Documents folder)\n  • Use the --output flag to specify a writable location: --output ~/repomix-output.xml\n  • Use --stdout to print output directly to the console","messagePattern":"Failed to copy output file to (.+?): Permission denied\\.\n\nThe current directory may be protected or require elevated permissions\\.\nPlease try one of the following:\n  • Run from a different directory \\(e\\.g\\., your home directory or Documents folder\\)\n  • Use the --output flag to specify a writable location: --output ~/repomix-output\\.xml\n  • Use --stdout to print output directly to the console","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/cli/actions/remoteAction.ts","lineNumber":311,"sourceCode":"  // This can happen when an absolute path is specified for the output file\n  if (sourcePath === targetPath) {\n    logger.trace(`Source and target are the same (${sourcePath}), skipping copy`);\n    return;\n  }\n\n  try {\n    logger.trace(`Copying output file from: ${sourcePath} to: ${targetPath}`);\n\n    // Create target directory if it doesn't exist\n    await fs.mkdir(path.dirname(targetPath), { recursive: true });\n\n    await fs.copyFile(sourcePath, targetPath);\n  } catch (error) {\n    const nodeError = error as NodeJS.ErrnoException;\n\n    // Provide helpful message for permission errors\n    if (nodeError.code === 'EPERM' || nodeError.code === 'EACCES') {\n      throw new RepomixError(\n        `Failed to copy output file to ${targetPath}: Permission denied.\n\nThe current directory may be protected or require elevated permissions.\nPlease try one of the following:\n  • Run from a different directory (e.g., your home directory or Documents folder)\n  • Use the --output flag to specify a writable location: --output ~/repomix-output.xml\n  • Use --stdout to print output directly to the console`,\n      );\n    }\n\n    throw new RepomixError(`Failed to copy output file: ${(error as Error).message}`);\n  }\n};\n","sourceCodeStart":293,"sourceCodeEnd":325,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/cli/actions/remoteAction.ts#L293-L325","documentation":"When copying the generated repomix output file from the temp directory into the current working directory, Node reports EPERM/EACCES. Repomix converts this into a guidance-rich RepomixError because the current directory is read-only or protected, and suggests alternate output locations.","triggerScenarios":"`runRemoteAction` -> `copyOutputToCurrentDirectory` -> `fs.copyFile(sourcePath, targetPath)` rejects with `code === 'EPERM'` or `'EACCES'`: the CWD lacks write permission (e.g. running from `/`, `/usr`, a protected volume, or a read-only mount).","commonSituations":"Running `npx repomix --remote ...` from the filesystem root, from a system directory on macOS with SIP, from a container with a read-only workdir, or from a directory owned by another user.","solutions":["Change to a writable directory (home, Documents) before running repomix","Pass `--output ~/repomix-output.xml` to write somewhere writable","Use `--stdout` to print output instead of writing a file","Fix directory permissions (chmod/chown) if appropriate"],"exampleFix":"// before\ncd / && npx repomix --remote user/repo\n// after\ncd ~/projects && npx repomix --remote user/repo\n# or\nnpx repomix --remote user/repo --output ~/repomix-output.xml","handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'node:fs';\naccessSync(process.cwd(), constants.W_OK); // throws early if CWD is not writable","typeGuard":"const isPermError = (e: unknown): boolean =>\n  (e as NodeJS.ErrnoException)?.code === 'EPERM' ||\n  (e as NodeJS.ErrnoException)?.code === 'EACCES';","tryCatchPattern":"try {\n  await runRepomix({ remote: url });\n} catch (e) {\n  if (/Permission denied/.test(e.message)) {\n    await runRepomix({ remote: url, output: '~/repomix-output.xml' });\n  } else throw e;\n}","preventionTips":["Run repomix from a user-writable directory (home/projects), not / or system dirs","Pass an explicit `--output` path in a known-writable location","Check CWD write permission programmatically before invoking"],"tags":["filesystem","permissions","eproj-eacces"],"backgroundTag":"permission-denied","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}