Claude settings.json can be overwritten when unreadable, and a symlinked one becomes a plain file
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 79/100
Direzione di ricerca
Inizia seguendo edit(_:add:port:token:) in CatNotchCore/ClaudeSettingsFile.swift per verificare come vengono gestiti gli errori di lettura e le scritture atomiche. Poi esamina le suite HookSync e OtherToolsAndBadFiles in CatNotchCoreTests/ClaudeHooksTests.swift e la specifica in docs/specs/0006-claude-request-strip.md. Usa una cartella temporanea per le impostazioni; il lavoro è completato quando gli errori di lettura lasciano invariato il file e la scrittura tramite un symlink conserva il collegamento e aggiorna la sua destinazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
[!NOTE]
This issue was raised by Claude (AI code review), not from a user report. Before you start, confirm the problem really exists: reproduce it, or trace the code path yourself. If it does not reproduce, comment here with what you checked and we will close it.The fix ideas and file names below are suggestions, not requirements. If a different or larger change is the right fix, go with it and explain why in the PR. The maintainer will review and merge.
Labels: bug, ready-for-agent · Difficulty: easy to medium (about 2 to 3 hours; all of it is testable in CatNotchCore)
Problem
When the Claude integration is on, CatNotch writes its hook entries into the user's ~/.claude/settings.json on every launch (ClaudeSettingsFile.edit). Two cases can damage the user's file:
- An unreadable file is treated as empty and overwritten.
CatNotchCore/ClaudeSettingsFile.swift:69doesif let data = try? Data(contentsOf: file). Any read error (for example a root-ownedsettings.jsonleft bysudo claude, inside a folder the user can still write) leavestextempty, sorootbecomes{}. The file is then replaced with only our hooks. No backup is made, because the backup at line 106 requirestextto be non-empty. The atomic write only needs the folder to be writable, so it succeeds. - A symlinked settings.json becomes a plain file.
out.write(to: file, options: .atomic)(line 107) writes a temp file and renames it over the path, which replaces the symlink. Users who keep~/.claude/settings.jsonas a symlink into a dotfiles repo (GNU stow and similar) silently lose the link: later edits in the repo stop applying, and our change never reaches the repo.
Expected outcome
- Only "file does not exist" counts as empty. Any other read error throws, and nothing is written.
- When
settings.jsonis a symlink, the write goes to the symlink's target and the link stays.
Relevant files
CatNotchCore/ClaudeSettingsFile.swift(edit(_:add:port:token:))CatNotchCoreTests/ClaudeHooksTests.swift(theHookSync/OtherToolsAndBadFilessuites)- Spec:
docs/specs/0006-claude-request-strip.md
Acceptance criteria
- A test with an unreadable
settings.json(for examplechmod 000) showseditthrows and the file's contents are unchanged. - A test with
settings.jsonas a symlink shows that aftereditthe link is still a link and the target holds the hooks. - Existing tests still pass.
- Tests use a temp folder (set
CLAUDE_CONFIG_DIRor pass a URL). Never touch the real~/.claude.
Hint
FileManager.default.destinationOfSymbolicLink(atPath:) or URL.resolvingSymlinksInPath() gives the real path to write to. For the read, check for CocoaError.fileReadNoSuchFile and rethrow everything else.
- Lingua principale
- Swift
- Stelle
- 1
- Fork
- 1
- Merge medio
- 3h 11m
- PR unite (30g)
- 28
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di thecharydev/catnotch
-
bug good first issue ready-for-agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
thecharydev/catnotch#68 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
thecharydev/catnotch#41 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
thecharydev/catnotch#40 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
thecharydev/catnotch#39 ·
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
thecharydev/catnotch#74 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di thecharydev/catnotch
Issue simili
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
manaflow-ai/cmux#68791 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
codual-ai/designlane#56 ·
I maintainer di solito rispondono entro 1 giorno
-
apple
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
erkamyaman/unslop-anything#375 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
openwatersio/slackwater-ios#976 ·
I maintainer di solito rispondono entro 1 giorno