Materialize
Materialize is the act of resolving a profile (extends + includes),
merging its files into a single tree, and writing that tree into .claude/
on disk. It’s what c3p use and c3p sync
do after the drift gate clears.
Materialize is atomic: either the swap completes fully or .claude/
stays exactly as it was. There is no half-applied state.
How the atomic swap works
Section titled “How the atomic swap works”- Resolve — walk
extendsandincludes, building a list of every file the active profile contributes and where each came from. - Merge — apply the layering rules (extends and includes) to produce the final byte stream for each path.
- Stage — write the merged tree into a sibling temp directory next to
.claude/(same volume, so the rename in step 5 is atomic). - Backup — move the existing
.claude/aside (kept for the most recent N swaps, configurable; default 3). - Rename —
rename(staging, .claude)— a single POSIXrename(2)/ WindowsMoveFileExswap. Either it happens or it doesn’t. - Update state — record the new active profile, resolve hash, and warnings in the state file.
What you can rely on
Section titled “What you can rely on”- No torn writes — readers never see a half-merged tree.
- Backups — the previous
.claude/is retained until the configured count is exceeded. - A lockfile — only one C3P process can be materializing at a time;
peer attempts get exit code
3(or wait, with--wait). - Project-root
CLAUDE.mdis byte-exact above and below the markers — if a profile manages a section, only the bytes between the<!-- c3p:v1:begin -->/<!-- c3p:v1:end -->markers are touched.
What materialize does not do
Section titled “What materialize does not do”- It does not edit profile source files. (Source-edit propagation is
c3p sync, not materialize.) - It does not consult git. Materialize is a pure file-system operation.
- It does not fix drift on its own — that’s the drift gate’s job, before materialize runs.
See also
Section titled “See also”c3p use— switch active profile, materializec3p sync— re-materialize after a source editc3p doctor— verifies the lockfile, backups, and state-file invariants