Getting started
Install runthat, write a script, lock it, run it, then connect a database. About ten minutes.
1. Install
- Install the .NET 10 SDK. Scripts build with it.
- Download runthat for Windows or Linux. On Windows, the installer can add
runthatto your PATH. Choose that option. - Open a new terminal and check it works:
> runthat --helpYou can also do everything below in the desktop editor: open a folder, create a script and press Run.
2. Write a first script
A script is a plain .cs file. Save this as hello.cs:
#:package [email protected] using Humanizer; "runthat".Pascalize().Dump(); TimeSpan.FromMinutes(90).Humanize().Dump("How long");
The #:package line pins a NuGet package to an exact version. runthat refuses a package without a version, so a script never picks up a different one by accident. Dump() prints any value as text, and Dump("Title") adds a heading.
3. Lock it
> runthat lock hello.cs
Locked hello.lock.json (net10.0).hello.lock.json lists every package the script needs, indirect ones too, with content hashes and the target framework. Commit it next to the script. When you change a #:package line, lock again.
4. Run it
> runthat hello.cs Runthat ── How long ── 1 hour # In CI and production, run exactly as locked: > runthat run --frozen hello.cs
The first plain run also creates the lock if there isn't one. --frozen uses the lock exactly and fails if it's missing, so use it in CI and on servers. To check a machine can run a script without running it:
> runthat check hello.cs Checking hello.cs ok Script directives are valid (1 pinned package) ok Lock file found (hello.lock.json) ok .NET SDK 10.0.404 installed (target net10.0, from the lock) ok All locked packages restored from the configured feeds ok Script compiles Ready to run on this machine.
5. Connect a database
Connection strings stay out of scripts. Save one on each machine. runthat asks for the value, so it doesn't end up in your shell history:
> runthat connection add Sales --provider sqlserver > runthat db test Sales
On Windows the value is encrypted for your user account. Then declare the connection in the script, pin a driver, and open it:
#:package [email protected] #:package [email protected] #:connection Sales using Dapper; await using var db = await Db.Sales.OpenAsync(); // a SqlConnection var orders = await db.QueryAsync<Order>("select top 10 * from dbo.Orders"); orders.Dump("Latest orders"); record Order(int Id, string Customer, decimal Total);
SQL Server, PostgreSQL, MySQL and MariaDB, SQLite and Oracle are supported. runthat db drivers lists the package line for each. On a CI server, set RUNTHAT_CONNECTION_SALES instead of saving a connection.
Run queries in parallel
Each OpenAsync() gives you a new pooled connection. Use one per task. SelectAsync does that for you:
var totals = await Db.Sales.SelectAsync(regions, (db, region) => db.ExecuteScalarAsync<decimal>("select sum(Total) from dbo.Orders where Region = @region", new { region }), maxParallel: 8); // results come back in the same order as regions
Prefer EF Core? Write #:connection Sales efcore, pin the EF Core provider, and Db.Sales.CreateContext() gives you a typed context.
Next steps
Ship a script
# One file with the lock inside, to share or deploy: > runthat export hello.cs # A folder that runs on a server with no package feeds and no .NET: > runthat publish hello.cs -r linux-x64
Let an AI agent use your scripts
runthat mcp is an MCP server. Add it to your agent or editor and it can list, read, lock, run and debug the scripts in the folders you give it. Runs always use the lock, and secrets show as [redacted].
> runthat mcp --folder D:\scriptsImport your existing queries
runthat import turns an existing query file into a script and locks it, pinning the package versions this machine already uses. The editor shows each package before it imports.
Questions? Email [email protected].