After renaming a file, loadDirectory() was called which rebuilt the galleryImages array in new alphabetical order. The gallery index didn't change, so it now pointed to a different file — subsequent renames hit the wrong file. Fix: only update local state during the gallery session, defer the file list refresh to when the gallery closes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>