yamadashy/repomix · error · RepomixError
Failed to copy output file to ${targetPath}: Permission deni
Error message
Failed to copy output file to ${targetPath}: Permission denied.
The current directory may be protected or require elevated permissions.
Please try one of the following:
• Run from a different directory (e.g., your home directory or Documents folder)
• Use the --output flag to specify a writable location: --output ~/repomix-output.xml
• Use --stdout to print output directly to the console What it means
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.
Source
Thrown at src/cli/actions/remoteAction.ts:311
// This can happen when an absolute path is specified for the output file
if (sourcePath === targetPath) {
logger.trace(`Source and target are the same (${sourcePath}), skipping copy`);
return;
}
try {
logger.trace(`Copying output file from: ${sourcePath} to: ${targetPath}`);
// Create target directory if it doesn't exist
await fs.mkdir(path.dirname(targetPath), { recursive: true });
await fs.copyFile(sourcePath, targetPath);
} catch (error) {
const nodeError = error as NodeJS.ErrnoException;
// Provide helpful message for permission errors
if (nodeError.code === 'EPERM' || nodeError.code === 'EACCES') {
throw new RepomixError(
`Failed to copy output file to ${targetPath}: Permission denied.
The current directory may be protected or require elevated permissions.
Please try one of the following:
• Run from a different directory (e.g., your home directory or Documents folder)
• Use the --output flag to specify a writable location: --output ~/repomix-output.xml
• Use --stdout to print output directly to the console`,
);
}
throw new RepomixError(`Failed to copy output file: ${(error as Error).message}`);
}
};
View on GitHub (pinned to f465ad9093)
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
Example fix
// before cd / && npx repomix --remote user/repo // after cd ~/projects && npx repomix --remote user/repo # or npx repomix --remote user/repo --output ~/repomix-output.xml
Defensive patterns
Strategy: validation
Validate before calling
import { accessSync, constants } from 'node:fs';
accessSync(process.cwd(), constants.W_OK); // throws early if CWD is not writable Type guard
const isPermError = (e: unknown): boolean => (e as NodeJS.ErrnoException)?.code === 'EPERM' || (e as NodeJS.ErrnoException)?.code === 'EACCES';
Try / catch
try {
await runRepomix({ remote: url });
} catch (e) {
if (/Permission denied/.test(e.message)) {
await runRepomix({ remote: url, output: '~/repomix-output.xml' });
} else throw e;
} Prevention
- 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
When it happens
Trigger: `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).
Common situations: 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.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- Could not read the remote repository's config (${configName}
- Permission denied while scanning directory. Please check fol
- Failed to write skill output to ${skillDir}: Permission deni
- Failed to read file: ${filePath}
- Failed to copy output file: ${(error as Error).message}
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/eaa7aa95fd2ea0d5.
Report an issue: GitHub.