Skip to content

Move/rename/delete operations leave _attachments folder orphaned #3

@kendocode

Description

@kendocode

Problem

When using noteplan_manage_note move to relocate a note to a different folder, the note's _attachments directory is left behind in the original location. This silently breaks all embedded images and file references in the moved note.

The same gap exists for rename (the _attachments folder name derives from the note filename, so it becomes disconnected) and delete (the _attachments folder is left behind when the note is trashed).

How encountered:

While reorganizing a NotePlan library via the MCP — moving notes from subfolders to other folders. After moving ~26 notes, NotePlan's sidebar still showed the now-empty subfolder tree. Investigating on disk found:

  1. Empty parent directories (the MCP moves the file but doesn't clean up empty dirs)
  2. Orphaned _attachments folders with images/files still in the old location
  3. Broken ![file](...) links in the moved notes (relative paths no longer resolve)

Fixed manually by moving _attachments folders via the shell and removing empty directories with rmdir.

Suspected root cause

In src/noteplan/file-writer.ts, moveLocalNote() calls moveFile() on the single .md file only. The _attachments sibling directory is not considered. Same pattern in renameLocalNoteFile() and deleteNote().

The attachment path logic already exists in attachments.ts (getAttachmentsFolderPath()), it's just not referenced during note-level file operations.

Suggested fix

In file-writer.ts, after each note file operation, also handle the _attachments folder:

  • moveLocalNote()** — after moving the .md, move {noteName}_attachments/ to the destination:

  • renameLocalNoteFile()** — rename the _attachments folder AND rewrite attachment links in note content

  • deleteNote()** — move _attachments/ to @Trash alongside the note.

  • Optional:** moveLocalNote() could also clean up empty parent directories after moving, since the MCP's folders.delete action exists but users might not expect to need it after moving out the last note. Less sure about that, we don't have a .keep equivalent here I know of and some might want to keep the folder with no content, others not.

Environment

  • noteplan-mcp v1.1.15
  • NotePlan 3 (SetApp)
  • Using CloudKit sync
  • M3 Max MBP on macOS 26.3.1

Thanks for a great MCP server — this was the only hiccup in an otherwise seamless reorganization of ~200 notes. Happy to submit a PR if that's preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions