/engineering-practices:code-lawfrom engineering-practices
Use when writing or changing code in any language. Not for prose, docs-only, or config-only changes.
Ships in engineering-practices. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The craft law for code. AGENTS.md keeps the law whose violation is
unrecoverable — boundary, secrets, publish, done-claims.
This skill carries the law whose violation the harness and behavior-first
verification catch.
A property you want held is made unwritable first, detected second. Before reaching for any check, shape the code so the defect cannot be written: a type the wrong value cannot inhabit, visibility that hides the wrong call, a module boundary, the invariant kept with the state it protects, a capability that only the authorized scope can obtain. Correct types are the proof. They need no checker, fixture, or mutation run to show that they hold. Choose this even when a check would be quicker to add today.
Where construction cannot hold a property, a sentence saying "be
deterministic" still changes nothing; a floor that reddens on a violation is
what holds. A floor is a runner setting where one exists (network off,
parallel random order), one-off evidence where it needs judgment, and a
permanent test only when it meets the bar in testing-best-practices.
What construction cannot hold goes to the cheapest existing check that can express it: the compiler, then rules an existing linter already ships, turned on and configured, then a behavior test. Craft rules a mainstream linter or compiler already checks (function length, complexity, warnings as errors, unchecked results, unused values) are enforced through that tool's configuration. A project never writes its own checks over its repository, whether they read source or artifacts such as schemas, manifests, plans, and docs: no analyzer scripts, linter plugins, custom rule files, or checkers that re-judge an artifact. Data that crosses a boundary has one typed definition that each reader parses at its boundary; its test feeds vectors written from the spec through the product's own parser. A second hand-written interpreter of the same data is a duplicate, not independence. A finding that something is not typed is answered with a type. A check that only confirms a file or string changed prevents no defect and is not added. When no rung can hold an invariant, because the defect is rare, hard to enforce, or impossible to catch, a waiver comment at the site says it is unchecked; it does not become a review deliberation or a contrived example. The waiver is the last rung, never a shortcut past a redesign. A recurring finding is answered by a redesign that makes its class unwritable. Retire a check when its defect can no longer be written or another check covers it.
new, v2, fixed, updated,
refactored), or the author's reasoning. When a plain form and a clever
form are both correct, the plain form ships.ifs up and fors down — parents own control flow and
state, leaves stay pure. Every branch accounts for its complement: a guard
clause is right for an exceptional path or short case when the guard itself
handles or asserts the negative space; use else when complementary
branches are both core logic; an if whose other case nothing handles,
asserts, or rules out by type is the defect. Break up nested control flow
and mixed boolean expressions into named decisions.testing-best-practices defines them, are part of the migration.RPC are useful when a
future reader in the domain will understand them; expand obscure or local
abbreviations. Name booleans positively, use long-form flags, and put units and
qualifiers last by descending significance (latency_ms_max).agent-operability. Its inspect/plan/apply/verify contract is the public
expression of this skill's deterministic, idempotent, atomic, observable,
evented, and contextual properties—not a second implementation path.Security-relevant code is written and reviewed against a stated threat model. A bug is a vulnerability only when it lets an actor do something they could not already do. Unless the project's SPEC says otherwise, the default model is:
Hosts are single-tenant. Shared hosts, group-writable package prefixes (Linuxbrew), permissive ACLs, and other weaker setups a user chooses are that user's risk and a documented limitation, not a design input. Do not add ownership, mode, or parent-chain checks whose only purpose is to stop local accounts.
A project tightens the default in its SPEC when the software crosses a local privilege boundary: setuid programs or root daemons, multi-tenant services, or anything acting for a less-privileged local principal. The SPEC names the added actors, and the rest of the default stands.
A review finding that needs a trusted actor is answered by citing the model. It does not block, does not count as a second instance of a defect class, and needs no waiver. The driver may still take a trivial in-scope fix as ordinary hardening. The model itself can be challenged: a reviewer who argues it is wrong for the project takes that to the human.
Apply each property where its failure mode exists; non-applicability needs no waiver. Builds and deterministic test harnesses owe determinism, hermeticity, and isolation. Retried effects, reconcilers, and at-least-once consumers owe idempotency. Operations that can expose partial state owe atomicity. Side- effecting and live surfaces owe observability. Async coordination should be evented, and authority-bearing effects should be contextual. When an applicable property cannot hold, carry a waiver.
Sources of drift: wall clock, unseeded randomness, UUIDs, map and set
iteration order, readdir order, thread scheduling, locale, timezone, hash
seeds. The fix is always the same shape: inject the clock, the seed, the id
generator, the scheduler. Never reach for them ambiently.
Floor: two checks, and conflating them is the common mistake. Repeatability — run twice with the same seed and diff; any difference is nondeterminism. Order-independence — vary only what must not matter (runner shuffle seed, thread scheduling, map iteration order) and assert the result is unchanged. A seeded algorithm legitimately produces different output under a different algorithm seed; that seed is an input, so changing it proves nothing. For engines with a fixed input set, a seeded simulator whose emitted trajectory is compared against a golden run.
Failures: tests that reach the network, tools resolved off PATH, absolute
paths, implicit environment variables, host state. Determinism says the same
inputs give the same output; hermeticity says the inputs are all declared.
Reproducible = hermetic + deterministic.
Floor: run with the network off, a scrubbed environment, and a foreign
$HOME.
Three shapes people conflate: the idempotent operation (f(f(x)) == f(x)),
the convergent reconciliation (desired state, applied to a fixpoint), and
exactly-once effects via an idempotency key. Its sibling is atomic:
idempotency covers the re-run, atomicity covers the interrupted run —
write-temp-then-rename, all-or-nothing apply. Neither alone is crash-safe.
Floor: run it twice; assert the second run is a no-op and the diff is empty. Then kill it mid-apply and run it again.
Own tmpdir, own port, own database, own fixtures. Distinct from hermetic: hermetic is no external dependence, isolated is no inter-instance interference. A flake that root-causes to shared state between tests is an isolation defect, not a flake.
Floor: run the suite in parallel and in random order.
Emit structured fields rather than prose-only log lines, with enough context to identify the failing operation and state.
Floor: cause the failure, then diagnose it using only the emitted logs, metrics, and traces — without re-running and without adding instrumentation.
Wait on a condition, not a duration. A duration-only sleep used as proof that a condition now holds is the defect. Bounded backoff before rechecking a condition is valid when no event source exists; the condition and deadline, never elapsed time alone, decide success. Two pairings matter more than the property itself:
Floor: reject duration-only success; assert the condition and a deadline. Where polling is unavoidable, perturb the backoff and prove the same terminal state.
A side-effecting function receives the context of the event that authorizes it. One structure does four jobs: capability (what this call may do), scope (deadline and cancellation), provenance (which event, on whose behalf), and the fields its logs and spans carry. "Dictates the possibilities" is the load-bearing part — the argument shape should make illegal effects unrepresentable, which is types-first applied to effects and authority rather than to data.
Floor: one assertion per job the context does, and the first is the one usually missing. Capability — construct a context that withholds an authority and assert the call fails rather than reaching for an ambient fallback; without this, code that kept its ambient authority passes every other check. Scope — assert cancellation propagates to the leaf. Provenance — assert every record on the path carries the correlation id.
An instance that cannot hold a property, or an invariant no rung can hold, carries a waiver comment naming the property or invariant, why this instance can't hold it or why holding it costs more than the defect could, and whether it is debt or a permanent exemption. For an invariant, the reason names the design that would make the defect unwritable and why it does not fit here. Debt names what would remove it.
// WAIVER(<property or invariant>): <why this instance cannot hold it, or why it is not worth holding>. <Debt — removed by X | Permanent — X makes it impossible.>
The WAIVER( tag is literal in every language's comment syntax, so one search
lists every waiver in a project. A waiver is written prose a maintainer can evaluate, never a suppression flag.
A waiver whose reason a redesign within scope would remove is a defect: ship
the redesign instead. The same invariant waived at a second site means its
class needs the redesign. A waiver list that grows without its debt entries
shrinking means the property was stated too strongly — weaken the property,
don't grow the list.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alleneubank/agent-profile --plugin engineering-practices28 skills in this plugin
/agent-browserUse when driving a browser the agent owns through the agent-browser CLI — opening pages, clicking and filling by snapshot refs, screenshots, testing a web app, or extracting data from a rendered page./agent-deviceUse when driving an iOS, Android, macOS, or TV app through the agent-device CLI — opening an app on a simulator, emulator, or device, tapping and filling by snapshot refs, capturing screenshots, logs, or recordings, or replaying a scripted flow./agent-operabilityUse when designing or changing a CLI, API, control plane, or automation surface that an agent must inspect, operate, and verify safely.