This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Adjacent is a local dev-server harness so a developer and a coding agent can share one supervised server instead of fighting for the process. Single Rust binary adj; user-facing daemon runs lazily on first request and proxies *.adj.ac to registered apps.
Names are locked (see ~/.claude/projects/-Users-norton-src-adjacent/memory/project_naming.md):
- Brand: Adjacent, CLI:
adj, domain:*.adj.ac, config file:adjacent.toml, home dir:~/.adjacent/. - Brand split in copy/visuals:
adj.ac+ent(neveradj+ac.ent). The/is the URL path boundary. - Public copy: no "tracer bullets", no "AI agents" (just "agents"). Tagline:
Humans and agents live adjacently.Landing page (revamped 2026-06-09) is a lean positioning page — wordmark + tagline, problem statement, commands, design principles, status, footer. Keep copy tight; the user cuts anything that bloats.
Design contract: see project_solocal_design.md. Decisions to treat as load-bearing: lazy-boot + single-flight, PORT injection (override via port_env), JSONL logs at ~/.adjacent/logs/<name>.log, idle shutdown default-on, never runs as root (privileged ops emit reviewable sudo commands).
Rust toolchain pinned in .tool-versions (rust 1.92.0, nodejs 26.2.0 for the landing page) — asdf install from the repo root.
cargo build— workspace build (binary lands attarget/debug/adj).cargo test— full suite (unit + the integration tests incrates/adj/tests/).cargo test --test proxy— run one integration test file (seecrates/adj/tests/for the others).cargo test <substring>— run individual test functions by name substring.cargo run -- daemon— run the daemon in the foreground. Logs go to stderr viatracing(RUST_LOG=debugfor more).cargo run -- <subcommand>— exercise a CLI command against a running daemon (e.g.cargo run -- list --json).just serve—npx live-serverfor theent/landing page. Checklsof -nP -iTCP:8080 -sTCP:LISTENfirst — the user often already has this running; spinning up a second server demos the exact problem Adjacent solves.
Tests sandbox state via ADJACENT_HOME=<tmpdir> and start their own daemon — no global ~/.adjacent/ pollution. The same env var works for ad-hoc local runs.
Workspace, two crates:
crates/adj— the binary. Subcommands insrc/main.rsdispatch to eitherdaemon::run(long-lived process) orclient::*(one-shot Unix-socket RPC).crates/adj-protocol— wire types (Request/Response/AppState) and stable JSON DTOs (ListEntryDto,StatusDto,LogRecord). The--jsonoutput schema incrates/adj/JSON.mdis the contract; the test suite asserts it.
One process hosts three concurrent tasks:
- Control-plane listener on
~/.adjacent/sock(Unix). Accepts one JSON request per connection, dispatches viadispatch(), writes one JSON response. Each request is line-delimited JSON. - Reverse proxy (
proxy.rs) on127.0.0.1:8080(override withADJACENT_PROXY_PORT;0= kernel-assigned, with the bound port written to~/.adjacent/proxy.port—https.portfor the HTTPS listener — which is how the test sandboxes discover their daemon's ports race-free). Routes byHost: <name>.adj.ac. On first request, lazy-boots the app via a per-nameBootGate(single-flight: concurrent waiters serialize on the same mutex; the first one boots, the rest findRunningon re-check). Crash during boot surfaces as502; timeout as504. - Idle scanner sweeps every 500ms. Apps whose
last_requestis older than theiridle_timeoutget SIGTERM'd viadown_if_idle, which re-checks the timestamp under the supervisor lock to close the request-vs-scanner race (without that re-check, a request landing between snapshot and SIGTERM turns into a spurious 502).
Owns process lifecycle. One Inner mutex covers app state and the reserved_ports set. up():
- Resolves env layers eagerly so a missing
env_filefails before port reservation. - Allocates a free port by binding
127.0.0.1:0, closing, retrying if the kernel reissues a port that's still inreserved_ports(covers the close→bind race window). - Spawns
sh -c <cmd>withprocess_group(0)so SIGTERM/SIGKILL hit the whole tree — not justsh, which would reparent the real dev server to init. - Injects
$PORT(or whateverport_envrenames it to). Env precedence:env_file→[env]table → PORT injection (later wins). - Pipes stdout/stderr to per-stream readers that write JSONL records (
{ts, stream, line}) to~/.adjacent/logs/<name>.log. The on-disk format is JSONL;adj logsprojectslinefor humans,adj logs --jsonstreams the file as-is.
State machine: Stopped ↔ Running { pid, port, started_at } ↔ Crashed { exit_code }. The wait task uses an intentional_stop flag to distinguish a down-driven exit from a real crash.
Polls supervisor state and either TCP-connects (default) or HTTP-GETs health_check_url for a 2xx. Shared by the proxy's lazy-boot path and adj wait-ready. A Crashed state mid-poll short-circuits with ReadinessError::Crashed so the caller doesn't sit on a timeout.
~/.adjacent/registry.toml maps name → path. Registry keys may carry one structural dot: <label>.<name> is a worktree instance (feature-x.site routes at feature-x.site.adj.ac). adj add inside a linked git worktree derives the label from the branch name (--label overrides); adj remove <name> deletes one entry, adj prune deletes every entry whose path is gone, and adj list flags those as stale. App names in adjacent.toml therefore cannot contain dots. The TLS leaf carries a *.<name>.adj.ac SAN per registered base name and re-issues on registry changes.
Per-app config at <path>/adjacent.toml:
name = "site"
cmd = "npm run dev"
port_env = "BIND_PORT" # optional, defaults to PORT
env_file = ".env.local" # optional, dotenv-format (no shell substitution)
[env] # optional, committed-safe overrides on top of env_file
NODE_ENV = "development"
boot_timeout = 90 # seconds, defaults to 60
health_check_url = "/healthz"
idle_timeout = "15m" # or "30s" / "1h" / "off". default 15mAt boot the daemon injects a reserved, daemon-owned ADJ_* namespace into cmd (after
env_file/[env], so these win): ADJ_NAME (routing key), ADJ_HOST (<name>.adj.ac),
and four base URLs — ADJ_URL (https) / ADJ_URL_HTTP (http), clean and assuming the
port-forward, plus ADJ_URL_DIRECT / ADJ_URL_HTTP_DIRECT carrying the daemon's real
listener ports. Lets a
cmd address its own origin, e.g. hugo server --appendPort=false --port $PORT --baseURL $ADJ_URL_HTTP.
Path canonicalization happens client-side in add — the daemon refuses non-absolute paths so it never silently resolves against its own CWD (it may have been launched by launchd from /).
The daemon never executes as root. Privileged work is emitted as commands the user reviews and sudos.
-
adj install-port-forward— prints (never runs) apfctlanchor with twordrrules::80 → :8080and:443 → :8443. The daemon listens on high ports always; this is how:80/:443reach it. -
adj install-ca— generates a local CA: cert at~/.adjacent/ca.crt, private key in the macOS login keychain under the labelAdjacent local CA, marked non-extractable (kSecAttrIsExtractable=false) so ordinary tooling —security export, Keychain Access UI export,SecItemCopyMatching(kSecReturnData=true)— refuses to hand the bytes back. This is a software promise enforced by the Security framework, not a hardware boundary; a determined attacker with the user's login password and framework-level access can probably still pull the bytes out via legacySecKeychainAPIs. Still a meaningful step up from "PEM file at mode 0600" — no cleartext bytes on disk for backup tools orcat ~/.adjacent/ca.keyto scoop up. The cert carries a critical RFC 5280nameConstraintsextension permittingDNS:adj.aconly, so a misused CA cannot mint trusted certs for other domains. Prints thesecurity add-trusted-certcommand. The daemon issues a leaf signed by the CA on next start carrying*.adj.acplus*.<name>.adj.acper registered base name, re-issued when the registry changes (signed through rcgen'sRemoteKeyPairtrait +SecKeyCreateSignature, so the CA private key never enters process memory). Rotating the CA deletes the cached leaf so a fresh one re-issues. -
adj install-ca --reset— removes both halves of the keychain key entry plus the on-disk cert/leaf files. Use for fresh start or test teardown. Prints thesecurity delete-certificatecommand for the trust anchor (sudo, not run for you).Tried Secure Enclave first; SE requires
keychain-access-groupsentitlements that an unsignedcargo-built binary doesn't carry (SecKeyCreateRandomKeyreturnserrSecMissingEntitlement/ OSStatus -34018), so the pivot was non-extractable software ECDSA P-256 in the login keychain. To revisit SE later, codesign the binary withkeychain-access-groupsand addToken::SecureEnclave+Location::DataProtectionKeychainto theGenerateKeyOptionspath incrates/adj/src/tls/keychain.rs.
Alongside the HTTP proxy, the daemon opens an HTTPS listener on :8443 (override ADJACENT_HTTPS_PORT). Both share the same request routing — the per-connection serve loop is generic over the stream type. Startup is best-effort: if either half of the CA is missing (no cert on disk, or no keychain entry under the install's label), the HTTPS task logs at error! and exits while HTTP and the control plane keep serving. Run adj install-ca to opt in.
- Commit messages: no Conventional Commit prefixes ("fix:", "feat:" etc.). Plain descriptive messages.
- PR bodies use
Resolves #N, notCloses #N. git commit <path>, nevergit commit -a— the user keeps ambient working-tree edits intentionally dirty.- Comments describe WHY, not WHAT. The codebase leans heavily on dense block comments above tricky races (boot single-flight, scanner re-check, process-group signaling, port reservation set) — match that style when adding similar code.