Documentation
¶
Overview ¶
Package settings edits Claude Code's settings.json in place: only the keys sitrep owns change, and the rest of the file (other keys, their order, the user's formatting) stays byte for byte. An edit is checked before anything is written, written to a temporary file, and moved into place, so Claude Code never sees half a file and a symlinked settings.json stays a symlink.
Index ¶
Constants ¶
const BOM = "\xef\xbb\xbf"
BOM is the byte order mark some editors put at the start of a file. It is kept as it is, outside the document.
const Tag = "# claude-sitrep"
Tag ends the status line command sitrep writes. It is how any clone's wrapper is recognized as ours (invariant 6).
Variables ¶
var ( ErrNotJSON = errors.New("cannot be parsed as JSON") ErrNotObject = errors.New("is not a JSON object") ErrStatusNotObj = errors.New("the statusLine is not an object") ErrStatusMissing = errors.New("there is no statusLine") )
Errors a caller reports as they are.
var ErrChanged = errors.New("changed while it was being edited")
ErrChanged says the file changed while setup worked on it.
var ErrDuplicate = errors.New("has a duplicate key")
ErrDuplicate says an object has the same key twice.
Functions ¶
func Backup ¶
Backup writes the given bytes (what was read and parsed) to <path>.bak.<timestamp>, owner-only because settings may hold credentials. It never overwrites an earlier backup: a name that is taken gets a number. It returns the name.
func SplitBOM ¶
SplitBOM takes a leading byte order mark off, so that the rest can be parsed and edited.
func Verify ¶
Verify checks an edit before it is written: the result is valid, every other top-level key holds what it held, and the status line is what was meant (command empty means it was removed). The edit library does not check its own work.
func Write ¶
Write replaces the file in one step. A link is followed, so the real file is replaced and the link stays a link. The mode of an existing file is kept; a new one is owner-only. original is what the file held when it was read (nil for none): when it holds something else by the time of the rename, Claude Code or the user has written it too, and Write stops and changes nothing. That narrows the race; it cannot close it without a lock both sides take.
Types ¶
type Doc ¶
type Doc []byte
Doc is the text of a settings file.
func Parse ¶
Parse checks that data is one JSON object. The edit library accepts malformed input and a byte order mark silently drops the rest of the file, so nothing is edited until this passes.
func (Doc) HookCommands ¶
HookCommands lists the commands of every hook of every event.
func (Doc) RestoreStatusLine ¶
RestoreStatusLine puts the upstream command back, or removes the status line when there was none.
func (Doc) SetStatusLine ¶
SetStatusLine makes the status line a command. Other keys of the statusLine object, such as padding, stay.
func (Doc) StatusLine ¶
StatusLine is the status line command, and whether the key holds an object (or nothing, or null), which is the only shape setup edits.