Gemini CLI "ENAMETOOLONG: name too long" in write_file: how to fix it
Back to the blog
Articlegemini clitroubleshootingagente de programaçãodev toolsopen source

Gemini CLI "ENAMETOOLONG: name too long" in write_file: how to fix it

MafraOctober 17, 20265 min read

You updated Gemini CLI, asked the agent to create or edit a file with a long name, and write_file (or replace) came back with ENAMETOOLONG: name too long. The name is valid: the shell writes the same file without complaint. What overflows the limit is the temporary file Gemini CLI creates since version 0.64.0, the current stable release.

This guide shows where the error comes from, how to confirm it with one command, and three ways to get unstuck until the official fix ships. Everything was checked against the source code and releases of the google-gemini/gemini-cli repository on 2026-10-17, and the limit was reproduced on an ext4 filesystem.

What does "ENAMETOOLONG" mean in Gemini CLI's write_file?

It means the operating system refused to open a file whose name is longer than 255 bytes. The clue is at the end of the message: the rejected path ends in .tmp, it is not the file you asked for.

Error writing to file '/project/docs/<long-name>.md': ENAMETOOLONG: name too long, open '/project/docs/<long-name>.md.8dcae82f-0430-47ee-adf0-bcd8979a3a72.tmp' (ENAMETOOLONG)

The file is not created. If it already exists, the agent can't overwrite or edit it. The case is described in issue #29702, opened on 2026-10-10.

Why does a valid name fail in 0.64.0?

Because 0.64.0 switched to atomic writes: it writes to a temporary file next to the destination and then renames it. The temp name is the destination name plus a UUID and .tmp, which adds 41 bytes. From packages/core/src/services/fileSystemService.ts:

const tmpPath = `${realPath}.${randomUUID()}.tmp`;

Linux and macOS allow up to 255 bytes per file name (NAME_MAX). So any name between 215 and 255 bytes is legal for the system and illegal for the temp file. In our ext4 test, a 214-byte name produced a 255-byte temp name and the write succeeded; at 215 bytes the temp name hit 256 and failed.

VersionHow it writesReleased
0.63.0Writes straight to the destination, no temp file2026-10-06
0.64.0 (stable, latest tag)Temp file + rename, fails above 214 bytes2026-10-13
0.65.0-preview.0 and the 0.66.0 nightly of 10/17Same code as 0.64.02026-10-13 to 2026-10-17

Count bytes, not characters

A plain ASCII letter takes 1 byte in UTF-8, an accented letter takes 2, and a Chinese or Japanese character takes 3. A file named with 70 CJK characters plus .md is 213 bytes and passes. With 71 characters it is 216 bytes and write_file fails. Names built from document titles, long slugs or embedded hashes get there fast.

A symlink shortcut doesn't help either: Gemini CLI resolves the link to the real path before it builds the temp name, so the destination file's own name is what counts.

Flowchart: the ENAMETOOLONG error names a .tmp file, count the name in bytes with printf and wc -c, shorten the name to 214 bytes or less; if the name can't change, go back to 0.63.0 with auto update turned off
From the error to the workaround, in three steps and one branch.

How do I confirm this is the problem?

Check the version and count the name in bytes:

gemini --version
printf '%s' 'file-name.md' | wc -c

If the version is 0.64.0 or newer and the number is above 214, this is the bug. To find every file in the project that write_file can't rewrite, in one go:

find . -type f | LC_ALL=C awk -F/ 'length($NF) > 214'

LC_ALL=C makes awk count bytes instead of characters. Your filesystem's limit comes from getconf NAME_MAX . (255 on ext4, APFS and most setups).

How do I fix ENAMETOOLONG in Gemini CLI?

Shorten the name to 214 bytes or less. It is the simplest path and doesn't depend on the version. To keep the agent from generating long names again, put the rule in the project's GEMINI.md:

New file names: 150 bytes at most. Use a short slug, not the full title.

You need to edit an existing file with a long name

Rename it, edit it, and rename it back. mv doesn't use a temp file, so it works with any name the system accepts:

mv 'original-long-name.md' tmp-edit.md
# ask for the edit on tmp-edit.md
mv tmp-edit.md 'original-long-name.md'

Another way out is to ask the agent to write through the shell (run_shell_command) instead of write_file. The shell writes straight to the destination, without the 41-byte suffix.

The name can't change: go back to 0.63.0

  1. Turn off auto update in ~/.gemini/settings.json, or Gemini CLI will move itself back to 0.64.0:
    {
      "general": {
        "enableAutoUpdate": false
      }
    }
  2. Install the previous version:
    npm install -g @google/gemini-cli@0.63.0

Mind the trade-off: 0.63.0 has the Untrusted Command Flags Detected false positive in YOLO mode, which 0.64.0 fixed. We cover that warning in this guide. If you run with --yolo, shortening the name is usually cheaper than downgrading.

When does the official fix ship?

Not yet. PR #29703, opened on 2026-10-10, keeps the temp file in the same folder (so the rename stays atomic) and trims its name to fit in 255 bytes, with tests for a 254-byte ASCII name and a long Chinese name. As of 10/17 it was still open, not merged. Watch issue #29702 and turn enableAutoUpdate back on once the fix reaches a stable release.

In Verboo Code, the write and edit tools also write to a temp file and rename it, but if the temp file fails the write falls back to writing straight to the destination. A long name doesn't kill the task halfway through.

Enjoyed this article?
Share knowledge with your network.
// Read also

Related articles