# The Coding Law — a hash to start, a hash to commit

Two agents editing the same file from the same version produce two individually valid commits and one silently destroyed piece of work. Claiming a file says you are working there; it does not say what text you are working from. The version you read is the fact that makes a collision detectable, so it must be on the record before the first edit and checked again before the commit.

## The two calls

```bash
# before your first edit
curl -s -X POST https://miscsubjects.com/api/coding-law/start \
  -H 'content-type: application/json' \
  -d '{"agent":"claude:7d88e44e","intent":"add the ledger thread to every article",
       "files":[{"path":"functions/a/[slug].js","base_sha":"<shasum -a 256 of what you read>"}]}'

# immediately before git commit
curl -s -X POST https://miscsubjects.com/api/coding-law/commit \
  -H 'content-type: application/json' \
  -d '{"lease_id":"lease_…","files":[{"path":"functions/a/[slug].js","new_sha":"<shasum -a 256 now>"}]}'
```

COMMITTED means the version you read is still the head. COMMITTED_FORK means someone moved it while you worked: your row names theirs as its parent, both stay in the chain, and you merge the bytes in git. Either way you commit and carry on — nothing here waits.

## The law

### The lease

**CL01 · Take a hash before you touch anything**

Before the first edit of a session ALWAYS declare every file you will change and the sha256 of each as you just read it, via POST /api/coding-law/start. A session that edits before it declares has no base version on the record.

**CL02 · The hash is of what you read**

base_sha is ALWAYS the file at the moment of the lease. NEVER the file after your edit, NEVER as you remember it, NEVER HEAD. IF you have not read the file this session THEN you may not edit it.

**CL03 · Late leasing is legal and weaker**

IF you did not open a lease at the start THEN open it anyway before commit. A late lease detects a collision but NEVER prevents one.

### The commit

**CL04 · Take a hash before you commit**

Immediately before git commit ALWAYS submit the sha256 of every leased file as you are leaving it. All paths clear or nothing is recorded.

**CL05 · A refusal is the law working**

IF the commit answers COMMITTED_FORK THEN the head moved under you: your commit is recorded as a fork naming what it diverged from, both rows stay in the chain, and you merge the bytes in git the way you always would. You do not wait, you do not re-lease, you do not redo the work.

**CL06 · The chain is the evidence**

Every lease and commit is ALWAYS a row naming who, which files, which base, which result and when.

### Scope

**CL07 · It binds anything that ships**

ALWAYS enforced on functions/, scripts/, migrations/, workers/, apps-script/, public/, .claude/skills/, .agents/skills/, schema.sql and wrangler.toml. Articles are governed by the write path's own stale-body refusal.

**CL08 · It binds every agent**

ALWAYS binds anything that edits this repository, including the agent that wrote it. The deploy gate checks the files, NEVER the claimed identity.

### Concurrency

**CL09 · Never move another agent's working tree**

NEVER stash, reset, checkout or revert a file you did not change. IF a file you do not own blocks your deploy THEN wait for it or ship from a clean clone.

**CL10 · A commit is not the change until the blob says so**

After committing ALWAYS read the blob back from HEAD and from origin/main and confirm the marker. IF hooks revert your work THEN commit with --no-verify and run the gates yourself.

**CL11 · Never let a rebase resolve a shared-file conflict**

ALWAYS push without rebasing when the tree is level. IF a rebase is unavoidable THEN verify the blob afterwards.

**CL12 · Stage by path**

ALWAYS name every path you commit. NEVER use git add -A.

### Reporting

**CL13 · Every response ends with OUTSTANDING**

The last thing in every report is ALWAYS a block headed OUTSTANDING containing a numbered list or the single word none. NEVER implied in prose, NEVER buried, NEVER omitted.

**CL14 · Say what is true now**

ALWAYS report the state of the system. NEVER the sequence of attempts. IF a fact does not change what the owner does next THEN cut it.

**CL15 · Links first**

ALWAYS open with the addresses a person can click. NEVER describe a surface without its URL. Deployed is NEVER a result; a 200 at a named address is.

### Obligation

**CL16 · The deploy is where it is felt**

check-coding-law.mjs ALWAYS runs in the pre phase of every deploy and fails the ship on a changed file with no committed lease.

**CL17 · Never weaken the gate**

IF the gate refuses your work THEN the artifact is wrong. NEVER edit the checker, NEVER add an exemption for your paths, NEVER set a bypass.

## Why

Every agent that edits this repository declares the exact version of each file it read before editing, and declares the version it is leaving behind before committing. The server refuses any commit whose declared base is no longer the newest committed version of that file, because that commit was about to erase another agent's work.

Canonical object: `functions/_lib/coding_law_object.js`. Live: https://miscsubjects.com/a/coding-law
