Skip to content
A minimal 8-bit style icon: on the left is a simple file explorer window with stacked rectangles representing folders and a highlighted single file; on the right is a basic command line window, centered with a bright triangle play button. Above these, a plain scroll suggests a code script and a square ticked checkbox suggests a task. A small magnifying glass and a gear icon are present for analysis and settings. The image uses five flat corporate colors, features only basic geometric shapes without background, people, text, gradients, shadows, or 3D effects, and is sized at 128x128 pixels.

Running scripts

In Visual Studio Code, the location where you start running a script determines the entries in the env.files variable.

Play
  • Right click on a file in the Explorer and select Run GenAIScript….
  • Or right click in a file editor and select Run GenAIScript….

The env.files array will contain a single element with the selected file.

A file explorer window shows various files and folders. The file "Document.docx" is selected, and a context menu is open with the option "Run GenAIScript..." highlighted.

  • Right click on a folder in the Explorer and select **Run GenAIScript…**s.

The env.files array will contain all nested files under that folder.

The image shows a file explorer with a context menu. The "rag" folder is expanded, displaying files like "Document.docx." The context menu includes options like "New File," "Cut," "Copy," and "Run GenAIScript."

You can run scripts in the GitHub Copilot Chat through the @genaiscript participant.

A screenshot of the chat participant window.

You can specify default file or files to run the script on. When you run the script from the script file itself, or with the command line without file arguments, the default files will be used.

script({
files: "path/to/files*.md",
})
...

The GenAIScript extension exposes each script as a Task automatically.

The task launches the cli and runs the selected script and pass the path to the current opened editor.

  • Open the command palette Ctrl+Shift+P and search “Tasks: Run Task”
  • Select the genaiscript task provider
  • Select the script you want to run

By default, GenAIScript opens the output preview which shows a rendered view of the LLM output (assuming the LLM produces markdown).

The GenAIScript view provides an overview of the trace of the latest run.

You can also use the Trace to review the each transformation step of the script execution.

  • Click on the GenAIScript status bar icon to various options to investigate results.

A code editor displaying a JSON array with city data, including names, populations, and Wikipedia URLs. A toolbar at the top shows options like "Retry," "Output," and "Trace." The bottom right corner indicates "150 tokens."

Start by creating a script using the command line.

  • JavaScript
Terminal window
npx genaiscript scripts create proofreader
  • TypeScript “—typescript”
Terminal window
npx genaiscript scripts create proofreader --typescript

The scripts create command also drops a TypeScript definition file (genaiscript.d.ts and tsconfig.json) to enable type checking and auto-completion in your editor. If you need to regenerate the TypeScript definition file, use the scripts fix

Terminal window
npx genaiscript scripts fix

Use the run command to execute a script from the command line.

Terminal window
npx genaiscript run proofreader path/to/files*.md

You can start a playground to interactively run scripts through a similar web interface as the Visual Studio Code extension.

Terminal window
npx genaiscript serve

Debug your scripts using the Visual Studio Code Debugger!

These are not actively maintained by the GenAIScript team, but we try to make them work as much as possible. If you find dragons, please report the issues.

GenAIScript can be installed in Cursor using the manual installation steps.

The genaiscript-runner.nvim project provides a plugin to run GenAIScript scripts.