/tckit:tc-write-stfrom tckit
Writes and modifies Structured Text (ST) code in TwinCAT 3 projects via TcKit MCP tools. Handles POU creation, method/property editing, variable addition, and enforces naming conventions and error propagation patterns.
Ships in tckit. 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.
Read when SKILL.md points to them.
Follow this procedure every time you produce ST that will be written to the project.
These TcKit writer tools go through the selected writer backend (the XAE Automation Interface by default on Windows; a deterministic on-disk XML writer elsewhere or when TCKIT_WRITER=xml), which keeps GUIDs and project cross-references consistent. Use them in place of Edit/Write on .TcPOU or .plcproj files.
| Request | Tool |
|---|---|
| Tweak one line in a method / action / property body | UpdateMethodBodyPatch(pou, method, old, new) |
Tweak one line in the POU's own declaration block (FB-level VAR) | UpdatePouDeclarationPatch(pou, old, new) |
| Tweak one line in the POU's own cyclic body (FB / PRG implementation) | UpdatePouImplementationPatch(pou, old, new) |
Add one variable to a VAR_INPUT / VAR_OUTPUT / VAR etc. scope | AddVariable(pou, scope, declaration, item?) |
| Rewrite a method / action / property body | UpdateMethodBody(pou, method, code) |
| Rewrite the POU's own declaration block | UpdatePouDeclaration(pou, code) |
| Rewrite the POU's own cyclic body (FB / PRG implementation) | UpdatePouImplementation(pou, code) |
| Add a brand-new method to an existing POU | AddMethod(pou, method_name, code) |
| Add a brand-new property to an existing POU (Get, Set, or both) | AddProperty(pou, name, return_type, getter_code?, setter_code?) |
| Add a brand-new POU (FB / function / program / interface) | AddPou(name, pou_type, code) |
Add a brand-new GVL (VAR_GLOBAL declarations) | AddGvl(name, code) |
| Add a brand-new DUT (struct, enum, or union) | `AddDut(name, code, dut_kind="struct" |
| Create a brand-new PLC project | CreateProject(name, path) |
| Open / re-open a TwinCAT solution in XAE | OpenProject(solution_path) |
| Read the current item body before deciding on a patch anchor | GetPouItem(pou, item) (reader) |
Read just the FB-level VAR block before AddVariable | GetPouDeclaration(pou) (reader) |
FB-level vs method-level. A POU has its own declaration block and (for FBs / programs) its own cyclic body, plus zero or more methods / actions / properties hanging underneath. The three UpdatePou* calls target the POU itself; the three UpdateMethodBody* calls target a named child item. Pick the level that matches the change — patching a method body via UpdatePouImplementationPatch will not find the anchor.
Patch primitive semantics. All three _patch calls mirror Claude Code's own Edit tool: each replaces exactly one occurrence of old_string with new_string on the targeted block. They fail if the anchor is missing or appears more than once. If the call fails on non-uniqueness, extend the anchor with more surrounding context and retry. Patches are the right tool for a one-line tweak; do NOT rewrite the whole body for a small change.
AddVariable semantics. Inserts the declaration line before the matching scope's END_VAR. If the scope block does not exist on the target item, a new one is created at the conventional position (order: VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT, VAR, VAR CONSTANT, VAR_PERSISTENT, VAR_TEMP). Use this instead of reading the full declaration, hand-editing the VAR block, and writing it back.
Backend requirement. On the default automation backend, writer tools drive XAE over the COM Automation Interface and will not work unless TcXaeShell is open with the solution loaded. On the xml backend (TCKIT_WRITER=xml; the default off Windows) they edit the project files directly, need no XAE, and take the target solution from OpenProject or TCKIT_SOLUTION. The backend is fixed for the session — never work around a writer failure by editing .TcPOU / .plcproj yourself, and never assume the other backend as a fallback mid-session.
Safety, SIL, TÜV/TUV, Emergency, EStop, SafetyDoor, or anything else that suggests safety-critical functionality, STOP. Show the user the proposed change, explain that it appears safety-critical, and wait for explicit approval before any writer call. This applies even if the change seems trivial.tc-beckhoff-docs, hand off to tc-beckhoff-docs now. Do not write code against a Beckhoff FB whose inputs/outputs/timing you only know from memory.CLAUDE.md if it specifies any (naming, error pattern, public/private boundaries, etc.). Where the project does not specify, match the existing style of the file you are editing. The skill does not impose a default naming or error-handling convention.tckit_analysis_profile in its .editorconfig), AnalyseProject is the authority on what that convention is. Write in the style of the surrounding code, then let the post-write check below correct you rather than arguing from memory about prefixes.// :Description:, // :param x:, // :returns:) and Beckhoff XML ((*~ <docu> ~*)). Match the file's existing style.If the user has named a specific FB and the change is a clear add (one variable, one method, or one patch with the anchor already stated), call the writer directly. The writer fails cleanly if the target FB is missing, so a defensive GetPouInterface "to confirm it exists" is wasted. Only read first when you actually need the existing shape, e.g. to choose a patch anchor or check a signature.
Pick the smallest write that does the job using the Tool selection table above. Small edit on a method -> UpdateMethodBodyPatch. Small edit on the FB-level decl / cyclic body -> UpdatePouDeclarationPatch / UpdatePouImplementationPatch. Single new variable -> AddVariable. Full method-body rewrite -> UpdateMethodBody. Full POU declaration / implementation rewrite -> UpdatePouDeclaration / UpdatePouImplementation. New unit -> AddPou / AddMethod / CreateProject.
For patch-based edits, fetch the current item with GetPouItem (or GetPouDeclaration if only the FB-level VAR block matters) so the anchor you choose is grounded in the real text, not your memory of it.
NEVER edit .TcPOU or .plcproj XML directly. GUIDs and cross-references go through the writer tools (whichever backend serves them).
Check what you wrote. Call AnalyseProject(projectPath, objectName: "<the POU you edited>"). This is offline, needs no XAE, and returns in well under a second, so it costs nothing next to a build. It catches what the compiler will not: a function block instance declared in a method's VAR (its state resets every call), floating-point equality, an unused local, RETAIN where it cannot retain, and naming that departs from the project's configured convention.
Fix what it reports, then re-run it on the same POU. Two rules apply:
Cross-file rules (unread inputs, multi-writer globals, unreachable POUs) are skipped when objectName scopes the run, and the result says so in rules_not_run. Analysing the whole project is worth it once at the end of a larger change, not after every edit.
After the writer returns success, summarise what changed (POU, item, lines). The writer's success response is the confirmation; do not read the change back to "verify" it landed. Whether to build / deploy / test next is driven by the user's request: if they asked for tests to pass, a behaviour to be verified, or the project to build, hand off to tc-build-test-loop and run the cycle through to actual results. If they only asked for the edit, stop here.
.TcPOU file with Read and then editing it with Edit. The MCP writer tools exist to keep GUIDs and project cross-references consistent; bypassing them silently breaks the project..plcproj with Read or Edit to add or remove <Compile Include="..."/> entries. AddPou maintains those entries itself.UpdateMethodBody / UpdatePouDeclaration / UpdatePouImplementation) for a one-line change. Use the matching _patch variant instead.AddVariable instead.GetPouItem / GetPouDeclaration / Read immediately after a successful writer call to confirm it landed. The writer already told you it succeeded. (This is about verifying the write itself, not about running the build / test cycle the user asked for — that's a hand-off to tc-build-test-loop, not a re-read.)AnalyseProject because the edit "was small". The state-losing declaration and the floating-point comparison it catches both compile, so a clean build is not evidence they are absent.AnalyseProject across the whole project after every single edit. Scope it to the POU you touched; save the full pass for the end of a larger change.If the user asked for tests to pass, a behaviour to be verified, or the project to build, the work is not done after the write — hand off to tc-build-test-loop for build → deploy → test and report the actual outcome. If the user only asked for the edit, stop here and report what changed.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub georgeturneruk/tckit --plugin tckit7 skills in this plugin
/tc-beckhoff-docsUse when researching a Beckhoff TwinCAT library, function block, or function via Beckhoff infosys, OR when looking up a Beckhoff hardware product by order number. Triggers on requests like "what does FB_EcCoESdoRead do", "which TF library has SDO read", "what are the inputs of FB_X", "what are the technical specs of EL3004", "look up EPP6228", "how many channels does the EK1100 have", or as a precondition before writing code that uses an unfamiliar Beckhoff FB. Uses TcKit's FindFb, SearchDocs, FindHardware, and GetDocPage MCP tools. Do NOT use for inspecting the user's local project (that is tc-read-project)./tc-build-test-loopUse when building a TwinCAT project, deploying to a target, running TcUnit tests, or iterating on build/test failures through TcKit (Build, Deploy, StartRuntime, RunTests, GetTestResults). Triggers on requests like "build it", "run the tests", "fix the build errors", "deploy to <NetId>", "make the tests pass". Enforces the build-before-deploy ordering, the 2-attempt-per-error build fix limit, the 5-iteration test loop limit, the permission-gate rules for Deploy and StartRuntime (surface denials, never self-elevate), and the save+install rule for multi-PLC solutions with library references. Do NOT use for the initial code write itself (that is tc-write-st)./tc-configUse when configuring TcKit's safety stance (the permission gate), including initial setup ("set me up", "configure tckit", "make tckit read-only"), ongoing edits ("raise the mode to execute", "add NetId to allowed", "block this NetId"), or inspecting the stance ("what permissions does tckit have", "why was deploy denied", "tckit not working"). Wraps the GetPermissions / SetPermissions MCP tools and the user-global permission file at `~/.tckit/permissions.json`. Do NOT use for runtime tool calls like building, deploying, reading projects, or researching Beckhoff FBs (those are owned by tc-build-test-loop, tc-read-project, tc-write-st, and tc-beckhoff-docs)./tc-hardwareUse when inspecting or configuring TwinCAT hardware through TcKit — EtherCAT master/slave diagnostics, IPC hardware health, NC axis state, reading/writing live PLC symbols, invoking RPC methods, or authoring the I/O tree (scan the bus topology, scaffold I/O GVLs, add/remove EtherCAT masters and boxes). Triggers on requests like "what's the EtherCAT bus status", "list the EtherCAT masters", "check the IPC CPU/temperature/UPS", "what state is axis 1 in", "read MAIN.nCounter on the target", "set GVL.bEnable to TRUE", "call the Reset method on fbPid", "scan the hardware", "scaffold I/O variables", "add an EK1100 under the master", "delete Box 3". Do NOT use for reading/writing ST code (tc-write-st), build/deploy/test (tc-build-test-loop), or looking up a product's datasheet by order number (tc-beckhoff-docs / FindHardware)./tc-orient-projectUse on the FIRST encounter with a TwinCAT project in a session, or when the user asks for a "structural overview", "subsystem map", "what's in this project", "introduce me to this project", "give me the lay of the land", "tell me about this codebase", "summarise this project", or any first-touch orientation. Triggers BEFORE tc-read-project; tc-read-project takes over for follow-up reads once orientation is done. Do NOT use mid-task on a project already mapped this session./tc-read-projectUse when inspecting, navigating, or searching a TwinCAT 3 PLC project through TcKit's MCP tools (GetStructure, GetPouInterface, GetPouItem, GetGvl, GetDut) AFTER orientation. Triggers on requests like "show me FB_X", "what's the public API of FB_Motor", "list the methods of FB_TestSuite", "summarise the motor controller POU", "what does ST_Config look like", or any task that requires reading specific PLC code before writing it. Do NOT use for first-touch orientation (use tc-orient-project), and do NOT use for researching Beckhoff library FBs (use tc-beckhoff-docs).Other plugins' skills for the same job