clickhouse-cs / examples
AGENTS.md102 starsChanged 2 months agoMITView on GitHub
Each example is a self-contained, runnable demonstration of one topic. dotnet run in this directory runs them all against a live server, and CI does the same on every pull request that touches examples/ or the driver, so an example that throws fails the build. Examples are grouped by transport: Http/ uses ClickHouseClient / ClickHouseConnection over HTTP, Tcp/ uses ClickHouseTcpClient over the native protocol. See Tcp/README.md for what is specific to the native client. ExampleConfig takes the server from environment…
- Deletes or force-pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,117 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ClickHouse.Driver/AGENTS.mdAGENTS.md
- ClickHouse.Driver.Tcp/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ClickHouse.Driver/CLAUDE.mdCLAUDE.md
- ClickHouse.Driver.Tcp/CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- reviewSkill
- issue-classificationSkill
- issue-prioritySkill
- reviewSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 72
Ask ExampleConfig for the endpoint with HttpEndpoint or TcpEndpoint when an example has to name or dial it itself.
- Very specific: line 89
If you add an example of that kind, leave it out of RunAllExamples, add its class name to _optIn, and list it here.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Examples — contributor guide
Each example is a self-contained, runnable demonstration of one topic. dotnet run in this directory
runs them all against a live server, and CI does the same on every pull request that touches
examples/ or the driver, so an example that throws fails the build.
Examples are grouped by transport: Http/ uses ClickHouseClient / ClickHouseConnection over
HTTP, Tcp/ uses ClickHouseTcpClient over the native protocol. See Tcp/README.md for what is
specific to the native client.
Running examples
cd examples
dotnet run # Run all examples
dotnet run -- --http # Run one transport's examples (or --tcp)
dotnet run -- --list # List class names, which --filter matches
dotnet run -- --filter basicusage # Run the examples whose class name matchesExampleConfig takes the server from environment variables, with localhost defaults. The "How to
run" section of README.md lists them. HTTP examples use port 8123, TCP examples port 9000.
Adding an example
Five steps. Skip any one of them and the example does not run.
- Put the file in the transport and category it belongs to:
Http/<Category>/<Category>_0NN_<Topic>.csorTcp/<Category>/Tcp_0NN_<Topic>.cs. Take the next free number in that category. - Declare
namespace ClickHouse.Driver.Examples;— not a namespace derived from the folder.ExampleRunnermatches that namespace exactly and will not find a class in any other one. Make it a
public static classwith apublic static Task Run(). Discovery requires both. The class name is what--listprints and what--filtermatches, so name it after the topic (BasicUsage), not after the file (Core_001_BasicUsage).A native-protocol example's class name must start with
Tcp(TcpBasicUsage). Every example shares one namespace, so it could not reuse an HTTP example's name anyway, and that prefix is howExampleInfo.Transportknows which endpoint to check before running it — and what--httpand--tcpselect on.- Add it to
RunAllExamplesinProgram.cs, under its category banner, in file-number order. That list is hand-maintained so the run order and the banners stay meaningful. An example missing from it still compiles, still appears in--list, and still runs under--filter— it just never runs in CI, so nothing tells you when it breaks. - Add it to the index in
README.md, in the matching section, with a one-line description.
Then run it (dotnet run -- --filter <topic>) and read the output. An example whose output does not
teach the topic is not finished.
Never hard-code a connection string
Take the server from ExampleConfig, which resolves environment variables over localhost defaults:
ExampleConfig.CreateHttpClient()/CreateHttpConnection()for the common case.ExampleConfig.HttpConnectionStringwhere a constructor takes the string itself.$"{ExampleConfig.HttpConnectionString};SomeKey=value"to add a key the assembled string does not already set. It setsHost,Port,Username,PasswordandDatabase, so appending any of those would produce a duplicate.ExampleConfig.HttpBuilder()to change one of those five. It returns a fresh builder each call.
Seven examples are exempt, because configuration is their subject, they use a separate endpoint, or
they start their own server:
Core_002_ConnectionStringConfiguration, Core_003_DependencyInjection,
Auth_001_JwtAuthentication, Tables_003_CreateTableCloud, Testing_001_Testcontainers,
Tcp_003_Tls, Tcp_005_Testcontainers. A literal connection string inside a comment,
shown to teach the reader what one looks like, is also fine.
Ask ExampleConfig for the endpoint with HttpEndpoint or TcpEndpoint when an example has to name
or dial it itself. There are no Host/Port properties: a whole-string override would not reach
them, so an example reading one could print an endpoint it did not connect to.
Examples deliberately left out of RunAllExamples
Three need infrastructure the CI server does not have, so they are registered nowhere and run only by explicit filter:
Tables_002_CreateTableCluster— needs a ClickHouse cluster.Tables_003_CreateTableCloud— needs ClickHouse Cloud credentials.Auth_001_JwtAuthentication— needs a JWT.
Their class names are also in ExampleRunner._optIn, which is what keeps --http and --tcp from
running them: those select by reflection, so leaving an example out of RunAllExamples does not on
its own keep a transport run from picking it up.
If you add an example of that kind, leave it out of RunAllExamples, add its class name to
_optIn, and list it here. Otherwise the omission is indistinguishable from having forgotten step 4.
Style
- Console output is the teaching surface. Print what you did and what came back, not just "OK".
- Show one thing well rather than covering an API exhaustively. A reader who wants the full surface reads the docs.
- Drop any table you create, in a
finally, andDROP TABLE IF EXISTSit before theCREATEas well. The second one is what lets a run survive an earlier run that was interrupted before itsfinally. - Name a table
example_<topic>, fixed, not unique per run. This project is not the test suites: it assumes one suite run at a time against a server, so it does not needCreateTableName. Two things do need a per-runGuid: a name the example needs the server not to have (a deliberately missing table), and a marker an example counts insystem.processesorsystem.query_log. A second run would otherwise make the first one's measurement or expected failure wrong. - Comments explain why the server or the driver behaves as it does, not what the line does.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

