/klayoutclaw:nanodevice_flakedetect_commitfrom klayoutclaw
Inserts detected flake polygons into KLayout as GDS geometry using coordinate transforms from traces.json. Use after combine step completes.
Ships in klayoutclaw. 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.
Pure agent workflow using existing skills and MCP tools. No custom scripts needed.
Scope: This workflow is for pre-gdsalign only. If you have already run
nanodevice_gdsalign, use thecontour_gdscoordinates fromtraces_gds.jsondirectly and do not apply the image-center transform described below.
After the combine step completes. Requires traces.json from <out>/combine/.
create_layout MCP tool if needed)image skill's add_image.py)traces.json produced by the combine stepNOTE: The add_image.py script uses the MCP client which does NOT work from inside a Docker container. Instead, use execute_script directly to load the image:
filepath = "/path/to/full_stack_raw.jpg"
pixel_size = 0.087 # um/px
img = pya.Image(filepath)
img.visible = True
w_um = img.width() * pixel_size
h_um = img.height() * pixel_size
img.set_pixel_width(pixel_size)
img.set_pixel_height(pixel_size)
# Center the image at (0, 0)
img.trans = pya.DCplxTrans(1.0, 0, False, pya.DVector(-w_um / 2.0, -h_um / 2.0))
_layout_view.insert_image(img)
_refresh_view()
result = f"Image loaded: {w_um:.1f} x {h_um:.1f} um, centered at origin"
Load <out>/combine/traces.json. Extract:
image_size_um — [w_um, h_um] for coordinate transformlayer_map — material name → "layer/datatype" stringmaterials — per-material contour lists with contour_um coordinatesContours in traces.json use image-origin coordinates (0,0 at top-left, y-axis pointing down, units in microns).
KLayout uses centered coordinates (0,0 at image center, y-axis pointing up, units in microns).
Transform each point:
kl_x = img_x_um - w_um / 2
kl_y = h_um / 2 - img_y_um
The y-axis sign flip (h_um/2 - img_y_um) is the most common source of errors.
NOTE: The add_polygon.py script uses the MCP client which does NOT work from inside a Docker container. Instead, use execute_script to add polygons directly:
import json
with open("<out>/combine/traces.json") as f:
traces = json.load(f)
w_um, h_um = traces["image_size_um"]
top_cell = _layout.top_cell()
for material in traces["stack"]:
layer_str = traces["layer_map"][material] # e.g. "10/0"
layer_num, dt = [int(x) for x in layer_str.split("/")]
li = _layout.layer(layer_num, dt)
for region in traces["materials"][material]:
pts = []
for x_um, y_um in region["contour_um"]:
kl_x = x_um - w_um / 2.0
kl_y = h_um / 2.0 - y_um # Y-axis flip!
pts.append(pya.DPoint(kl_x, kl_y))
top_cell.shapes(li).insert(pya.DPolygon(pts))
_refresh_view()
result = f"Committed polygons for {len(traces['stack'])} materials"
This is faster and more reliable than calling add_polygon.py for each material, and works from inside Docker containers.
Use the MCP screenshot tool to capture the viewport and visually confirm polygons align with the background image:
mcp__klayoutclaw__screenshot → view the PNG
| Material | Layer | Color |
|---|---|---|
| top_hBN | 10/0 | green |
| graphene | 11/0 | red |
| bottom_hBN | 12/0 | blue-ish |
| graphite | 13/0 | yellow |
These defaults come from traces.json layer_map — always use the values from the JSON, not hardcoded.
kl_y = h_um/2 - img_y_um — forgetting the sign flip puts polygons upside down.add_polygon.py and add_image.py connect to KLayout MCP on localhost, which doesn't work from inside a container. Always use execute_script instead (shown above).execute_script, use _layout.top_cell() to get the current top cell — don't hardcode a cell name.kl_x = x_um - w_um/2 aligns correctly.execute_script with the full polygon — it handles large point arrays efficiently.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
klayout, gds, flake-detection, polygon-insertion, nanodevice, traces-json
18 skills in this plugin
/autocadEdit and export layout geometry in the optional AutoCAD for Mac backend when the user selects AutoCAD or requests native DWG editing through its MCP server./displayklayoutclaw:displayToggle KLayout layer visibility on and off for better visualization. Use this skill when the user wants to show/hide layers, toggle layer display, change layer visibility, or focus on specific layers in KLayout. Also trigger when the user says things like "hide the metal layer", "show only mesa", "turn off layer 3", or wants to isolate layers for inspection./e2e-judgeklayoutclaw:e2e-judgeRun agentic E2E tests for KlayoutClaw. Gives Claude Code natural-language tasks, lets it autonomously choose MCP tools, independently verifies layout state via direct MCP calls, and judges outcomes with gpt-5-mini. Use when the user wants to run agentic tests, validate KlayoutClaw, or benchmark agent performance./geometryklayoutclaw:geometryCreate geometry in KLayout via MCP — rectangles, polygons, paths, cells, and cell instances. Use this skill whenever the user wants to draw, add, or create shapes/geometry/structures in KLayout, even if they don't say "geometry" explicitly. Trigger on phrases like "draw a rectangle", "add a polygon", "create a cell", "place an instance", "make a shape", or any layout/chip/mask design geometry task./imageklayoutclaw:imageLoad a reference image (microscope photo, optical image, SEM) into KLayout as a background overlay for design alignment. Use this skill whenever the user wants to load an image, add a background image, overlay a microscope photo, import a reference picture, align to a photo, or trace over an image. Also trigger when the user says "load this image", "use this photo as reference", "overlay the microscope image", or needs to position/scale/remove background images./klayout_gds_importImport a GDS file into the current KLayout layout, flatten hierarchy, and merge into a single top cell. Use this instead of raw Layout.read() which leaves orphaned cell indices and multi-top-cell states.npx claudepluginhub caidish/klayoutclaw --plugin klayoutclawOther plugins' skills for the same job