DocsClone a generator

Clone a generator to change the code it writes

Updated Dec 1, 2026

Copy the source of a published Skmtc generator into your project with skmtc clone, edit it, and generate again. The steps, the commands, and what each error means.

To change the code that a Skmtc generator writes, clone the generator. The skmtc clone command copies the source of a published generator into your project. You then edit that copy, and skmtc generate runs it:

skmtc clone petstore -g @skmtc/gen-zod

This page is for a developer, or a coding agent, who generates code with the Skmtc CLI and wants different output. It gives the steps from a new project to a changed file, and the errors that skmtc clone can give.

A generator is a package that writes code from an OpenAPI document. Do not edit a generated file: the next skmtc generate writes it again. Change the generator.

Before you start

  • Install the Skmtc CLI, version 0.17.0 or later. On macOS or Linux, run curl -fsSL https://skmtc.dev/install | sh. On Windows, in PowerShell, run irm https://skmtc.dev/install.ps1 | iex. skmtc --version prints the version.

  • Have a project that generates code. If you do not have one, these three commands make a project named petstore that writes Zod schemas to src/generated:

    skmtc init petstore src/generated
    skmtc install @skmtc/gen-zod petstore
    skmtc generate petstore https://petstore3.swagger.io/api/v3/openapi.json --save
  • Check if a setting does the change. Some generators take settings for one operation or one model, which Skmtc calls enrichments. If a setting does what you want, use it and do not clone. See Configure enrichments.

The examples on this page use the petstore project and the @skmtc/gen-zod generator. Replace these two names:

  • petstore: the name of your project.
  • @skmtc/gen-zod: the generator that writes the code you want to change.

Step 1: Clone the generator

  • In the folder that has .skmtc/, clone the generator:

    skmtc clone petstore -g @skmtc/gen-zod

    The command prints the version that it cloned:

    Cloned 1 generator(s) into "petstore":
      - @skmtc/gen-zod@0.6.12

The source is now in .skmtc/petstore/gen-zod/. The file .skmtc/petstore/deno.json points the generator at that folder, so skmtc generate runs your copy and not the published package. These are the two entries that point at the clone. The command also adds each package that the generator imports, such as valibot, and the file has other entries too, such as @skmtc/core. Do not remove them.

{
  "imports": {
    "@skmtc/gen-zod": "./gen-zod/mod.ts"
  },
  "workspace": ["./gen-zod"]
}

To clone more than one generator, repeat -g. To clone one version, add it to the name: -g @skmtc/gen-zod@0.6.12. For JSON output, add --json.

Step 2: Edit the source

Open .skmtc/petstore/gen-zod/src/. Two files hold most changes:

FileWhat it decides
src/base.tsThe identifier of each definition, and the export path of its file.
src/<Name>.ts, one for each schema typeThe code for that type, such as ZodObject.ts for an object.

As an example, change the folder of the generated files from types to schemas.

  1. Open .skmtc/petstore/gen-zod/src/base.ts and find toExportPath:

    return `@/types/${decapitalize(name)}.generated.ts`;
  2. Change types to schemas:

    return `@/schemas/${decapitalize(name)}.generated.ts`;

In a path, @/ is the base path of the project: src/generated here.

Step 3: Generate again

  • Run the generator:

    skmtc generate petstore

    The files are now in the new folder, and Skmtc deleted the files that it wrote to the old one:

    src/generated/schemas/pet.generated.ts
    src/generated/schemas/user.generated.ts

To run the generator each time you save a file of the clone, run skmtc dev petstore while you edit.

Commit the folder .skmtc/petstore/gen-zod/ to git. It is your code now.

Get a later version of the generator

A clone does not change when its generator gets a new published version. To replace the clone with the newest version, add --force:

skmtc clone petstore -g @skmtc/gen-zod --force

--force deletes the folder and your edits, and clones again. Commit your edits first. After the command, apply them again from git diff.

To go back to the published generator with no edits, remove the clone and install the package:

skmtc remove petstore @skmtc/gen-zod
skmtc install @skmtc/gen-zod petstore

skmtc remove deletes the folder of the clone and your edits.

Troubleshooting

skmtc clone changes no file when it stops with one of these errors.

OutputExit codeCauseFix
Error: already cloned2The project has a clone of this generator.Edit the clone you have. Or add --force to replace it, which deletes your edits.
Error: folder in use2The folder .skmtc/<project>/<name>/ holds another generator, or files that are not a generator.Move or delete that folder. --force does not replace it.
Error: @skmtc/core conflict2The generators in the project need versions of @skmtc/core that no one version satisfies. One project runs one version.The message names each generator and the version it needs. Clone or install versions that agree. To move more than one clone, name each one in one clone --force command.
Error: package version conflict2Two generators in the project need versions of a package that no one version satisfies. One project has one version of each package.The message names the package, each version and the generator that needs it. Clone versions of the generators that agree.

Clone a generator from an agent

A coding agent runs the same commands. Give it these rules:

  • Run skmtc agent-context --json first. It lists the projects and the commands of the installed CLI.
  • Run skmtc guide customize for the steps that match the installed version.
  • Add --json to clone, install, remove and generate, and read the exit code. Exit code 2 means that the command changed nothing and the message says what to do. skmtc dev takes no options.
  • Edit the files in .skmtc/<project>/<name>/src/, and no generated file.
  • Never add --force without a question to the user: it deletes edits.

See also