klink
An AI-native control plane for KLayout. It turns a running KLayout GUI into a layout kernel driven by external Python, MCP clients, and AI agents — geometry-first: mark intent on geometry, let algorithms complete the wiring, and decide "done" with structured geometry and LVS, not a screenshot that "looks right". It is an early-stage, experimental open-source project — try it and send feedback.
More than a chat plugin
klink's core method is geometry-first: geometry comes first, you mark intent on it (Port for connectivity, Anchor for routing constraints), routing algorithms complete the wiring, and structured queries plus live LVS decide "done". The human keeps GUI freedom; the agent reads, writes, moves, records, routes, and verifies real geometry.
The geometry-first idea
Mark intent → algorithms route → structured verification. Ports/Anchors are the input to routing; the mechanism layer stays process-agnostic.
Read the core idea → AgentMCP tool surface
klink-mcp exposes the same catalogue to Claude Code, Codex and others — 122 tools across 11 domains, navigated by klink.find_tools.
Structured verification
Routing, LVS, DRC and geometry queries return structured reports. "Done" is ok, overlap/hit counts, LVS match=True — never how a screenshot looks.
A first result in 30 seconds
The public release ships examples that need no private GDS. Run an offline demo first, then connect a live KLayout. Full steps on Quickstart.
python -m pip install klayout-klink
klink init my-chip
cd my-chip
python example_template/nanodevice/ebl_wraparound.py
Install the Python package
The PyPI package brings the klink core + its two bundled Rust kernels; starter demos are copied into your project by klink init, and refreshed later with klink update — your own files are never touched.
Install the KLayout plugin
Copy klink_plugin/ into KLayout's salt dir and restart. The plugin runs 8765 RPC and the 8082 klive display.
Connect an agent
Run python -m klink.mcp, using a profile to select read/write/verify/escape or a specific domain.
The control path
A thin plugin hugs KLayout; the heavy intelligence runs in external Python. The two sides talk only over RPC. Detail on Architecture.
Agent (Claude Code / Codex)
→ MCP server (python -m klink.mcp)
→ klink client (NDJSON over TCP)
→ KLayout plugin (in-process RPC)
RPC: 127.0.0.1:8765+
klive-compat: 127.0.0.1:8082
Sessions are ports, equal peers
Each KLayout window binds a port (8765, 8766…) as a session. No port has a privileged role — you always say which one.
Process purity
klink holds no process constants. Layers, sizes and devices are passed in from your pdk.py; a missing fact returns an instructive error with a next_action.
Interaction capabilities for human + agent
A set of interaction capabilities that let a human and an agent collaborate on one live KLayout. Full detail on Workflows.
SEND selection memory
The toolbar SEND records a selection as a stable id (e.g. sel_0006) so an agent resolves "this area", "that one" — by order not age, journaled and never lost.
One agent, many KLayouts
One MCP bridge drives many KLayout windows; label, resolve, and switch the target session.
Sessions →Cross-session transfer
Two-phase and confirmation-safe: prepare + dry-run on the target, then commit — a wrong target is caught at dry-run.
Transfer →8082 klive display
A drop-in klive replacement: any gdsfactory c.show() hard-coded to localhost:8082 pushes into KLayout unchanged, with a selectable target in multi-session mode.
Record → replay script
Record manual GUI edits and RPC edits into a replayable script, plus a standalone pya variant that runs inside KLayout with no klink.
Escape hatch
exec.python runs controlled pya for what typed RPCs don't cover yet; it still schedules the recorder and layout-diff detection.
Capabilities, by domain
klink is a general geometry-first control plane. Below are some current capabilities grouped by domain, each backed by a runnable example script (all with no private GDS). The project is still early and experimental, so coverage will keep changing. Per-example measured detail on Examples.
EBL nanodevices
Electron-beam-lithography device generation: EBL wraparound, Hall bar, with writefield planning, patches and geometry validation. Offline EBL measures 40 electrodes / 0 violations / 0 overlaps.
See EBL / Hall bar → Neural electrodeNeural electrodes
Parametric neural-electrode probe: pad/via geometry → Ports → corridor anchors → tapered-hybrid routing, self-contained with no GDS. 4 rows: 48 ports / 24 nets / overlap 0.
See neural electrode → New materialsMaterial flake detection
Detect material flakes from a microscope image (needs cv2+numpy), or read a precomputed traces.json, commit them as polygons and derive contact Ports. Built on KlayoutClaw priors.
Silicon photonics
Take an ordinary gdsfactory MZI script into klink in one call; after a GUI drag, one photonics.reroute re-routes optics (incl. sbend / all_angle / dubins) and metal together.
Custom-device digital P&R → LVS
Fit a device from synthetic exemplars, place, detailed-route, verify with live LVS. Measured routed 94/94, LVS match=True, 173 devices; the device-agnostic netlist flow is structdevice.*.
122 tools, 11 domains
83 plugin RPCs + 39 MCP local tools, each with function, parameters and examples. The catalogue is generated from the live plugin's method registry — no hand-maintained list that can drift.
Documentation map
Not sure where to start? Pick a path by your goal.
Quickstart
Install the Python package and KLayout plugin, register the MCP server, get a first offline result.
Install →Core concepts & tutorials
geometry-first, Ports/Anchors, the user-project model, per-domain recipes, verification habits.
Concepts →Interactive workflows
SEND, sessions, cross-window transfer, 8082 klive, record/replay — the collaboration loop.
Workflows →MCP tool reference
All 122 tools across 11 domains: function, parameters, examples.
Reference →Demos explained
8 public demos: function, command, measured numbers, requirements, how to adapt.
Examples →Architecture
Three tiers, the control path, process purity, agent tool design principles, batch RPCs.
Architecture →