# Couldn't write a file

What "couldn't write a file" means and how to fix it.

```text
error: couldn't write package.json: Access is denied. (os error 5)
hint: Check that the file isn't open elsewhere and that you can write to its folder. Nothing was changed.
```

```text
error: couldn't write packages/web/src/button.tsx: a link takes it outside the repository or into .git
hint: Remove the link, or write somewhere else. Nothing was changed.
```

## Why it happens

A command that changes your files, such as [`axle init`](https://axlers.dev/docs/reference/init.md) or [`axle release`](https://axlers.dev/docs/reference/release.md), couldn't write one of them. The folder may be read-only, another program may have the file locked, or a file stands where a folder is needed. Axle also refuses to write through a symbolic link or junction that leads outside the repository or into `.git`, so a generator or a value given to it can't place files there.

Axle writes all of a command's files or none: it prepares every change first, and when one file can't be written, it puts back the files it had already changed. So nothing was changed. [`axle prune`](https://axlers.dev/docs/reference/prune.md) doesn't change your files: it writes a new copy, and removes that copy when one of its files can't be written.

[`axle login`](https://axlers.dev/docs/reference/remote-cache.md#logging-in) and `axle logout` keep tokens in your user's configuration folder. When that file can't be written, or Axle can't tell where the folder is, the hint names `AXLE_CONFIG_DIR`, which chooses another folder.

## How to fix it

Close any program that has the file open, check that you can write to its folder, then run the command again. For a link, remove it or write somewhere else.
