CLI — API reference¶
State paths¶
data_dir
¶
Return the mait-code data directory.
Delegates to :func:mait_code.config.data_dir, the single source of
truth for this resolution (honours $MAIT_CODE_DATA_DIR; otherwise
~/.claude/mait-code-data).
mait_code_config_dir
¶
Return the directory holding mait-code's configuration.
Houses the settings file. $XDG_CONFIG_HOME/mait-code by default;
honours $XDG_CONFIG_HOME overrides via :func:xdg_config_home.
mait_code_log_dir
¶
Return the directory holding mait-code's log files.
$XDG_STATE_HOME/mait-code by default; honours $XDG_STATE_HOME
overrides via :func:xdg_state_home.
mait_code_state_dir
¶
Return the directory holding mait-code's persistent data.
Houses the install record. $XDG_DATA_HOME/mait-code by default;
honours $XDG_DATA_HOME overrides via :func:xdg_data_home.
xdg_config_home
¶
Return the XDG config home directory.
Honours $XDG_CONFIG_HOME when set to a non-empty value; otherwise
falls back to ~/.config per the XDG Base Directory Spec.
xdg_data_home
¶
Return the XDG data home directory.
Honours $XDG_DATA_HOME when set to a non-empty value; otherwise
falls back to ~/.local/share per the XDG Base Directory Spec.
xdg_state_home
¶
Return the XDG state home directory.
Honours $XDG_STATE_HOME when set to a non-empty value; otherwise
falls back to ~/.local/state per the XDG Base Directory Spec.
Install record¶
InstallRecord
dataclass
¶
InstallRecord(
source_dir: str,
first_installed_at: str,
updated_at: str,
schema_version: int = SCHEMA_VERSION,
)
Persisted state about a mait-code install.
| ATTRIBUTE | DESCRIPTION |
|---|---|
source_dir |
Absolute path to the cloned source tree.
TYPE:
|
first_installed_at |
ISO 8601 UTC timestamp of the first install.
Frozen at install time and preserved across every
TYPE:
|
updated_at |
ISO 8601 UTC timestamp of the most recent
install / update. Refreshed on every
TYPE:
|
schema_version |
Format version of this record. See
:data:
TYPE:
|
new
classmethod
¶
new(
*,
source_dir: Path | str,
first_installed_at: str | None = None,
) -> InstallRecord
Construct a record stamped with the current UTC time.
| PARAMETER | DESCRIPTION |
|---|---|
source_dir
|
The cloned source tree.
TYPE:
|
first_installed_at
|
Preserve an earlier first-install
timestamp (passed by
TYPE:
|
RecordError
¶
Bases: Exception
Raised when the install record is missing, malformed, or from a schema version this binary doesn't understand.
read_record
¶
read_record(*, path: Path | None = None) -> InstallRecord
Read the install record from disk.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Override source path (defaults to
:func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
InstallRecord
|
The deserialised :class: |
| RAISES | DESCRIPTION |
|---|---|
RecordError
|
If the file is missing, malformed JSON, missing a
required field, or has a |
write_record
¶
write_record(
record: InstallRecord, *, path: Path | None = None
) -> Path
Persist record to disk, creating parent directories as needed.
| PARAMETER | DESCRIPTION |
|---|---|
record
|
The :class:
TYPE:
|
path
|
Override target path (defaults to
:func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The path the record was written to. |
Install flow¶
EMBEDDING_PROVIDERS
module-attribute
¶
The valid values for --embedding-provider.
InstallSummary
¶
InstallSummary(
*,
record: InstallRecord,
claude_md: SymlinkResult,
skills: SymlinkResult,
agents: SymlinkResult,
templates_copied: list[str],
templates_upgraded: list[str],
memory_md_created: bool,
settings_path: Path,
)
What :func:install produces — used by the CLI to render output.
Update flow¶
UpdateSummary
¶
UpdateSummary(
*,
record: InstallRecord,
fetched: bool,
landed_on: str,
reinstalled: bool,
installed_version: str | None,
claude_md: SymlinkResult,
skills: SymlinkResult,
agents: SymlinkResult,
templates_copied: list[str],
templates_upgraded: list[str],
settings_path: Path,
)
What :func:update produces — used by the CLI for output.
Uninstall flow¶
UninstallSummary
¶
UninstallSummary(
*,
had_record: bool,
claude_md_removed: bool,
skills_removed: list[Path],
agents_removed: list[Path],
settings_cleaned: bool,
uv_tool_uninstalled: bool,
data_dir_removed: bool,
warnings: list[str],
)
Outcome of an uninstall — used by the CLI for output.
Status & doctor¶
Check
dataclass
¶
A single diagnostic outcome.
DoctorReport
dataclass
¶
DoctorReport(checks: list[Check], fixes_applied: list[str])
All diagnostic outcomes for one doctor run.
Status
dataclass
¶
Status(
record_present: bool = False,
source_dir: str | None = None,
version: str | None = None,
embedding_provider: str | None = None,
first_installed_at: str | None = None,
updated_at: str | None = None,
record_error: str | None = None,
claude_md_path: str | None = None,
claude_md_target: str | None = None,
claude_md_is_symlink: bool = False,
skills_linked: int = 0,
skills_total: int = 0,
agents_linked: int = 0,
agents_total: int = 0,
hooks_registered: list[str] = list(),
data_dir_path: str | None = None,
data_dir_size_bytes: int = 0,
has_soul_document: bool = False,
has_user_context: bool = False,
has_memory_md: bool = False,
binary_path: str | None = None,
)
Snapshot of the current mait-code install state.
Symlinks¶
SymlinkResult
dataclass
¶
SymlinkResult(
created: list[Path] = list(),
already_linked: list[Path] = list(),
updated: list[Path] = list(),
backed_up: list[Path] = list(),
)
Outcome summary returned by the symlink helpers.
| ATTRIBUTE | DESCRIPTION |
|---|---|
created |
Links that did not exist before this call.
TYPE:
|
already_linked |
Links that already pointed at the correct target.
TYPE:
|
updated |
Links that existed but pointed somewhere stale, now repointed.
TYPE:
|
backed_up |
Existing non-symlink files renamed to
TYPE:
|
remove_agent_symlinks
¶
Remove every agent symlink under <claude_dir>/agents/ that
points into source_dir. Returns the list of paths removed.
remove_claude_md_symlink
¶
Remove the CLAUDE.md symlink if it points into source_dir.
Restores CLAUDE.md.backup to CLAUDE.md if the backup exists.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
remove_skill_symlinks
¶
Remove every skill symlink under <claude_dir>/skills/ that
points into source_dir. Returns the list of paths removed.
symlink_agents
¶
symlink_agents(
source_dir: Path, claude_dir: Path
) -> SymlinkResult
Symlink every agents/<file> into <claude_dir>/agents/.
No-op if source_dir/agents is missing. .gitkeep placeholders
are ignored. Agents are individual files, not directories.
symlink_claude_md
¶
symlink_claude_md(
source_dir: Path, claude_dir: Path
) -> SymlinkResult
Symlink config/CLAUDE.md to <claude_dir>/CLAUDE.md.
If a non-symlink CLAUDE.md already exists at the target, it is
renamed to CLAUDE.md.backup first (preserving the user's
pre-existing config).
| PARAMETER | DESCRIPTION |
|---|---|
source_dir
|
Absolute path to the cloned source tree.
TYPE:
|
claude_dir
|
The Claude Code config dir (typically
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
A
|
class:
TYPE:
|
symlink_skills
¶
symlink_skills(
source_dir: Path, claude_dir: Path
) -> SymlinkResult
Symlink every skills/<name>/ directory into <claude_dir>/skills/.
No-op if source_dir/skills is missing. .gitkeep placeholders
are ignored.
Settings¶
merge_settings
¶
merge_settings(
source: dict[str, Any],
dest: dict[str, Any],
*,
user_settings: dict[str, str],
) -> dict[str, Any]
Merge mait-code's settings into a user's existing settings.
Returns a new dict; does not mutate either input. The merge replaces
mait-code-owned hook entries and MCP servers with the source's
versions, then propagates all user settings as MAIT_CODE_*
environment variables. Other user keys are preserved verbatim.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The
TYPE:
|
dest
|
The user's existing
TYPE:
|
user_settings
|
Flat
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
The merged settings dict ready to write back. |
read_settings_file
¶
Read a settings.json. Returns {} if missing or unparseable.
unmerge_settings
¶
Strip mait-code-owned entries from a settings dict.
Hook entries are identified by any inner command starting with
:data:MAIT_CODE_HOOK_PREFIX. MCP servers are removed by name from
:data:MAIT_CODE_MCP_SERVERS. The
MAIT_CODE_EMBEDDING_PROVIDER env entry is removed. Empty
top-level sections are dropped.
| PARAMETER | DESCRIPTION |
|---|---|
settings
|
The current on-disk settings dict.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
A new dict with mait-code's footprint removed. |
write_settings_file
¶
Write settings to path atomically with a trailing newline.
Uses a tempfile + os.replace so a crash mid-write can't leave
half a JSON file on disk.
Editable settings¶
ApplyOutcome
dataclass
¶
ApplyOutcome(
key: str,
old_value: str,
new_value: str,
followup: str | None,
followup_done: bool,
warnings: list[str] = list(),
)
The result of a successful :func:apply_setting call.
| ATTRIBUTE | DESCRIPTION |
|---|---|
key |
The setting that was changed.
TYPE:
|
old_value |
Its resolved value before the change.
TYPE:
|
new_value |
The value written to the settings file.
TYPE:
|
followup |
The required follow-up —
TYPE:
|
followup_done |
TYPE:
|
warnings |
Human-readable warnings (e.g. a shell export still shadows the change).
TYPE:
|
apply_setting
¶
apply_setting(
key: str,
value: str,
*,
reindex: bool | None = None,
move_data: bool | None = None,
confirm: Callable[[str], bool] | None = None,
) -> ApplyOutcome
Validate, persist and enforce a single setting change.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Kebab-case setting key (e.g.
TYPE:
|
value
|
The new value, as a string.
TYPE:
|
reindex
|
For a migration key, whether to re-embed now.
TYPE:
|
move_data
|
For
TYPE:
|
confirm
|
A yes/no prompt used by the interactive editor to decide a
follow-up when the corresponding flag is
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
An
|
class:
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SettingError
|
The key is unknown, derived (read-only), a single scoring weight, or the value fails validation; or a required follow-up decision was not supplied. |
Entry point¶
app
module-attribute
¶
app = Typer(
name="mait-code",
help="mait-code install-lifecycle CLI.",
pretty_exceptions_enable=False,
add_completion=False,
)