{"record":{"id":"b133b25a4b06dd5b","repo":"twpayne/chezmoi","slug":"s-cannot-add-chezmoi-s-config-file-to-chezmoi-u","errorCode":null,"errorMessage":"%s: cannot add chezmoi's config file to chezmoi, use a config file template instead","messagePattern":"(.+?): cannot add chezmoi's config file to chezmoi, use a config file template instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/chezmoi/sourcestate.go","lineNumber":423,"sourceCode":"\n\t\ttargetRelPath := destAbsPath.MustTrimDirPrefix(s.destDirAbsPath)\n\t\tif s.Ignore(targetRelPath) {\n\t\t\tif options.OnIgnoreFunc != nil {\n\t\t\t\toptions.OnIgnoreFunc(targetRelPath)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tdestAbsPaths[n] = destAbsPath\n\t\tn++\n\t}\n\tdestAbsPaths = destAbsPaths[:n]\n\n\t// Check for protected paths.\n\tfor _, destAbsPath := range destAbsPaths {\n\t\tif destAbsPath == options.ConfigFileAbsPath {\n\t\t\tformat := \"%s: cannot add chezmoi's config file to chezmoi, use a config file template instead\"\n\t\t\treturn fmt.Errorf(format, destAbsPath)\n\t\t}\n\t}\n\tfor _, destAbsPath := range destAbsPaths {\n\t\tfor _, protectedAbsPath := range options.ProtectedAbsPaths {\n\t\t\tif protectedAbsPath.IsEmpty() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif destAbsPath.HasDirPrefix(protectedAbsPath) {\n\t\t\t\tformat := \"%s: cannot add chezmoi file to chezmoi (%s is protected)\"\n\t\t\t\treturn fmt.Errorf(format, destAbsPath, protectedAbsPath)\n\t\t\t}\n\t\t}\n\t}\n\n\ttype sourceUpdate struct {\n\t\tdestAbsPath    AbsPath\n\t\tentryState     *EntryState\n\t\tsourceRelPaths []SourceRelPath","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/twpayne/chezmoi/blob/f901167e4685db90da56d6a2a19df642cb3e0247/internal/chezmoi/sourcestate.go#L405-L441","documentation":"chezmoi refuses to add its own config file (the file passed via --config or the default config location) into the source state via 'chezmoi add'. Managing the config file as a regular source entry would create a recursive dependency; the documented alternative is a config file template so machine-specific values are rendered at runtime.","triggerScenarios":"Running 'chezmoi add ~/.config/chezmoi/chezmoi.toml' (or equivalent path) where the destination path exactly equals options.ConfigFileAbsPath during source state update in addEntries/add path handling.","commonSituations":"Users try to version-control their chezmoi config by adding it like any other dotfile; scripts that blanket-add ~/.config; users switching config locations and adding the old file.","solutions":["Create a config file template instead: run 'chezmoi add --template ~/.config/chezmoi/chezmoi.toml' is also blocked, so manually create the file under ~/.local/share/chezmoi/ with a .tmpl suffix containing the template form of the config.","Move the config content into e.g. ~/.local/share/chezmoi/dot_config/chezmoi/chezmoi.toml.tmpl and let chezmoi apply it as a managed file.","If you only need the config on the current machine, exclude it from add operations (avoid passing it to 'chezmoi add')."],"exampleFix":"// before (fails)\n$ chezmoi add ~/.config/chezmoi/chezmoi.toml\n// after\n$ chezmoi cd\n$ mkdir -p dot_config/chezmoi\n$ cat > dot_config/chezmoi/chezmoi.toml.tmpl <<EOF\n[git]\nautoCommit = {{ .chezmoi.hostname == \"work\" }}\nEOF","handlingStrategy":"validation","validationCode":"#!/bin/sh\ncfg=$(chezmoi source-path 2>/dev/null)\nif [ \"$1\" = \"$HOME/.config/chezmoi/chezmoi.toml\" ]; then\n  echo \"use a config file template instead of chezmoi add\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass the chezmoi config file path to 'chezmoi add'","Keep config machine-specific values in .chezmoi.toml.tmpl","Script wrappers around chezmoi add should filter the config path"],"tags":["chezmoi","config-file","protected-path"],"backgroundTag":"protected-path-rejected","analyzedSha":"f901167e4685db90da56d6a2a19df642cb3e0247","analyzedAt":"2026-09-01T18:16:41.508Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}