Docs / CLI

CLI reference

Every runthat command, its options and samples you can copy. The same text is inrunthat --help and runthat help <command>.

30 commands and 21 MCP tools, from runthat 0.1.9. Generated from runthat help --json.

Run & debug

runthat run

runthat <script.cs> [args...]
runthat run [--frozen] <script.cs> [--] [args...]

Run a script using the packages in its lock file. Creates the lock file if it's missing, unless --frozen is given (use that in production and CI).

Restores exactly the packages in <script>.lock.json, builds the script in Release and runs it. runthat <script.cs> is the same as runthat run. Without a lock file, a plain run resolves the pinned packages and writes one first; --frozen refuses instead, so nothing can change the packages. Everything after the script goes to the script; put -- first to pass arguments that start with a dash. The exit code is the script's own. An unhandled exception is reported at the script's own file and line.

Options for runthat run
OptionWhat it does
--frozenUse the lock file exactly and fail if there's none, instead of creating it. Use this in CI and production.
--Everything after it goes to the script, even arguments that start with a dash.

Samples

Run a script; the first run creates report.lock.json

runthat report.cs

Run exactly as locked, as in CI or production

runthat run --frozen report.cs

Pass arguments that start with a dash to the script

runthat run report.cs -- --month 11

runthat debug

runthat debug <script.cs> [--frozen] [--break <line>]... [--max-hits <n>] [--json] [--debugger <path>] [-- args...]

Build in Debug and run under netcoredbg. At each breakpoint (a line in the script), print the line, the call stack and the locals (secrets hidden), then go on (at most --max-hits stops, default 50). An unhandled exception is reported with its file and line. --json writes one object at the end.

Builds the script in Debug, with symbols that point at the script itself, and runs it under netcoredbg, the MIT-licensed .NET debugger. At each breakpoint it prints the line, the call stack and the local variables, then carries on; the script's own output is printed as it comes. Values are cut to 1,000 characters and passwords, keys, tokens and connection strings show as [redacted]. A breakpoint on a line with no code binds to the next line that has some. An unhandled exception is reported with its type, message, file, line, stack and locals. The exit code is the script's own.

Options for runthat debug
OptionWhat it does
--break <line>repeatableStop at this line of the script.
--max-hits <n>Stop recording after this many breakpoint hits (default 50); the script then runs on without breakpoints.
--frozenUse the lock file exactly and fail if there's none, instead of creating it. Use this in CI and production.
--jsonWrite one object when the script ends: { version, exitCode, output, outputTruncated, breakpoints, hits, hitLimitReached, error }.
--debugger <path>The netcoredbg executable or its folder. Without it runthat uses RUNTHAT_DEBUGGER, a netcoredbg next to runthat, or its tools folder, and downloads netcoredbg (pinned, SHA-256 checked) the first time.
--Everything after it goes to the script.

JSON shape: see JSON output (debug).

Samples

Print the stack and locals at lines 12 and 30

runthat debug report.cs --break 12 --break 30

One JSON object for tools and agents

runthat debug report.cs --break 12 --json

Pass arguments to the script after --

runthat debug report.cs --break 12 -- --month 11

runthat debug --dap

runthat debug <script.cs> --dap [--frozen] [--debugger <path>] [-- args...]

Build in Debug, then speak the Debug Adapter Protocol on stdin/stdout (for editors); runthat fills in the launch request.

Restores and builds first; if that fails it exits 1 with a runthat: message on stderr and writes nothing to stdout. Then it starts netcoredbg and passes Debug Adapter Protocol messages between stdin/stdout and netcoredbg. Only DAP goes to stdout. runthat fills in the launch request (program, args, cwd and the script's connections) and maps setBreakpoints paths that name the script to its symbols, so breakpoints bind. It can't be combined with --break, --max-hits or --json: the client sets breakpoints itself.

Options for runthat debug --dap
OptionWhat it does
--dapSpeak the Debug Adapter Protocol on stdin/stdout.
--frozenUse the lock file exactly and fail if there's none, instead of creating it. Use this in CI and production.
--debugger <path>The netcoredbg executable or its folder. Without it runthat uses RUNTHAT_DEBUGGER, a netcoredbg next to runthat, or its tools folder, and downloads netcoredbg (pinned, SHA-256 checked) the first time.
--Everything after it goes to the script.

Sample

Start a debug adapter for an editor

runthat debug report.cs --dap

Lock & deploy

runthat lock

runthat lock <script.cs>

Resolve packages and write <script>.lock.json.

Resolves the script's pinned #:package lines and every indirect package, and writes <script>.lock.json next to it with each package's content hash, the target framework and platform. Run it after you edit #:package lines, then commit the script and its lock together. For an EF Core connection without a model yet, it also writes <script>.schema.json from the cached schema. It warns when several feeds are enabled without packageSourceMapping.

Sample

Write report.lock.json

runthat lock report.cs

runthat check

runthat check <script.cs> [--source <script.cs>]

Check this machine can run the script as locked. With --source, also check an exported copy still matches the script it came from.

Checks the .NET SDK and runtime for the script's target, the feeds, the locked restore and the compile, with one ok/FAIL line per step, and reports any connection the script declares that this machine is missing. It never runs the script's code, so it's the safe way to try a script. Exits 1 when a check fails.

Options for runthat check
OptionWhat it does
--source <script.cs>For an exported copy: also check that it still matches the script it was exported from.

Samples

Check this machine can run report.cs as locked

runthat check report.cs

Check an exported copy is up to date

PowerShell

runthat check dist\report.cs --source report.cs

bash

runthat check dist/report.cs --source report.cs

runthat export

runthat export <script.cs> [-o <folder|file.cs>]

Write one file with the lock inside, for sharing or deploying (default: dist\<script>.cs).

Writes a single .cs file with the lock embedded at the end as comments, for sharing or deploying. The script and its lock file stay as they are. The copy runs anywhere with runthat run --frozen. Don't edit the embedded lock: a changed line or hash stops the run.

Options for runthat export
OptionWhat it does
-o <folder|file.cs>Where to write the copy (also --output). Default: dist\<script>.cs next to the script.

Samples

Write dist\report.cs with the lock inside

PowerShell

runthat export report.cs

bash

runthat export report.cs   # writes dist/report.cs

Write the copy to a share

PowerShell

runthat export report.cs -o \\server\scripts

bash

runthat export report.cs -o /srv/scripts

runthat unpack

runthat unpack [--force] <exported.cs>

Turn an exported copy back into a script and its lock file.

Splits an exported copy into the script and its <script>.lock.json again, so you can edit it. It won't replace existing files unless you pass --force.

Options for runthat unpack
OptionWhat it does
--forceReplace a script or lock file that's already there.

Sample

Turn an exported copy back into report.cs and report.lock.json

runthat unpack report.cs

runthat publish

runthat publish <script.cs> [-o <folder>] [-r <runtime>] [--framework-dependent] [--single-file]

Compile a locked script into a folder that runs with no package feeds, and with no .NET installed unless --framework-dependent is given (default: dist\<script>-<runtime>, this machine's runtime, for example win-x64 or linux-x64).

Restores for the target platform, compares every package with the lock by version and content hash, and only then compiles the script into a folder you copy to the server. If anything differs, nothing is published. It's self-contained by default, so the server needs neither feeds nor .NET. runthat writes runthat-publish.json into the folder and only ever replaces a folder it published before, or an empty one. To lock platform-only packages, list the platforms with #:property RuntimeIdentifiers=win-x64;linux-x64 and relock.

Options for runthat publish
OptionWhat it does
-o <folder>The output folder (also --output). Default: dist\<script>-<runtime>.
-r <runtime>The runtime identifier, for example win-x64, linux-x64 or osx-arm64 (also --runtime). Default: this machine's.
--framework-dependentLeave out the .NET runtime: a smaller folder for machines that have it.
--single-fileBundle everything into one executable.

Samples

Build dist\report-linux-x64 for a Linux server

PowerShell

runthat publish report.cs -r linux-x64

bash

runthat publish report.cs -r linux-x64   # builds dist/report-linux-x64

One self-contained .exe

runthat publish report.cs -r win-x64 --single-file

A smaller folder for machines with .NET

runthat publish report.cs --framework-dependent -o out

runthat import

runthat import <file.linq> [-o <script.cs>] [--pin <id@version>]... [--force] [--no-lock]

Import an existing query into a script and lock it. Packages without a version get the one this machine already uses; --pin sets one yourself.

Turns an existing query file into a runthat script next to it and locks it. Expression, Statements and Program queries are supported. Pinned packages keep their version; for the others runthat uses the newest version already on this machine, and says to use --pin when it finds none. A query's connection becomes a #:connection line. What can't be carried over, such as DLL references, is listed in note: lines.

Options for runthat import
OptionWhat it does
-o <script.cs>Where to write the script (also --output). Default: next to the query, with a .cs extension.
--pin <id@version>repeatableUse this version for a package, for example --pin [email protected].
--forceReplace a script that's already there.
--no-lockWrite the script without locking it.

Samples

Import a .linq query and lock it

runthat import report.linq

Choose a version and where the script goes

PowerShell

runthat import report.linq --pin [email protected] -o scripts\report.cs

bash

runthat import report.linq --pin [email protected] -o scripts/report.cs

Packages & feeds

runthat sources

runthat sources <script.cs> [--json]

Show the package feeds the script uses, its packageSourceMapping rules, and which feed each locked package may come from.

Lists the feeds the script restores from (its nearest nuget.config, or the user and machine NuGet config without one), whether each is enabled and has saved credentials, the packageSourceMapping rules, and which feed each locked package may come from. Exits 1 when a package has no allowed feed.

Options for runthat sources
OptionWhat it does
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources).

Samples

See the feeds and mapping report.cs restores with

runthat sources report.cs
runthat sources report.cs --json

runthat sources add

runthat sources add <name> <url-or-folder> --script <script.cs> [--user] [--json]

Add a feed to the script's nearest nuget.config (created next to the script if there's none), or to your user NuGet.Config with --user.

Adds a feed (an https:// URL or a folder; a relative folder stays relative) to the nuget.config restore reads for the script. A new nuget.config starts with the feeds, disabled feeds and mapping the script already used, after a <clear />. Refuses a duplicate name, a bad URL or a missing folder. Credentials are never written.

Options for runthat sources add
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--userEdit your user NuGet.Config instead.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Samples

runthat sources add acme https://pkgs.example.com/acme/v3/index.json --script report.cs

A folder feed

PowerShell

runthat sources add local ..\packages --script report.cs

bash

runthat sources add local ../packages --script report.cs

runthat sources remove

runthat sources remove <name> --script <script.cs> [--user] [--json]

Remove a feed, with its mapping patterns, disabled entry and saved credentials in that file.

Removes a feed from the file that defines it, with its packageSourceMapping patterns, disabled entry and credentials. A feed in your user config needs --user; machine-wide feeds are never changed (disable the feed for the script instead).

Options for runthat sources remove
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--userEdit your user NuGet.Config instead.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Sample

runthat sources remove local --script report.cs

runthat sources enable | disable

runthat sources enable <name> --script <script.cs> [--json]
runthat sources disable <name> --script <script.cs> [--json]

Turn a feed on or off for the script.

Turns a feed on or off for the script with disabledPackageSources in its nuget.config, without removing it.

Options for runthat sources enable | disable
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Samples

runthat sources disable local --script report.cs
runthat sources enable local --script report.cs

runthat sources map

runthat sources map <pattern> <feed> --script <script.cs> [--json]

Add a packageSourceMapping pattern (an exact id, Prefix.* or *) for a feed.

Writes NuGet's packageSourceMapping into the script's nuget.config, so a package can only come from the feeds it's mapped to. NuGet uses the most specific pattern. Patterns NuGet wouldn't match, such as A*b, are refused.

Options for runthat sources map
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Samples

Acme packages only from the acme feed

runthat sources map "Acme.*" acme --script report.cs

Everything else from nuget.org

runthat sources map "*" nuget.org --script report.cs

runthat sources unmap

runthat sources unmap <pattern> [<feed>] --script <script.cs> [--json]

Remove a packageSourceMapping pattern from one feed, or from every feed.

Removes a packageSourceMapping pattern from the named feed, or from every feed when none is named.

Options for runthat sources unmap
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Samples

runthat sources unmap "Acme.*" --script report.cs
runthat sources unmap "Acme.*" acme --script report.cs

runthat sources clear-above

runthat sources clear-above on|off --script <script.cs> [--json]

Add or remove <clear /> at the top of packageSources.

With on, the script's nuget.config starts its packageSources with <clear />, so feeds from other config files don't apply in that folder (for dotnet and IDEs too). off takes it out.

Options for runthat sources clear-above
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-change).

Sample

runthat sources clear-above on --script report.cs

runthat sources which

runthat sources which <package-id> --script <script.cs> [--json]

Which feeds a package may come from, the pattern that decided it, and why.

Shows the enabled feeds a package may come from under packageSourceMapping, the pattern that decided it, and why. No feed means restore will fail.

Options for runthat sources which
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-which).

Sample

runthat sources which Acme.Billing --script report.cs

runthat sources test

runthat sources test <name-or-url> --script <script.cs> [--json]

Try a feed, signing in like restore does.

Reads a feed's service index (or checks a folder) with restore's own credential handling, and says whether it answered or needs signing in. Exits 0 whenever the test ran, whether or not the feed answered.

Options for runthat sources test
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to read or edit. Required.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (sources-test).

Sample

runthat sources test acme --script report.cs

runthat info

runthat info <id> [--script <script.cs>] [--version <v>] [--json]

List every version of a package on those feeds, newest first, marking deprecated and vulnerable ones, with the dependencies and license of one version (default: the newest stable).

Lists every version of a package on the script's feeds, newest first, marking prerelease, deprecated and vulnerable ones, with one version's dependency groups by framework, its license and its advisories. Use it to choose a version before pinning it.

Options for runthat info
OptionWhat it does
--script <script.cs>The script whose nearest nuget.config to use. Without it, the current folder's.
--version <v>The version to show details for. Default: the newest stable.
--jsonWrite one JSON object to stdout instead of text.

JSON shape: see JSON output (info).

Samples

runthat info Newtonsoft.Json --script report.cs
runthat info Newtonsoft.Json --version 12.0.3 --json

Databases

runthat db test

runthat db test <connection> [--provider <kind>] [--json]

Open a connection and show the server version.

Opens one of this machine's named connections and shows the server version, how long it took and where the connection came from (the saved list or a RUNTHAT_CONNECTION_ variable). Exits 1 when it can't connect.

Options for runthat db test
OptionWhat it does
--provider <kind>Read the connection as this kind of database instead of the one it was saved with (also -p).
--jsonWrite one JSON object to stdout instead of text.

Sample

runthat db test Sales

runthat db schema

runthat db schema <connection> [--schema <name>] [--refresh] [--provider <kind>] [--json]

List its tables, views, routines and columns, with keys. Cached after the first read; --refresh reloads.

Lists the schemas, tables, views, procedures and functions, with each column's type, whether it allows nulls, and the primary and foreign keys. It reads the catalog with three queries rather than one per table and caches the result (names only) until you pass --refresh or change the connection. It never reads data. SQL Server, PostgreSQL, MySQL and MariaDB, SQLite and Oracle are supported.

Options for runthat db schema
OptionWhat it does
--schema <name>Only this schema (SQL Server or PostgreSQL schema, MySQL database, Oracle user).
--refreshRead the catalog from the database again instead of the cache.
--provider <kind>Read the connection as this kind of database instead of the one it was saved with (also -p).
--jsonWrite one JSON object to stdout instead of text.

Samples

runthat db schema Sales
runthat db schema Sales --schema dbo --refresh

runthat db record

runthat db record <connection> <table> [--schema <name>] [--refresh] [--provider <kind>]

Write a C# record for a table's rows, for Dapper.

Writes a C# record for a table's rows, with the .NET types the driver returns, to paste into a script for Dapper. The table can be name or schema.name.

Options for runthat db record
OptionWhat it does
--schema <name>Only this schema (SQL Server or PostgreSQL schema, MySQL database, Oracle user).
--refreshRead the catalog from the database again instead of the cache.
--provider <kind>Read the connection as this kind of database instead of the one it was saved with (also -p).

Sample

runthat db record Sales dbo.Orders

runthat db model

runthat db model <connection> --script <script.cs> [--table <t>]... [--schema <s>] [--refresh] [--provider <kind>] [--remove]

Save the tables an EF Core connection uses (#:connection Sales efcore) in <script>.schema.json, which builds Db.Sales.CreateContext(). Commit it. lock and runs that aren't --frozen take every table and view (up to 100) when the file has no model yet.

Saves a snapshot of the tables an EF Core connection uses next to the script, as <script>.schema.json, which builds Db.Sales.CreateContext(). Builds read that file, never the database, so run --frozen, export and publish work offline. Pick the tables the script needs: EF builds its model from all of them at the start of every run. Commit the file with the script.

Options for runthat db model
OptionWhat it does
--script <script.cs>The script the model is for; it's saved next to it. Required.
--table <t>repeatableA table or view to include, as name or schema.name. Default: every one, up to 100.
--schema <name>Only this schema (SQL Server or PostgreSQL schema, MySQL database, Oracle user).
--refreshRead the catalog from the database again instead of the cache.
--provider <kind>Read the connection as this kind of database instead of the one it was saved with (also -p).
--removeTake the connection's model out of the file.

Samples

runthat db model Sales --script report.cs --table dbo.Orders --table dbo.Customers
runthat db model Sales --script report.cs --remove

runthat db drivers

runthat db drivers [--json]

The databases with typed Db.<Name> connections, and the #:package line for each one's driver.

Lists the supported databases, the driver package to pin for each (with its #:package line), the connection type Db.<Name> returns, and, with --json, the EF Core provider package.

Options for runthat db drivers
OptionWhat it does
--jsonWrite one JSON object to stdout instead of text.

Samples

runthat db drivers
runthat db drivers --json

Connections

runthat connection list

runthat connection list [--json]

List this machine's named database connections: names and kinds, never the connection strings.

Lists the named connections on this machine with their kind. --json adds the environment variable each reaches scripts as and where it comes from. Connection strings are never shown.

Options for runthat connection list
OptionWhat it does
--jsonWrite one JSON object to stdout instead of text.

Samples

runthat connection list
runthat connection list --json

runthat connection add

runthat connection add <name> --provider <kind> [--connection-string <value>] [--replace]

Save a named connection on this machine. It asks for the connection string, or reads it from stdin. Scripts declare #:connection Sales, pin its driver and use await Db.Sales.OpenAsync() (with efcore: Db.Sales.CreateContext()).

Saves a connection string under a name on this machine; on Windows it's encrypted for your user account. It asks for the string with a hidden prompt, or reads it from stdin, so it doesn't end up in shell history. Kinds: sqlserver, postgresql, mysql, sqlite, oracle, other.

Options for runthat connection add
OptionWhat it does
--provider <kind>The kind of database: sqlserver, postgresql, mysql, sqlite, oracle, other (also -p). Required.
--connection-string <value>The connection string. Avoid it: it lands in shell history. Leave it out to be asked.
--replaceReplace a connection that already has this name.

Samples

Asks for the connection string

runthat connection add Sales --provider sqlserver

Read it from a file instead

PowerShell

Get-Content sales.txt | runthat connection add Sales --provider sqlserver --replace

bash

runthat connection add Sales --provider sqlserver --replace < sales.txt

runthat connection remove

runthat connection remove <name>

Remove a named connection from this machine.

Removes a saved connection. Scripts that declare it then need a RUNTHAT_CONNECTION_<NAME> variable instead.

Sample

runthat connection remove Sales

AI agents

runthat mcp

runthat mcp [--folder <dir>]... [--read-only] [--timeout <seconds>]

Start an MCP server on stdin/stdout so AI agents can list, edit, import, lock, run and publish scripts in the given folders (default: the current folder). Connect with: claude mcp add runthat -- runthat mcp --folder <dir>

Serves the scripts in the given folders to AI agents over the Model Context Protocol (stdio). Every path must be inside a --folder; runs are always frozen; a run stops after the time limit and output is cut at 100,000 characters; secrets in scripts and output show as [redacted]; connection strings never pass through. Every call is logged to mcp.log in the runthat folder (%LOCALAPPDATA%\runthat, or RUNTHAT_HOME).

Options for runthat mcp
OptionWhat it does
--folder <dir>repeatableA folder the agent may use. Default: the current folder.
--read-onlyOffer only the read tools, so nothing runs and no file changes.
--timeout <seconds>How long a run may take (default 120).

Samples

Add it to Claude Code

PowerShell

claude mcp add runthat -- runthat mcp --folder D:\scripts

bash

claude mcp add runthat -- runthat mcp --folder ~/scripts

Let an agent look but not change anything

runthat mcp --folder . --read-only

MCP tools

What runthat mcp offers an agent. With --read-only, only the read-only tools are offered. Your MCP client asks before each call to a tool that changes something.

MCP tools
ToolChanges things?What it does
list_scriptsread only

Lists the C# scripts in the folders this server can use, with each script's pinned packages and whether it's locked. Paths are relative and can be passed to the other tools.

read_scriptread only

Returns a script's code, its lock file and the hash of its current content (pass it as expected_hash to save_script). Passwords, tokens and keys are shown as [redacted].

Parameters (1)
  • path string, required: Path of the script, relative to the first folder or absolute.
check_scriptread only

Checks this machine can run a script exactly as locked: directives, lock, .NET runtime, package restore from the feeds, and compiling. Returns one ok or FAIL line per step. Doesn't run the script.

Parameters (2)
  • path string, required: Path of the script.
  • source string: For an exported copy: the source script, to check the copy is still up to date.
search_packagesread only

Searches the package feeds a script restores from (its nearest nuget.config, with packageSourceMapping applied) and returns each package's id, latest version, feed, downloads and description. Use package_info to see every version, then add_package with an exact version.

Parameters (4)
  • query string, required: Search words, for example 'json' or 'Polly'.
  • take integer: How many results to return (1 to 20).
  • prerelease boolean: Include prerelease versions.
  • script string: A script whose feeds to search. By default, the first folder's nuget.config applies.
package_inforead only

Lists every version of a package on a script's feeds, newest first, marking prerelease, deprecated and vulnerable ones, and shows one version's dependencies by target framework, license and advisories. Pick an exact version from it for add_package.

Parameters (3)
  • id string, required: The package id, for example 'Newtonsoft.Json'.
  • version string: The version to describe. By default, the newest stable one.
  • script string: A script whose feeds to read. By default, the first folder's nuget.config applies.
which_feedread only

Says which of a script's feeds a package may be restored from under its packageSourceMapping, the pattern that decided it, and why. An empty list means restore will fail for that package; fix it with map_package.

Parameters (2)
  • script string, required: Path of the script.
  • id string, required: The package id, for example 'Newtonsoft.Json'.
list_connectionsread only

Lists the named database connections saved on this machine: each one's name and kind of database, never its connection string. A script uses one by declaring '#:connection Name' at the top, pinning the database's driver package, and opening it with 'await Db.Name.OpenAsync()' (or, with '#:connection Name efcore' and the EF Core provider, 'Db.Name.CreateContext()'). describe_database shows its tables and columns.

describe_databaseread only

Lists the tables, views, procedures and functions of one of this machine's named connections (see list_connections), or, with 'table', that table's columns, keys and a C# record for its rows. Reads only the database's catalog, never its data, and never shows the connection string. The schema is cached; pass refresh=true after the database changes.

Parameters (5)
  • connection string, required: The connection's name, as in '#:connection Sales'.
  • table string: A table or view, as name or schema.name, to show its columns and a C# record for it.
  • schema string: Only this schema (SQL Server or PostgreSQL schema, MySQL database, Oracle user).
  • refresh boolean: Read the schema from the database again instead of the cache.
  • script string: A script that uses this connection with '#:connection Name efcore': also lists its EF Core model's DbSets, entity classes, properties and navigations, as the script must name them.
run_scriptyes, asks first

Runs a locked script and returns its exit code and output, including Dump() tables. Always runs frozen: exactly the versions in the lock, and an unlocked script is refused (use lock_script first). Runs have a time limit and an output cap. This runs real code on the user's machine.

Parameters (2)
  • path string, required: Path of the script.
  • args string[]: Arguments passed to the script.
debug_scriptyes, asks first

Runs a locked script under the debugger (netcoredbg, downloaded on first use), stopping at each breakpoint line to record the line, the call stack and the local variables, then going on. Returns JSON: {version, exitCode, output, outputTruncated, breakpoints: [{line, verified, boundLine, message}], hits: [{line, file, stack: [{name, file, line}], locals: [{name, type, value}]}], hitLimitReached, error: null or {type, message, file, line, stack, locals} for an unhandled exception}. Always runs frozen, like run_script, with the same time limit and output cap; values are cut to 1000 characters and secrets are redacted. A line with no code binds to the next line that has some (see boundLine). This runs real code on the user's machine.

Parameters (4)
  • path string, required: Path of the script.
  • breakpoints integer[], required: Line numbers in the script to stop at, for example [12, 30].
  • args string[]: Arguments passed to the script.
  • max_hits integer: Stop recording after this many hits (default 50); the breakpoints are then removed and the script runs on.
lock_scriptyes

Resolves a script's pinned packages and writes its lock file (<script>.lock.json next to it), recording every package with its content hash. Run this after changing #:package lines.

Parameters (1)
  • path string, required: Path of the script.
save_modelyes

Saves the tables a script's EF Core connection ('#:connection Sales efcore') uses into <script>.schema.json next to it, from this machine's cached schema (refresh=true reads the catalog again). The script's Db.Sales.CreateContext() is built from that file, never from the database. Pick the tables the script needs: EF builds its model from all of them at the start of every run. Without tables it takes every table and view, up to 100. Commit the file with the script. Reads only the catalog, never data.

Parameters (5)
  • script string, required: Path of the script.
  • connection string, required: The connection's name, as in '#:connection Sales efcore'.
  • tables string[]: Tables and views to include, as name or schema.name. Leave out for all of them (up to 100).
  • schema string: Only this schema (SQL Server or PostgreSQL schema, MySQL database, Oracle user). A MySQL model needs one when the server has several.
  • refresh boolean: Read the schema from the database again instead of the cache.
add_packageyes

Adds a pinned '#:package Id@Version' line to a script and relocks it. The version must be exact (find one with search_packages). If the package can't be restored, the script is left unchanged.

Parameters (3)
  • path string, required: Path of the script.
  • id string, required: NuGet package id, for example Dapper.
  • version string, required: Exact version, for example 2.1.35.
export_scriptyes

Writes a single-file copy of a locked script with its lock embedded at the end, for sharing or deploying. The script and its lock file aren't changed. The copy runs anywhere with 'runthat run --frozen'.

Parameters (2)
  • path string, required: Path of the script.
  • output string: Where to write the copy: a folder or a .cs file inside the allowed folders. Defaults to dist/<script>.cs next to the script.
save_scriptyes, asks first

Creates a .cs script, or replaces one with new text. To replace an existing script, pass the hash read_script returned as expected_hash: if the file changed since then, nothing is written. Packages must be pinned to exact versions. If the #:package lines (or the target framework) changed, the script is relocked, and if the restore fails the old script and lock are put back.

Parameters (3)
  • path string, required: Path of the script, for example reports/sales.cs. Folders that don't exist yet are created.
  • content string, required: The whole text of the script.
  • expected_hash string: The hash read_script returned for the current file. Required to replace an existing script; leave it out to create a new one.
publish_scriptyes, asks first

Compiles a locked script into a folder that runs on a machine with no package feeds (and, when self-contained, no .NET installed). Refused if any package would differ from the lock. Only replaces a folder runthat published before, or an empty one. Returns the folder.

Parameters (5)
  • path string, required: Path of the script.
  • runtime string: Runtime identifier, for example win-x64, linux-x64 or osx-arm64. Defaults to this machine's.
  • self_contained boolean: Include the .NET runtime, so the target machine needs nothing installed.
  • single_file boolean: Bundle the app into one executable.
  • output string: The folder to publish into, inside the allowed folders. Defaults to dist/<script>-<runtime> next to the script.
import_linqyes

Turns an existing .linq query file into a runthat script and locks it. Packages the query didn't pin get the version this machine already uses; if it has none, pass pins. Returns the new script's path and hash, and notes on anything that couldn't be carried over (for example a database connection to add with #:connection).

Parameters (4)
  • path string, required: Path of the .linq file, inside the allowed folders.
  • output string: The script to write: a .cs file or a folder inside the allowed folders. Defaults to the .linq file's name with .cs, next to it.
  • pins string[]: Exact versions for packages the .linq file doesn't pin, for example ["[email protected]"].
  • expected_hash string: To replace a script that already exists: the hash read_script returned for it.
add_feedyes

Adds a package feed to the nuget.config a script restores with (its nearest one, or a new nuget.config next to it, which starts with the feeds the script already used). The source is an https:// URL or a folder; a relative folder stays relative to the config file. Refuses a name that's already used. Never writes credentials. With packageSourceMapping on, map packages to the new feed with map_package.

Parameters (3)
  • script string, required: Path of the script whose feeds to change.
  • name string, required: The feed's name, for example 'acme'.
  • source string, required: An https:// feed URL (usually ending in index.json) or a folder of .nupkg files.
remove_feedyes, asks first

Removes a feed from the script's nuget.config, with its packageSourceMapping patterns, disabled entry and saved credentials in that file. Feeds from the user's or the machine's NuGet config aren't changed; the error says how to turn them off instead.

Parameters (2)
  • script string, required: Path of the script whose feeds to change.
  • name string, required: The feed's name.
map_packageyes

Adds a packageSourceMapping pattern to the script's nuget.config, so matching packages come only from that feed. A pattern is an exact package id, a prefix ending in * (Contoso.*), or * for everything else. Once any pattern exists, packages that match none can't be restored: check with which_feed.

Parameters (3)
  • script string, required: Path of the script whose feeds to change.
  • pattern string, required: The pattern: an exact id, Prefix.*, or *.
  • feed string, required: The feed's name.
unmap_packageyes, asks first

Removes a packageSourceMapping pattern from the script's nuget.config: from one feed, or from every feed when feed is left out. When no pattern is left, packageSourceMapping is off and NuGet tries every enabled feed.

Parameters (3)
  • script string, required: Path of the script whose feeds to change.
  • pattern string, required: The pattern, exactly as mapped.
  • feed string: The feed to remove it from. By default, every feed.

Script directives

Lines at the top of a script. runthat reads them before it builds.

#:property <Name>=<Value>

Set an MSBuild property. Without TargetFramework, new scripts target net10.0 (they need the .NET 10 SDK), and a locked script keeps the target its lock was made for. RuntimeIdentifiers locks platform-only packages for each platform listed.

#:property TargetFramework=net8.0
#:property RuntimeIdentifiers=win-x64;linux-x64

#:connection <Name> [<kind>] [efcore]

Use one of this machine's named connections. It reaches the script as RUNTHAT_CONNECTION_<NAME>, and Db.<Name> is typed for the driver the script pins: await Db.Sales.OpenAsync() returns, for example, a SqlConnection. The kind (sqlserver, postgresql, mysql, sqlite, oracle) is needed only when the script has drivers for several databases. With efcore, Db.Sales.CreateContext() returns a typed DbContext built from <script>.schema.json. Connections.Get("Sales") returns the plain string for any library.

#:connection Sales
#:connection Sales sqlserver
#:connection Sales efcore

Reference

runthat help

runthat help [<command>] [--json]
runthat --help

Show this help, or one command's options and samples. --json writes every command, option, directive and MCP tool as JSON.

Without a command, prints the usage of every command. With one, for example runthat help lock or runthat help sources add, prints its options and samples. --json writes the whole reference (commands, options, samples, directives, environment variables, exit codes and MCP tools) as one JSON object, which the runthat.dev command reference is built from.

Options for runthat help
OptionWhat it does
--jsonWrite one JSON object to stdout instead of text.

Samples

runthat help lock
runthat help --json

Environment variables

Environment variables
VariableWhat it does
RUNTHAT_HOMEThe folder runthat keeps its state in: hidden projects, saved connections, the schema cache, tools and mcp.log. Default: %LOCALAPPDATA%\runthat on Windows. Set it to a temp folder in tests.
RUNTHAT_CONNECTION_<NAME>A connection string for a script that declares #:connection <Name> (letters and digits upper-cased, anything else _). runthat sets it from the saved connection; one that's already set wins, so set it on a CI server or for a published app.
RUNTHAT_CLIFor the desktop app: the full path of the runthat executable to use instead of the copy installed with it or the one on the PATH.
RUNTHAT_DEBUGGERThe netcoredbg executable or its folder for runthat debug, after --debugger and before the copy next to runthat or in its tools folder.

Give a script its connection on a CI server

PowerShell

$env:RUNTHAT_CONNECTION_SALES = "Server=db;Database=Sales;Integrated Security=true"

bash

export RUNTHAT_CONNECTION_SALES="Server=db;Database=Sales;Integrated Security=true"

Exit codes

Exit codes
CodeMeaning
script's ownrun and debug return the script's exit code (an unhandled exception gives .NET's usual code).
0The command did what it was asked. search, info and sources test also return 0 whenever they ran, even with no results or a feed that failed.
1runthat couldn't do it, with a message on stderr that starts with runthat: (for example a missing lock with --frozen, a failed check, a connection that won't open, or a package with no allowed feed in runthat sources).
2A usage error: an unknown command or option, or a missing argument.

JSON output

With --json, a command writes one object to stdout. Properties are camelCase and always present (null when unknown). version (now 1) changes only when a property is removed, renamed or changes meaning; new properties can appear without a change.

JSON output shapes
FromShape
search{ version, query, prerelease, configFile, hasMapping, feeds: [{ name, url, results, hidden, problems }], packages: [{ id, latestVersion, description, authors, owners, totalDownloads, projectUrl, source, foundOn }], problems }

One entry per package id, best matches first.

info{ version, id, configFile, hasMapping, latestStable, latestPrerelease, feeds: [{ name, url, allowed, versions, problems }], versions: [{ version, prerelease, sources, published, downloads, deprecation, vulnerable, vulnerabilities }], selected, problems }

selected has the chosen version's description, license, tags and dependencyGroups; null when there are no versions.

sources{ version, script, configFile, configDescription, feeds: [{ name, url, enabled, definedIn, credentials }], mapping, locked, packages: [{ id, sources }], warning, configChain, editTarget, clearsAbove }

Exits 1 when a package has no allowed feed.

sources-change{ version, changed, message, notes, sources }

Every sources edit (add, remove, enable, disable, map, unmap, clear-above). sources is what runthat sources <script> --json returns afterwards.

sources-which{ version, id, feeds, rule, reason }

feeds [] means restore will fail.

sources-test{ version, name, url, ok, needsSignIn, message }

Exits 0 whenever the test ran.

debug{ version, exitCode, output, outputTruncated, breakpoints: [{ line, verified, boundLine, message }], hits: [{ line, file, stack, locals }], hitLimitReached, error }

error is null, or { type, message, file, line, stack, locals } for an unhandled exception. The MCP tool debug_script returns the same object.