Agent instructions

./gradlew updateKlokAgents (alias initKlokAgents) installs the Klok instructions for AI coding agents into the repository, so a Java developer who never installs the klok-cli gets the same files from IntelliJ's Gradle tool window as klok agents update writes. A file git tracks stays as it is, so in a repository that commits the platform files this is how the tenant's skills arrive:

  • KLOK-AGENTS.md with the platform rules and the section for the project type;
  • one managed row in every harness file (AGENTS.md, CLAUDE.md, GEMINI.md, .cursorrules, .clinerules, .github/copilot-instructions.md) pointing at KLOK-AGENTS.md;
  • the two rule files that are named after Klok (.cursor/rules/klok-agents.mdc, .agents/rules/klok-agents.md);
  • the platform skills the catalog zip ships, each folder whole, under .claude/skills/<name>/ and .agents/skills/<name>/ (on 2026-10-18 klok-cli, klok-datamodel, klok-docs, klok-release, klok-route, klok-solution and klok-worktree): SKILL.md with the marker, and every other file of the folder byte for byte, such as klok-cli's reference.md, exactly as klok agents update writes them;
  • the tenant's skills from its catalog, next to the platform skills (below);
  • the shared Klok knowledge blocks in knowledge/ next to KLOK-AGENTS.md (glossary.md, platform-rules.md, kloker-identity.md, roles/*.md, retired-patterns.txt), once the catalog zip carries agents/knowledge/.

The plugin does not author the platform text. The CLI assets in klok-integration-agent (packages/cli/assets/agents) are the single source. A build of that repository on main copies the tree to klok/framework/klok-gradle-dependency-catalog as agents/ plus klok-agents.zip. The Gradle task downloads the zip from main (the same repository updateKlokLibsToml reads klok-libs.versions.toml from) and writes the files. A local checkout can be used instead with -PklokAgentsAssetsDir.

What a repository commits is kept current for it: klok fleet upgrade commits the platform files once a week, and in the project templates on every agent release, so git pull brings them (Fleet status, upgrade and rebuild). Rewriting a tracked file here would turn the checkout dirty, and git pull --ff-only would then refuse the next change to that file, even with the same bytes. The last line of the task counts the files it left alone.

Tenant skills

KlokDocumentationEgress writes one skill per documented repository of the tenant, named after the repository's documentation id, plus the router skill <tenant>-context, into agents/skills/ of the tenant's private dependency catalog (<tenant>/framework/<tenant>-gradle-dependency-catalog; klok/framework/klok-tenant-dependency-catalog for tenant klok, whose skills are therefore called klok-context and klok-integration-…). Every skill directory is self-contained: SKILL.md and the data files beside it, data/facts.jsonl for a repository and data/{projects,routes,datamodels,topics,solutions}.jsonl for the router. See Catalog update for the catalog itself.

updateKlokAgents reads that catalog with the project's GitLab token (klokGitAuthToken or GITLAB_TOKEN as PRIVATE-TOKEN, CI_JOB_TOKEN in CI; the platform zip needs none): the last commit on main that touched agents/, then the agents/ subtree of that commit as a zip archive. It installs every skill directory whole into the same .claude/skills/ and .agents/skills/, after the platform skills, with the marker on the line after the YAML front matter:

<!-- klok-agents:file template=tenant-skill tenant=acme catalog-commit=<sha> -->

catalog-commit is that last agents/ commit, the same value klok agents update writes and compares, so the two tools agree on whether a repository is current. Tenant skills change with every documentation publish in the tenant, so they are meant to be installed, not committed: klok agents init adds them to .git/info/exclude; the Gradle task writes files and does not touch git.

A tenant skill is skipped, with a warning and the reason in the summary, when its name equals a platform skill's (the platform skill wins and its file is left as it is), when it has no YAML front matter (a SKILL.md whose first line is not --- does not load, so there is no point writing it), or when the directory already holds a SKILL.md without any Klok marker (that one is yours; rename or remove it to install the tenant skill).

When there is nothing to install the task says why and goes on with the platform files; tenant skills never fail a build. The summary line ends with tenant skills <n> from <repoPath>@<sha8> (with a skipped count when there is one) or tenant skills none (<reason>):

Situation What happens
no tenant is known (klok.tenant, KLOK_TENANT, CI_PROJECT_ROOT_NAMESPACE, CI_PROJECT_PATH) warning, none (no tenant known)
the value is not a lower-case slug warning, none ('Acme' is not a tenant)
HTTP 404 warning no tenant catalog at <path>; create it with klok.dev's tenant Ensure
HTTP 401 or 403 warning with the token hint
the catalog has no agents/ commit yet 0 from <path>@none; installed skills of that tenant are removed, since the catalog lists none
klokAgentsTenantSkills=false none (klokAgentsTenantSkills=false)

In every "none" case the tenant's installed skills are left exactly as they are.

What the task owns and what you own

The rules live in exactly one file. KLOK-AGENTS.md belongs to Klok: the task replaces it wholesale on every run, so never edit it by hand — put repository notes in AGENTS.md instead, next to the row. The klok named rule files, the platform skills, the tenant skills and the knowledge/ files are Klok's too and are rewritten the same way. The knowledge files and the files of a platform skill folder besides SKILL.md (klok-cli's reference.md) are copied byte for byte, without a marker, because tools read them as data (the retired pattern list, the command reference); edit them only in klok-integration-agent, packages/cli/assets/agents/knowledge/ and packages/cli/assets/agents/skills/ (reference.md is generated there by npm run reference -w @klok/cli). A tenant skill is edited nowhere: it is generated from the repository's documentation payload, and the next publish would overwrite an edit.

Every other harness file belongs to you. The task manages exactly one line in it:

@KLOK-AGENTS.md — read `KLOK-AGENTS.md` (Klok platform and repository rules) before doing anything else. <!-- klok-agents:row target=KLOK-AGENTS.md klok-cli=… -->

An update is a search and replace of that one line: the row is replaced where it stands, or added at the top when the file has none, and nothing else in the file is touched. Because the managed part is a single line it cannot grow, drift or be duplicated, and no force flag is needed to write into a file somebody else already owns.

A skill file is the skill text exactly as it ships, with the <!-- klok-agents:file … --> marker on the line after the YAML front matter. The marker must not come first: a SKILL.md whose --- is not on line 1 does not parse. Platform skills carry template=skill-<name> klok-cli=<version>, tenant skills template=tenant-skill tenant=<tenant> catalog-commit=<sha>.

The marker in SKILL.md owns the whole skill folder. A file that an earlier catalog shipped in a platform or tenant skill folder and the current one does not is removed and reported as removed (no longer part of the platform skill), so a dropped reference never lingers. A folder named like a platform skill whose SKILL.md carried no Klok marker was yours: the task writes the platform skill's files into it as before, but deletes none of your other files.

Retired skills are removed, by their marker

Before writing the current skills the task removes the skills that are gone, so a renamed or retired skill disappears from a repository instead of lingering forever. The decision keys on the marker in SKILL.md, never on the directory name: tenant klok's skills are named klok-context and klok-integration-…, so a name prefix could not tell a platform skill from a tenant skill or from yours. The rule, implemented identically in klok-cli, this plugin and the agent runner:

  1. a platform marker (template=skill-* with klok-cli=) is removed when the name is not in the platform set this version ships, whatever the directory is called. A copy of a Klok skill under another name keeps Klok's marker and is therefore removed too; drop the marker line to keep such a copy as your own;
  2. a tenant marker (template=tenant-skill tenant=<t>) is removed only when tenant t's catalog was read in this run and no longer lists the name. Another tenant's skill, or any tenant skill when the catalog could not be read, is left alone;
  3. a directory without a marker is never touched, whatever its name.

A removal is reported as removed with its reason, and -PklokAgentsDryRun=true reports everything, downloads included, without writing or deleting anything.

Migrating from the managed block

Versions before this one wrapped a whole copy of the rules in <!-- klok-agents:start … --> … <!-- klok-agents:end --> inside each harness file. The task strips that block the first time it touches a file and leaves the row in its place, so a repository migrates on the next run with no manual step. Text you wrote outside the block is kept. A skill that still carries the block marker is read as a platform skill of that old version and pruned when retired.

Properties

Property / environment variable Default Meaning
klokAgentsType / KLOK_AGENTS_TYPE from klok.projectType (INTEGRATION, DATAMODEL, APPLICATION, otherwise framework) integration, datamodel, documentation, application or framework; selects the project-type section of KLOK-AGENTS.md
klokAgentsTools / KLOK_AGENTS_TOOLS all comma separated: claude, codex, opencode, cursor, gemini, antigravity, cline, copilot
klokAgentsSkills / KLOK_AGENTS_SKILLS true also install the skills, platform and tenant
klokAgentsTenantSkills / KLOK_AGENTS_TENANT_SKILLS true also install the tenant's skills from its catalog
klokAgentsDryRun / KLOK_AGENTS_DRY_RUN false print what would be written and removed
klokAgentsZipUrl / KLOK_AGENTS_ZIP_URL catalog main raw URL of klok-agents.zip where to download the platform zip
klokAgentsAssetsDir / KLOK_AGENTS_ASSETS_DIR unset a local packages/cli/assets/agents checkout instead of the platform download
klokTenant / KLOK_TENANT (klok.tenant) CI_PROJECT_ROOT_NAMESPACE, else the root group of CI_PROJECT_PATH the tenant whose catalog holds the tenant skills
klokGitlabBaseUrl / KLOK_GITLAB_BASE_URL https://git.klok.dev the GitLab the tenant catalog is read from
klokGitAuthToken / GITLAB_TOKEN, CI_JOB_TOKEN authentication against GitLab, the same as for the repositories and the tenant catalog

klokAgentsForce is gone. It existed to overwrite a file that had no managed block; nothing is skipped any more, because the row merges into a file the task did not create and KLOK-AGENTS.md is Klok's to replace.

The same zip also feeds extractKlokKnowledge, which bundles the knowledge into a service's jar (see Documentation tasks); both tasks share the download cache in ~/.gradle/caches/klok-agents, where the tenant's agents/ tree is extracted under tenant/<tenant>/.

Broker topics

What an agent runs to list a project's broker topics, which files it reads and how it hands a missing topic or grant to a person is on Broker topics of a project, Who uses the tasks. updateKlokAgents installs nothing separate for it; the platform rules and skills come from the catalog like every other file on this page.

Relation to the klok-cli

klok-cli (klok agents update, klok fleet upgrade) and this task all read the platform files from the dependency catalog, this task from the zip. The plugin does not depend on the CLI package, so the two tools stay peers and each releases on its own, and they write the same bytes. The tenant skills come from the same tenant catalog in both tools, with the same marker and the same prune rule; the CLI additionally keeps them out of git and checks their freshness at session start (klok agents update). The global installation (klok agents init --global) stays with the CLI because Gradle has no business writing into a developer's home directory.