specgate/docs v1.8.0

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:

bash
specgate agents init                          # every tool
specgate agents init --tool claude,cursor     # only these
specgate agents init --dry-run                # list the files, write nothing

This writes one slash command per step, from one definition:

Slash commandWhat the agent does
/specgate:exploreReads specgate status: what is left, and the next command.
/specgate:proposeOpens a change and writes its delta.
/specgate:draft <module>Turns a module of docs/brief.md into a draft change.
/specgate:newAdds one requirement straight to spec.md.
/specgate:applyDelivers one requirement: the test first, then the code, then the gate.
/specgate:checkRuns the gate.
/specgate:archiveCloses a change once every requirement in it is Implemented.
/specgate:onboardInstalls 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> or specgate propose --from-ticket <KEY> opens the draft and writes DRAFTING.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:

bash
specgate change instructions specs --json

This 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:

bash
specgate change instructions apply --json
specgate change instructions archive --json

The JSON contract#

The commands an agent drives (status, plan, check, validate, apply, change, doctor and more) take --json:

bash
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 stable code and a fix.
  • Branch on code, never on message: 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: 0 success, 1 failure or a gate finding, 2 usage 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 off or SPECGATE_GUARD=, apply --steps-reviewed, SPECGATE_ASSUME_TTY=;
    • writes to the control files: .specgate/config.json, .specgate/gate.yaml, .specgate/evidence/, any approvals.json, and approved: in a change.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 runs specgate apply REQ-NNN --steps-reviewed at 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.

How the guard decides on one tool call A tool call — Write, Edit, a patch or a shell command — goes through four questions in order. First: is it a person's act — approving a change, switching the guard, or writing a file the controls keep, such as .specgate/gate.yaml, .specgate/config.json, .specgate/evidence or a change's approvals.json? If yes, it is refused. If no: does it write a sealed test? If yes, it is refused, because the sealed test is the contract. If no: does it write a source file? If no, it is allowed. If yes: is a change open, and does a test that is changed in the working tree, or a sealed test, name one of its requirements? If no change is open, it is refused with the step to take: open one with specgate propose. If a change is open and no test names its requirement, it is refused: write the test first. If yes, it is allowed, and the guard records the step-definition files. Tool call Write · Edit · patch · shell A person's act? Sealed test? Source file? A change open, and a test that names its REQ? Refuse a person's act: approving, the guard, a control file — .specgate/ · approvals.json Refuse it is the contract Refuse no change open: open one, specgate propose <id> else: write the test first Allow Allow and record the steps no no yes yes yes no no yes
The guard asks four questions of every tool call, in this order — a control file counts as a person's act, and a source write with no change open is refused; a refusal names the step to take instead.

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:

bash
specgate agents install --global

OpenCode'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#