Use when working with any configuration file outside of project directories in ~/Code (unless already managed like ~/Code/CLAUDE.md) - handles chezmoi prefix mappings, template awareness, conflict...
Chezmoi manages dotfiles with a git-backed source directory. Always check for templates first, work with the source, understand prefix mappings, and follow the conflict resolution workflow to avoid losing changes.
Before editing ANY config file:
# Check if file is templated:
ls -la ~/.local/share/chezmoi/[prefix_mapped_name]*
If .tmpl exists:
chezmoi add (removes template attribute)cp ~/file ~/.local/share/chezmoi/prefix_mapped_name.tmplWhy this matters:
.tmpl exists → changes overwritten on next applychezmoi add on templates → loses template logic permanently{{ .chezmoi.hostname }} that must be preserved| Actual file | Chezmoi source |
|---|---|
.claude/hooks/SessionStart |
dot_claude/hooks/executable_SessionStart |
.ssh/config |
private_dot_ssh/config.tmpl |
.config/ghostty/config |
dot_config/ghostty/config |
.zshrc |
private_dot_zshrc.tmpl |
Pattern:
. → dot_private_ prefixexecutable_ prefix.tmpl suffixChezmoi source location: ~/.local/share/chezmoi/
Valid hook names (cannot create arbitrary names):
SessionStart - runs at session startstop-notification.sh - custom notification hooksThese are specific hook types, not arbitrary filenames.
For any config file edit:
ls ~/.local/share/chezmoi/prefix_mapped_name*cp ~/file ~/.local/share/chezmoi/prefix_mapped_namechezmoi diffcd ~/.local/share/chezmoi && git add -A && git commit -m "msg"git pushWhen working with config files that may have local drift + remote changes:
chezmoi status
# Shows files modified locally vs chezmoi source
# MM = modified in both local and source
# M = modified in source only
For each modified file:
cp ~/actual-file ~/.local/share/chezmoi/prefix_mapped_namechezmoi diff shows expected changesCommit local changes:
cd ~/.local/share/chezmoi
git add -A
git commit -m "Capture local config changes"
# Don't push yet
cd ~/.local/share/chezmoi
git pull --rebase
# Handle any git conflicts in source files if needed
chezmoi diff
# Shows what would change if you apply chezmoi now
For each file in diff:
If remote changes are good:
chezmoi apply
If local changes should override remote:
If need to merge:
~/.local/share/chezmoi/prefix_mapped_namecd ~/.local/share/chezmoi && git add file && git commit -m "Merge local and remote changes"cd ~/.local/share/chezmoi
git push
Now all machines get the resolved state.
| Mistake | Symptom | Fix |
|---|---|---|
| Skip template check | Changes disappear after apply | Always check for .tmpl FIRST |
Use chezmoi add on template |
"remove template attribute" warning | Copy directly to source instead |
| Edit generated file | Work gets overwritten | Edit template source |
Forget dot_ prefix |
Can't find file in source | Use prefix mapping table |
| Pull before capturing local | Local changes lost | Always capture local drift first |
| Act under time pressure | Invalid names, wrong locations | Check first, act second |
chezmoi add → Check if file is templated first.tmpl version exists firstTrigger this skill when:
~/.config/, ~/.ssh/, dotfiles like .zshrc, .claude/chezmoi status, chezmoi diff, chezmoi applyDon't use for:
~/Code/*) unless already managed by chezmoi (like ~/Code/CLAUDE.md)