Agents#
At the end of this page your coding agent knows the Specgate loop: it has slash commands for each step, an instruction file it reads on every session, and the rules it must not break.
You need: a project where specgate init has run, and one of the agent
tools below. specgate agents init offers thirteen --tool values: ten
agent tools — Claude Code, Cursor, Copilot, Windsurf, Aider, Gemini, Cline,
Codex, Antigravity and OpenCode — and, on request, three guards:
claude-plugin, opencode-plugin and codex-hooks. In
OpenCode the commands are /specgate-draft, /specgate-apply and so on,
written to .opencode/commands/; it reads AGENTS.md itself. The Claude Code
plugin is described in
Install the Claude Code plugin.
To run an agent unattended instead, see The harness.
Wire it in#
specgate init already does this for the agents your project uses. It looks
for .claude/ or CLAUDE.md, .cursor/, .github/copilot-instructions.md,
GEMINI.md, .windsurf/, .clinerules, .aider.conf.yml, .agents/ and
.codex/, installs the commands for each one it finds, and never overwrites a
file. AGENTS.md alone does not point to any one agent. --no-agents skips
this step. For any other agent, or later:
specgate agents init # every tool
specgate agents init --tool claude,cursor # only these
specgate agents init --dry-run # list the files, write nothingThis writes one slash command per step, from one definition:
| Slash command | What the agent does |
|---|---|
/specgate:explore | Reads specgate status: what is left, and the next command. |
/specgate:propose | Opens a change and writes its delta. |
/specgate:draft <module> | Turns a module of docs/brief.md into a draft change. |
/specgate:new | Adds one requirement straight to spec.md. |
/specgate:apply | Delivers one requirement: the test first, then the code, then the gate. |
/specgate:check | Runs the gate. |
/specgate:archive | Closes a change once every requirement in it is Implemented. |
/specgate:onboard | Installs Specgate on a repository that lacks it. |
It also writes the instruction file each tool reads:
.cursor/rules/specgate.mdc, .github/copilot-instructions.md,
CONVENTIONS.md, GEMINI.md, AGENTS.md and so on.
Agent Skills. specgate agents init --format skills writes the same steps
as skill folders (specgate-apply/SKILL.md, …) in the open Agent Skills
format: into .agents/skills/, which Codex and OpenCode read, and into the
skills folder of each tool you name with --tool claude|cursor|gemini (or,
without --tool, of each tool whose folder the project already has). A
SKILL.md that differs from what this version writes — one you changed, or one
an older Specgate wrote — is kept and reported as skill_kept; --force
replaces it. The Claude Code plugin carries the same skills, with an Agent Plugins
plugin.json (schema 1.0.0) and a Tessl .tessl-plugin/plugin.json
(rsaglobaltech/specgate); both find the skills in its skills/ folder.
The slash commands run the same commands you type in the terminal. An archive
the agent tries before every requirement is Implemented is refused, as it is
for you. Existing files are never overwritten without --force.
Upgrading Specgate? Run specgate update after you upgrade. It refreshes
the generated files with a three-way merge, so your edits stay and the new text
arrives; a conflict is marked in the file and reported, never resolved for you.
If a slash command was renamed, update moves your file to the new name with
your edits. If both the old and the new file exist, it touches neither and
tells you to keep one.
AGENTS.md is the contract#
init and adopt write AGENTS.md
(ADR-0031): what the
project is, its stack, the loop in a few steps, what never to do, and your
stack's rules, in at most 60 lines. Specgate keeps its part between
<!-- specgate:begin --> and <!-- specgate:end -->; everything outside that
block is yours, and no command rewrites it.
Its section From a brief or a Jira ticket tells the agent how to work on a draft change:
specgate propose --from-brief <module>orspecgate propose --from-ticket <KEY>opens the draft and writesDRAFTING.md. The agent follows it and re-runs the command until it reports "Ready to review". A person reviews the draft; the agent never archives it.- The agent never edits a change's
ticket.md(the copy of the Jira ticket). - Every commit message starts with the ticket key (
KAN-13 REQ-007: …), and never uses Jira Smart Commit commands such as#done, because they write to Jira.
See From a Jira ticket and From a brief.
Coming from AI_RULES.md? specgate update moves its text, unchanged,
below the Specgate block and removes the file (git keeps its history). Until
then both files are read, so no rule drops out of the agent's prompt.
Why the generated files are thin#
The generated files do not copy the delta format. A copy goes stale when the format changes, and an agent following a stale copy fails in a way that looks like the agent's fault. Instead they ask the engine:
specgate change instructions specs --jsonThis returns the template, the rules the validator enforces, the project's stack, the reserved REQ range, and what writing that file unblocks. The harness builds its prompt from the same call, so the slash commands, the harness and the MCP server cannot disagree. Each generated command says so: if this file and the engine disagree, the engine is right.
apply and archive are steps rather than files. They return the rules for
carrying out the step, with no template:
specgate change instructions apply --json
specgate change instructions archive --jsonThe JSON contract#
The commands an agent drives (status, plan, check, validate, apply,
change, doctor and more) take --json:
specgate validate . --json 2>/dev/null | jq .- One JSON document on standard output. Prose goes to standard error.
- Every document carries
status: a list of diagnostics, each with a stablecodeand afix. - Branch on
code, never onmessage: the message is prose and may change. - A failure has the same keys as a success, so a parser never meets a different shape.
- Exit codes:
0success,1failure or a gate finding,2usage error.
The agent contract has the full rules and every diagnostic code. It is generated from the source, and CI fails when it drifts.
The guards#
Instruction files are words an agent may walk past. The Claude Code plugin
(--tool claude-plugin), the OpenCode plugin (--tool opencode-plugin) and
Codex's hooks (--tool codex-hooks, which writes .codex/hooks.json) add
three hooks that run whatever the agent decides:
Session start — the session is told the project is spec-driven, the open change, the requirements it still owes and the next one.
Every tool call — the guard judges the whole working tree, shell commands included: a file written with
cat >is caught on the next call. It refuses:- a write to a source file while no change is open, or while no test new or changed in the working tree — or a sealed acceptance test — names a requirement of the open change;
- a person's acts:
specgate change approve,config set agent_guard offorSPECGATE_GUARD=,apply --steps-reviewed,SPECGATE_ASSUME_TTY=; - writes to the control files:
.specgate/config.json,.specgate/gate.yaml,.specgate/evidence/, anyapprovals.json, andapproved:in achange.yaml; - writes to a sealed acceptance test (
acceptance_sealed).
A refusal names the step to take instead, and never how to turn the guard off:
text specgate: write the test for REQ-311 first — change `module-map`. A test file new or changed in the working tree that names REQ-311 is the link; then src/core/map/scan.ts is allowed, then `specgate apply REQ-311`.Tests that are not sealed, specs, features, docs and Markdown are not refused by the test-first rule. When code begins, the guard records the step-definition files; changing them afterwards fails the gate (
steps_changed_after_code) until a person runsspecgate apply REQ-NNN --steps-reviewedat a terminal.The gate — before the session ends (Claude Code, Codex) or when it goes idle (OpenCode), a red gate sends its findings back, once per prompt.
The guards stop a session, not a determined process outside it. The
harness and specgate compat run add an outside judge: they read
the controls before the agent starts and compare when it stops
(controls_changed_by_session). Without a harness or CI, that check is absent.
--tool claude-plugin writes a plugin, not a project's settings. Run in
a Specgate project, it writes the plugin to .claude/specgate-plugin/, where
the guard never reads it as untested source; given another --project-dir,
there. The folder holds plugin.json (and .claude-plugin/plugin.json), commands/,
skills/, scripts/, hooks/hooks.json and .mcp.json, and its hooks call
${CLAUDE_PLUGIN_ROOT}/scripts/…, a path only Claude Code fills in for an
installed plugin. Writing the folder activates nothing: no hook runs until the
plugin is installed in Claude Code — see
Install the Claude Code plugin,
or the command below, which prints the two /plugin lines to paste into
Claude Code (/plugin marketplace add rsaglobaltech/specgate, then
/plugin install specgate@specgate).
Install the Claude Code and OpenCode guards once for every project:
specgate agents install --globalOpenCode's plugin goes into its global folder (~/.config/opencode, or
$XDG_CONFIG_HOME/opencode); for Claude Code the command prints the two
/plugin lines that install it from this repository's marketplace. Codex's
hooks are per project: specgate agents init --tool codex-hooks. A project
without spec.md sees nothing from any of them. A person turns the test-first
guard off for one project with specgate config set agent_guard off, or for
one session with SPECGATE_GUARD=off, from their own terminal; the guard
refuses both from inside a session.
Antigravity#
Antigravity gets two files: .agents/rules/specgate.md, the workspace rules,
and .agents/mcp_config.json, a connection to the
MCP server, so the agent reads the current spec tree instead of a
snapshot. Both paths follow Antigravity's own documentation. The rules file
stays far below Antigravity's 12,000-character limit, past which a rule file is
cut off without warning. Antigravity's GEMINI.md is covered by the gemini
tool.
Next#
- Change a shipped requirement: the loop the agent drives
- The MCP server: the same loop as tools