settings

package
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

View Source
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.

View Source
var ErrChanged = errors.New("changed while it was being edited")

ErrChanged says the file changed while setup worked on it.

View Source
var ErrDuplicate = errors.New("has a duplicate key")

ErrDuplicate says an object has the same key twice.

Functions

func Backup

func Backup(path string, content []byte, now time.Time) (string, error)

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 Ours

func Ours(command string) bool

Ours reports whether a command is a sitrep status line: it ends in the tag.

func SplitBOM

func SplitBOM(b []byte) (bom string, rest []byte)

SplitBOM takes a leading byte order mark off, so that the rest can be parsed and edited.

func Verify

func Verify(before, after Doc, command string) error

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

func Write(path string, d Doc, original []byte) error

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 New

func New() Doc

New is an empty settings file.

func Parse

func Parse(data []byte) (Doc, error)

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 Read

func Read(path string) (Doc, bool, error)

Read reads a settings file through any link. It reports whether the file exists.

func (Doc) HookCommands

func (d Doc) HookCommands() []string

HookCommands lists the commands of every hook of every event.

func (Doc) RestoreStatusLine

func (d Doc) RestoreStatusLine(upstream string) (Doc, error)

RestoreStatusLine puts the upstream command back, or removes the status line when there was none.

func (Doc) SetStatusLine

func (d Doc) SetStatusLine(command string) (Doc, error)

SetStatusLine makes the status line a command. Other keys of the statusLine object, such as padding, stay.

func (Doc) StatusLine

func (d Doc) StatusLine() (command string, editable bool)

StatusLine is the status line command, and whether the key holds an object (or nothing, or null), which is the only shape setup edits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL