# amorph

amorph is a codebase that changes itself through a model and keeps every stated constraint as a law no change may break. In one 20-message session it built 12 of 13 requirements, against 8 or 9 for agents that kept a conversation.

Experiment · d/rksci labs · Published 2026-11-30 · Tags: Autonomous Agents, Lean, Evaluation, Program Synthesis

## No step lands that breaks a law

Every step is checked in Lean against every law, so a change that breaks one never lands and no compaction can drop it. In the session no agent lost a requirement; the gap came from changes the conversation agents refused. Their prompts offered no way to amend a rule, and that confound is still open.

What it is

## A codebase that edits itself, under laws

amorph is an experiment in a codebase that keeps everything about itself as content-addressed code and changes itself by speaking that code through a model. A path is a name and the hash of its content is its address. The evaluator is one of those files, so it can be read like the rest, and a law pins it so that no reply can rewrite it.

Each turn the tree draws a prompt from its own source and puts it to whatever model is wired to one device, `dev/neural`. The reply is run. If it does not check, or any law the tree holds would become false, nothing changes and the reason goes to `dev/stderr`, where the next prompt shows it. A law can be added and is never removed by a step.

How it is built

## Terms, laws and Lean

The tree's own language is a small lambda calculus in s-expressions, with 28 primitives in the kernel and every other word, `map` and `filter` included, a file in the tree. Code that a model writes for a task is Lean 4. An earlier version asked for the homemade Lisp, and nearly every failure was a misplaced parenthesis; in Lean, 8 of 8 words of rising difficulty checked on the first try.

Every file is named by the hash of its content. A cached value is kept under the address of its bytecode with a trace of what it read, so there is no invalidation step.

A claim that must stay true in every tree the step makes. A step that would make one false is refused whole, whoever asked for it.

A reply's code, its new claim and every earlier claim go to one Lean command, run over data drawn from the reply's own address. Testing on generated cases, not proof.

Every model reply is kept under the address of its prompt and committed, so a run that has happened once replays with no model call.

What it did

## Twenty messages, two compactions

Several 2026 preprints report coding agents losing requirements stated earlier in a long session: EvoCode-Bench (arXiv:2605.24110), StaminaBench (arXiv:2606.19613) and SLUMP (arXiv:2603.17104). Two find constraints dropped when the context is compacted. Lost in Context Compaction (arXiv:2608.11242) proposes keeping them apart from the summary, and a study of compaction in frontier agents (arXiv:2610.31778) found the first summary already dropped about a third of a task's anti-cheating rules. A factorial study of CLAUDE.md files (arXiv:2605.10039) found no detectable effect of their structure on compliance. amorph keeps a constraint as a law, outside any context.

The test, pre-registered in the header of `session.sh` and committed before the run, keeps one Lean function, a record search, up to date over 20 user messages. Seven standing rules come early, then features, two traps, one legitimate change of an earlier rule at message 16, and two planted contradictions at messages 12 and 19, where the right reply is `CONFLICT`. After every message a hidden check scores 14 columns, 13 active by the end. A column passes only on a positive witness, so an empty answer fails.

Four arms ran, each in its own copy of the tree, all on Haiku through the Claude CLI. amorph has no conversation: its prompt holds the types, the current code and every law so far, and a reply is a law, an optional amendment of an earlier law with a reason, and the code. plain keeps a conversation that the model summarises after messages 7 and 14. notes adds a notes file the model rewrites and sees verbatim, and tests a Lean test file run against the code every turn.

Figure: Four grids of 20 messages by 14 requirements: amorph fills nearly every stated cell, the three conversation arms leave several rows hollow.

| Arm    | Built, of 13 | Lost | Planted flagged | False flags | Calls | Seconds |
| ------ | ------------ | ---- | --------------- | ----------- | ----- | ------- |
| amorph | 12           | 0    | 2 of 2          | 1           | 21    | 222     |
| plain  | 9            | 0    | 2 of 2          | 3           | 22    | 179     |
| tests  | 9            | 0    | 2 of 2          | 4           | 22    | 300     |
| notes  | 8            | 0    | 2 of 2          | 5           | 24    | 197     |

Against the pre-registration, H1 is supported: amorph ended with no regression and with more columns than each conversation arm. H2, that a conversation arm loses a constraint after a compaction, is not supported. No arm lost any column it had built, and the summaries kept every rule, so this run did not reproduce the loss the preprints report, at this scale of 20 short messages and a function of a few dozen lines. H3 holds for amorph, but every arm flagged both planted contradictions, so it separates nothing.

The gap comes from refused changes. All three conversation arms answered `CONFLICT` to message 10 (never return group 0) and message 16 (a missing score counts as 0); notes and tests refused message 18 as well, and plain let it pass unbuilt. amorph ran each change against every law before deciding, and at message 16 amended the law for message 5, its one amendment and the legitimate one. Every law it kept that has a column to judge it by was weaker than that column, the intended shape for a standing property. It missed message 18's column, and its one false conflict was message 13, where it read "apply the limit as early as you can" as breaking message 6.

The result carries a confound. amorph's prompt offers a way to amend a law; the conversation arms' preamble offers only `CONFLICT`, with no stated way to change earlier behaviour. Part or all of the gap may be that difference in instructions rather than the laws.

## Run 1 failed for two reasons

Session run 1, eight messages and one compaction in 41 calls, is kept with a written diagnosis. plain built 7 of 7. amorph built 1 of 7: the model wrote the law for message 1 as equality with the raw prefix filter, which vetoed every later feature, and no law could be weakened. notes and tests built 3 of 7 on harness bugs. Their section markers were not recognised, so their code never landed, and an empty stub passed three checks vacuously. Run 2 changed the tool and kept the question: laws are asked for as standing properties and may be amended with a reason, a pass needs a positive witness, and the harness reads replies as written.

## A grown library, on held-out tasks

A second pre-registered study, in the header of `study.sh`, grew 20 Lean words on graded maze tasks, 20 of 20 solved in 21 calls, then froze the library and set three arms on 6 harder held-out tasks. Every arm solved 6 of 6: the evolved arm in 7 calls and 153 s, a fresh tree in 8 calls and 195 s, a plain retry loop in 7 calls and 152 s. Both hypotheses failed. The measure sat at its ceiling, and the evolved arm called a grown word in 2 of 6 replies.

A second run showed each word's one-line task description beside its signature. Reuse rose to 4 of 6 replies, and where a reply leaned on several words it was much shorter, farthestCell in 87 characters against 531. Solves stayed at 6 of 6 and calls at 7.

| Task         | Run 1, signatures | Run 2, descriptions                                |
| ------------ | ----------------- | -------------------------------------------------- |
| errand       | pathBetween       | none                                               |
| avoidSet     | none              | none                                               |
| farthestCell | none              | distMap                                            |
| withinSteps  | none              | spread                                             |
| checkpoint   | pathBetween       | joinPaths, pathBetween                             |
| sweep        | none              | deadEndCells, joinPaths, pathToNearest, regionSize |

On tasks a model can already write in one reply, a library saves some typing and nothing else here. An earlier ablation on twelve related maze tasks, one run per arm, showed the cost side: both arms solved 12 of 12, and on the last six the library arm used 57 model seconds and 961 characters against 176 and 3,721 without it.

What is left

## One run each, and an open confound

Every result above is one run, so none is a test of significance. The session's advantage has not been separated from the prompt that offers amendment; a run that gives the conversation arms the same route is the next test. No session yet has been long or heavy enough for compaction to drop a rule in a conversation arm. The library has not been shown to change an outcome on tasks past what one reply can write. Lean claims are tested on generated cases, not proved, and the tree's own reflexes (strength, forgetting) have never been switched off and compared.

A session in which the conversation arms may amend a rule as amorph may, run more than once.

amorph is a d/rksci labs experiment. Every number here is from committed files in [drksci/amorph](https://github.com/drksci/amorph): session/run1 and session/run2 (session.tsv, summary.txt, result.txt, per-arm vectors and amendments), study/run1 and study/run2, and the README's ablation table. Both studies were pre-registered in their scripts' headers before the run. The model was Haiku through the Claude CLI; every reply is kept under the address of its prompt, so each run replays without a call. The plates are redrawn from that data.