Skip to content

Commit e9cdfea

Browse files
authored
chore-update-claude-md-branching-and-common-patterns (#438)
Add branch naming convention, lib.mkForce common pattern.
1 parent b0f7d4d commit e9cdfea

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

CLAUDE.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ nixos-rebuild switch --flake .#spore --target-host root@spore --build-host local
4949

5050
**Checking changes before committing:**
5151
```bash
52+
# NixOS hosts:
5253
nix-flake eval nixosConfigurations.hostname.config.system.build.toplevel.drvPath
54+
# macOS hosts:
55+
nix-flake eval darwinConfigurations.Rhizome.system.drvPath
5356
```
5457
Evaluates a host's configuration without building it. Catches option conflicts and type errors fast — run this after editing any NixOS module or host config.
5558

@@ -79,6 +82,22 @@ Secrets are organized using the principle of least privilege:
7982
- Each host only has access to its own secrets plus admin keys
8083
- Global secrets (if any) are defined in `lib/secrets/default.nix`
8184

85+
**agenix workflow:**
86+
```bash
87+
# Edit an existing secret (must be on a host with access, or have the deploy key):
88+
agenix -e hosts/spore/secrets/some-secret.age
89+
90+
# Add a new secret:
91+
# 1. Add an entry to lib/secrets/<host>.nix with the appropriate publicKeys
92+
# 2. Run: agenix -e hosts/<host>/secrets/<name>.age
93+
# 3. Reference it in the host config via age.secrets.<name>.file
94+
95+
# Rekey all secrets after adding a new host key:
96+
agenix --rekey
97+
```
98+
- Keys are defined in `lib/keys.nix` — each host's key is read from `hosts/<host>/key.pub`
99+
- A new host must have its key added to `lib/keys.nix` and any relevant secrets files before it can decrypt them
100+
82101
## Package and Overlay Management
83102

84103
Custom packages and overlays are organized for clarity:
@@ -90,6 +109,19 @@ Custom packages and overlays are organized for clarity:
90109
## Branching
91110

92111
- Branches should be scoped to a single host whenever possible. This keeps deploys independent and reduces risk of cross-host breakage.
112+
- Branch naming: `host/type-short-slug` for host-scoped changes, `type-short-slug` for top-level changes.
113+
- `host/` is the hostname (e.g. `glyph/`, `spore/`, `Rhizome/`, `zeta/`)
114+
- `type` is one of `feat`, `fix`, `chore`, `refactor`
115+
- The slug should be succinct — 2 to 4 words max (e.g. `fix-gc-options`, not `fix-gc-options-from-base-module-conflicting-definitions`)
116+
- Examples: `spore/fix-gc-options`, `Rhizome/feat-launchd-service`, `chore-update-flake-inputs`, `feat-add-ci-eval`
117+
- Always pass the branch name explicitly to `gt create` — if omitted, Graphite auto-generates one from the commit message and may prepend a user prefix:
118+
```bash
119+
gt create spore/fix-gc-options --message "fix(spore): ..."
120+
```
121+
122+
**Submitting PRs:**
123+
- Title format: `type: short description` — e.g. `fix: spore gc options`, `chore: update CLAUDE.md`, `feat: add ci eval job`
124+
- Description should include a brief summary of what changed and what to test/verify
93125

94126
## Nix Commands
95127

@@ -103,6 +135,37 @@ Never use `nix <subcommand> .#<output>` — the `#` causes permission prompt fai
103135
| `nix run nixpkgs#foo` | `nixpkgs-run foo` |
104136
| `nix shell nixpkgs#foo` | `nixpkgs-shell foo` |
105137

138+
## Common Patterns
139+
140+
**Amending the current branch:**
141+
Use `gt modify` instead of `git commit --amend` to keep the Graphite stack consistent:
142+
```bash
143+
git add <files>
144+
gt modify --no-edit # amend without changing message
145+
gt modify -m "new message" # amend with new message
146+
```
147+
148+
**`lib.mkForce` vs `lib.mkDefault`:**
149+
- `lib.mkForce value` — host wins over any module default. Use when a host must diverge from a shared module.
150+
- `lib.mkDefault value` — module loses to any host override. Use in shared modules to set a default that hosts can freely override without `mkForce`.
151+
152+
**Overriding a shared base module option in a host config:**
153+
Use `lib.mkForce` when a host needs to diverge from a value set in a shared module (e.g. `modules/base/`). Without it, Nix will error on conflicting definitions.
154+
```nix
155+
# modules/base/gc.nix sets nix.gc.dates = "weekly"
156+
# hosts/spore/default.nix overrides it:
157+
nix.gc.dates = lib.mkForce "daily";
158+
```
159+
160+
## Environment Awareness
161+
162+
- Before running commands like `ssh`, `nixos-rebuild`, or anything that targets a specific host, check which host Claude Code is running on (`hostname`) to avoid targeting the current machine unintentionally.
163+
- The current host is typically `glyph` (NixOS desktop) or `Rhizome` (macOS laptop).
164+
165+
## Learning and Memory
166+
167+
- After arriving at a working solution through trial and error, proactively ask whether the finding should be recorded in CLAUDE.md (or Basic Memory) for future sessions.
168+
106169
## Code style
107170

108171
- All files should end with a newline.

0 commit comments

Comments
 (0)