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
- Variables
- func ClaudeDirIn(getenv func(string) string, home string) string
- func CodexDirIn(getenv func(string) string, home string) string
- func DirOfEnv(environ []string, name string) string
- func EnvOf(environ []string) func(string) string
- func Unique(dirs ...string) []string
- type Compact
- type Config
- type Store
- func (s *Store) AgentSettings(_ context.Context, p wire.Provider) (wire.AgentSettings, error)
- func (s *Store) ClaudeProxy() (base, key string)
- func (s *Store) CompactOf(p wire.Provider, cwd, model string) Compact
- func (s *Store) FirstRun(p wire.Provider, cwd string) error
- func (s *Store) ForgetClaudeKey() error
- func (s *Store) PatchAgentSettings(_ context.Context, p wire.Provider, rev string, patch wire.AgentSettingsPatch) (wire.AgentSettings, error)
Constants ¶
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 ¶
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
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
CodexDirIn is Codex's home when it runs with this environment: $CODEX_HOME, else <home>/.codex.
func DirOfEnv ¶ added in v0.16.123
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.
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 (*Store) AgentSettings ¶
AgentSettings reads the settings of one CLI.
func (*Store) ClaudeProxy ¶
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 ¶
CompactOf is what an agent of the machine compacts at in a chat of the folder cwd on the model.
func (*Store) FirstRun ¶
FirstRun prepares the CLI of provider p to start in cwd without its first-run screens.
func (*Store) ForgetClaudeKey ¶
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.