Run every claude the loop starts in a Claude home generated outside the clone
CI / tests (pull_request) Successful in 4m45s

This commit is contained in:
2026-12-04 01:07:03 +01:00
parent 2460b9e132
commit 0203a8e0b3
48 changed files with 703 additions and 369 deletions
+22 -5
View File
@@ -10,7 +10,7 @@ RELEASE_ROOT = pathlib.Path(__file__).resolve().parents[2]
# Each folder below is named relative to the person's home folder.
# The Claude home: Claude Code's own folder, with its settings and transcripts. A release is deployed into it, so its CLAUDE.md, rules/ and agents/ are read from it.
# The person's own Claude home. No claude the loop starts runs there, and the setup doesn't read or write it: its name is for prose, and for the rule that keeps an agent out of its `.env`.
CLAUDE_HOME = ".claude"
# The name of the setup's own folder, in the config home and in the state home.
SETUP = "build-release"
@@ -20,6 +20,11 @@ XDG_CONFIG_HOME = "XDG_CONFIG_HOME"
# The state home, which holds the state folder, unless the variable XDG_STATE_HOME names another.
STATE_HOME = ".local/state"
XDG_STATE_HOME = "XDG_STATE_HOME"
# The data home, which holds the data folder, unless the variable XDG_DATA_HOME names another.
DATA_HOME = ".local/share"
XDG_DATA_HOME = "XDG_DATA_HOME"
# The variable that names the home a claude runs in, in place of the person's own.
CLAUDE_CONFIG_DIR = "CLAUDE_CONFIG_DIR"
# Only a claude started through this has the tools on PATH. One a person starts by hand lacks them, as their shell does: the plan keeps short names such as `wait-for` out of a person's shell. README.md → Tools says how to call a tool there.
@@ -44,21 +49,33 @@ def state_folder(env: Mapping[str, str], home: pathlib.Path) -> pathlib.Path:
return xdg_folder(env.get(XDG_STATE_HOME), home / STATE_HOME) / SETUP
def claude_home(env: Mapping[str, str], home: pathlib.Path) -> pathlib.Path:
"""The loop's Claude home, which claude_home.home builds in the data folder: every claude the loop starts keeps its settings, plugins, sign-in and transcripts there."""
# The data folder holds what the tools generate and can generate again, so it needs no backup.
return xdg_folder(env.get(XDG_DATA_HOME), home / DATA_HOME) / SETUP / "claude-home"
def in_claude_home(env: Mapping[str, str], home: pathlib.Path) -> dict[str, str]:
"""env with the loop's Claude home as the home a claude started in it runs in."""
return {**env, CLAUDE_CONFIG_DIR: str(claude_home(env, home))}
# The XDG Base Directory Specification calls a relative path in one of its variables invalid, to be ignored: https://specifications.freedesktop.org/basedir-spec/latest/
def xdg_folder(named: str | None, default: pathlib.Path) -> pathlib.Path:
return pathlib.Path(named) if named and os.path.isabs(named) else default
def without_xdg_folders(env: Mapping[str, str]) -> dict[str, str]:
"""env without the person's own config and state folders, so that both lie under the home folder a caller names."""
return {name: value for name, value in env.items() if name not in (XDG_CONFIG_HOME, XDG_STATE_HOME)}
"""env without the person's own config, state and data folders, so that each lies under the home folder a caller names."""
return {name: value for name, value in env.items() if name not in (XDG_CONFIG_HOME, XDG_STATE_HOME, XDG_DATA_HOME)}
@dataclasses.dataclass(frozen=True)
class Paths:
claude_code_transcripts: pathlib.Path
# The loop's Claude home, whose CLAUDE.md, rules/ and agents/ are links into the release root.
claude_dir: pathlib.Path
# The development clone of this setup, where a change to it is made: claude_dir holds only a release, docs/decisions.md → `deploy:`.
# The development clone of this setup, where a change to it is made.
config_clone: pathlib.Path
config_folder: pathlib.Path
home: pathlib.Path
@@ -68,7 +85,7 @@ class Paths:
def paths_from(home: pathlib.Path, env: Mapping[str, str]) -> Paths:
claude = home / CLAUDE_HOME
claude = claude_home(env, home)
config = config_folder(env, home)
return Paths(
claude_code_transcripts=claude / "projects",