agentcfg

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 19 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 agentcfg reads and writes the settings files of the agent CLIs on this machine for the Settings screen of the new interface: Claude Code's settings.json and Codex's config.toml. It is wire.AgentSettingsSource.

The files are the person's and the CLIs' own: a write changes only the keys the patch names, keeps the order of the rest, keeps keys nobody here models, and is refused (a conflict) when the file is not the one the page read. A file that does not read is never overwritten. Secrets never leave: the account is a method, a plan and a name, an environment value that looks like a secret is cut to its tail.

Index

Constants

View Source
const (
	ClaudeDirEnv = "CLAUDE_CONFIG_DIR"
	CodexDirEnv  = "CODEX_HOME"
)

The variables that move the CLIs' folders away from the home. On Coder workspaces and other managed machines they are often set in the person's shell, not in the service that runs the runtime and the machine's agent.

Variables

View Source
var ErrKeyInEnvironment = errors.New("agentcfg: the Claude key is set in the machine's environment")

ErrKeyInEnvironment: the key Claude Code signs in with comes from the machine's environment, not from a file the page may change; signing out cannot erase it.

Functions

func ClaudeDirIn added in v0.16.123

func ClaudeDirIn(getenv func(string) string, home string) string

ClaudeDirIn is the folder Claude Code keeps its state in when it runs with this environment: $CLAUDE_CONFIG_DIR, else <home>/.claude.

func CodexDirIn added in v0.16.123

func CodexDirIn(getenv func(string) string, home string) string

CodexDirIn is Codex's home when it runs with this environment: $CODEX_HOME, else <home>/.codex.

func DirOfEnv added in v0.16.123

func DirOfEnv(environ []string, name string) string

DirOfEnv is the folder an environment variable of a running CLI names, "" when it is not set. A relative value depends on the folder the CLI was started in and is not followed.

func EnvOf added in v0.16.123

func EnvOf(environ []string) func(string) string

EnvOf reads a process's environment (its KEY=value entries, as /proc/<pid>/environ holds them) as os.Getenv does.

func Unique added in v0.16.123

func Unique(dirs ...string) []string

Unique is the folders without repeats and empty ones, in the order given.

Types

type Compact

type Compact struct {
	// Window is the window Claude counts its compaction from (autoCompactWindow), in tokens.
	Window int64
	// At is the tokens Codex compacts at (model_auto_compact_token_limit).
	At int64
}

Compact is what a chat's agent is set to compact at; zero fields: nothing is set.

type Config

type Config struct {
	// Home is the person's home; it is shortened to ~ in the paths the page sees.
	Home string
	// ClaudeDir is $CLAUDE_CONFIG_DIR, else ~/.claude; CodexDir is $CODEX_HOME, else ~/.codex;
	// AntigravityDir is ~/.gemini/antigravity-cli.
	ClaudeDir, CodexDir, AntigravityDir string
	// ClaudeJSON is the file Claude Code keeps its account and servers in: <ClaudeDir>/.claude.json when
	// $CLAUDE_CONFIG_DIR is set, else ~/.claude.json.
	ClaudeJSON string
	// AuthDir is the folder a managed machine keeps Claude's sign-in in (CLAUDE_SECURESTORAGE_CONFIG_DIR of its chats,
	// `auth_directory` of the runtime's config); "" when the CLI keeps its own.
	AuthDir string
	// Getenv reads the environment the agents start in (os.Getenv when nil).
	Getenv func(string) string
}

Config says where the CLIs keep their files; the runtime passes the folders it already uses for them.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store serves the files of one machine.

func New

func New(cfg Config) *Store

New is the store of a machine.

func (*Store) AgentSettings

func (s *Store) AgentSettings(_ context.Context, p wire.Provider) (wire.AgentSettings, error)

AgentSettings reads the settings of one CLI.

func (*Store) ClaudeProxy

func (s *Store) ClaudeProxy() (base, key string)

ClaudeProxy is the one proxy of Claude Code's own settings (env ANTHROPIC_BASE_URL) and the key typed for it (ANTHROPIC_AUTH_TOKEN, else ANTHROPIC_API_KEY); base is "" when none is set.

func (*Store) CompactOf

func (s *Store) CompactOf(p wire.Provider, cwd, model string) Compact

CompactOf is what an agent of the machine compacts at in a chat of the folder cwd on the model.

func (*Store) FirstRun

func (s *Store) FirstRun(p wire.Provider, cwd string) error

FirstRun prepares the CLI of provider p to start in cwd without its first-run screens.

func (*Store) ForgetClaudeKey

func (s *Store) ForgetClaudeKey() error

ForgetClaudeKey is the rest of signing Claude Code out of a key: `claude auth logout` leaves the key in settings.json (env) and in the account file (primaryApiKey), so the page went on saying «вошли по ключу». Both are erased here; a key of the machine's environment stays and is said (ErrKeyInEnvironment).

func (*Store) PatchAgentSettings

func (s *Store) PatchAgentSettings(_ context.Context, p wire.Provider, rev string, patch wire.AgentSettingsPatch) (wire.AgentSettings, error)

PatchAgentSettings changes the keys a patch names, if the file is still the one the page read.

Jump to

Keyboard shortcuts

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