Comma Agents
@comma-agents/tuiHooks

useUserConfig

Load and persist user configuration — theme selection with synchronous first-read and async writes.

useUserConfig loads a persisted JSON user config from disk and provides mutators that persist asynchronously. The config is read synchronously on first render so the initial paint always uses the correct theme.

Must be inside <UserConfigContextProvider>.

import { useUserConfig } from "@comma-agents/tui";

const { config, setConfig, updateConfig, configFilePath } = useUserConfig();

config.themeName;          // Current theme name
updateConfig({ themeName: "dracula" });  // Partial update, persists to disk
setConfig({ themeName: "light" });       // Full replace

UserConfig

FieldTypeDescription
themeNameThemeNameName of the active theme

UserConfigContextType

FieldTypeDescription
configUserConfigCurrent config object
setConfig(next: UserConfig) => voidReplace the entire config and persist
updateConfig(patch: Partial<UserConfig>) => voidMerge a partial config and persist
configFilePathstringAbsolute path to the config file on disk

Persistence

Config is saved to a JSON file on disk. The default location is platform-dependent. Writes are deferred via queueMicrotask so disk I/O never blocks the React commit phase. New fields added to the config type are automatically merged in from defaults, so schema changes do not break existing config files.

UserConfigContextProvider accepts an optional configFilePath prop to override the default location.

On this page