#4361·chezmoi

[Feature Request] Automated synchronization of deletions and renaming of files from the home directory

Author: Lockszmith-GHCreated Mar 20, 2025Updated Aug 28, 2026
Labelsenhancement

In a necromanced thread a few days ago, the recurring theme of trying to tackle the synchronized removal of files came up again - a chezmoi engineering problem that hasn't been solved yet.

In summery: chezmoi has all of the building blocks to facilitate removal of files, but there is no automated synchronization as it's impossible to detect automatically.

Setting the stage:

Each Instance of chezmoi has 3 potential stages:

  1. Home - The home directory itself - the working copy.
  2. Source - The chezmoi source of truth - with all the settings and templates.
  3. Repo - most commonly git, which allows synchronizations across Instances

What is already in place and working:

Current optimized workflows (as far as I could tell) are:

A: Delete a file from everywhere - Destroy and remove

  • chezmoi destroy <file>
  • Add a remove_<file> blank file in source (or add to .chezmoiremove)

B: Rename a file everywhere - Forget, remove and add

  • chezmoi forget <file>
  • rename <file> to <new_file>
  • Add a remove_<file> blank file in source (or add to .chezmoiremove)
  • chezmoi add <new_file>

What can be improved?

The issue I see in common of these two workflows:

  1. Too many steps for what, fells like, should be a single operation.
  2. remove_ source-state-attribute files and .chezmoiremove are inherently temporary, and left untouched will create clutter and confusion later on.

Proposed solution

I believe I have a possible solution for both issues. This solution combines 2 separate ideas:

  • Automated remove_ source-state-attribute creation
  • An optional grabage-collection of remove_ files from the source by chezmoi update

Phase 1: * Automated remove_ source-state-attribute creation

  1. A flag added to forget and destroy (suggestions: --sync or --managed) which would also create the remove_ source-state-attribute file.
    This will reduce the A workflow into a single action.
  2. A new mv command, which would perform the B workflow in a single action.

Phase 2: Garbage collection

This phase is optional, and can be left to the user to manage on their own.

The idea is to introduce garbage-collection of remove_ source-state-attribute files when chezmoi update is running.

In order for this to work, the actions of Phase 1 above, will create the remove_ files with an expiration date (or a creation date - depending on how you choose to implement it) in ISO format as the content.

I would suggest that chezmoi.toml would allow to modify the default expiration time, but let's say 1 month is a reasnoble default.

When running chezmoi update, it will act as the garbage-collector and delete the remove_ files from the source when the expiration date has passed.

The combination of all these together will provide a complete solution addressing all existing recurring issue, providing a completely automated process of handing this naturally out-of-sync problem.

This proposed solution also allows to keep everything that is already working, and enhance on it.