Skip to content
/

openspec-schemas (kmhalvin)

openspec-schemas-kmhalvin · kmhalvin/openspec-schemas · ★ 1 · last commit 2026-04-09

Prevents context budget exhaustion and hallucination on complex brownfield changes via subagent delegation and mandatory session restarts.

Best whenContext isolation between planning phases, not within phases, is the most important quality lever for AI coding agents on large codebases.
Skip ifLong monolithic agent sessions that accumulate stale context, Autonomous agent decisions at architecture review points without human validation
vs seeds
openspec(same CLI, same command surface). Unique architectural contribution: two schemas implementing context-isolation orchestr…
Primitive shape 2 total
Subagents 2
00

Summary

OpenSpec Schemas (kmhalvin) — Summary

OpenSpec Schemas by kmhalvin is a two-schema extension pack for OpenSpec implementing advanced context engineering techniques focused on subagent dispatch and forced context isolation. The subagent-spec-driven schema orchestrates a Main Agent / Subagent pair for every artifact in the spec-driven workflow — the main agent writes .instructions/<artifact>.md prep files that the subagent executes in an isolated context window, keeping the main agent's context lean throughout a brownfield codebase analysis. The qrspi schema implements the ACE-FCA (Advanced Context Engineering for Coding Agents) QRSPI method (Questions → Research → Design → Structure → Plan → Implement) with mandatory autonomous "Context Drops" (session restarts) between phases to eliminate instruction budget exhaustion and horizontal hallucination. Both schemas ship as YAML+Markdown copyable folders that activate via openspec/config.yaml. With 1 star and a single contributor, this is a niche but technically sophisticated extension.

Compared to seeds: closest to openspec (same CLI, same command surface) but adds a two-tier Main Agent / Subagent orchestration pattern inside a single-user OpenSpec workflow — something no seed achieves natively. The QRSPI Context Drop mechanism is unique in the corpus.

01

Overview

OpenSpec Schemas (kmhalvin) — Overview

Origin

Published by GitHub user kmhalvin as a community OpenSpec schema pack. No blog post or companion content found. The QRSPI schema is attributed to HumanLayer's "Dex" from a talk titled "Everything We Got Wrong About RPI."

Philosophy

From the README:

"These schemas define structured workflows to help AI agents navigate complex changes, execute step-by-step reasoning, and maintain high-leverage alignment with human developers."

The core insight driving both schemas is context budget management: large monolithic prompts exhaust an LLM's instruction budget, causing feature hallucination. The solution is either (a) subagent delegation (subagent-spec-driven) or (b) forced session restarts between phases (qrspi).

Schemas

subagent-spec-driven

A spec-driven workflow where the main agent never executes research or drafting directly. Instead:

  1. Main agent writes .instructions/<artifact>.md — explicit instructions for a subagent
  2. Main agent spawns a subagent to execute those instructions
  3. Subagent writes the artifact and returns control
  4. Pattern repeats for every artifact in the chain

The subagent isolation keeps each phase focused. The main agent accumulates context across phases but offloads the heavy exploration work.

qrspi (Questions → Research → Design → Structure → Plan → Implement)

Attributed to ACE-FCA methodology. Key distinguishing feature: mandatory Context Drops between certain phases. A Context Drop is either:

  • Calling an agent framework tool like new_task to start a fresh session, OR
  • Halting with "Please start a New Chat / Task, then run /opsx-continue.md"

This guarantees zero carry-over of prior context between phases, preventing the main agent from "hallucinating" designs based on stale memory.

The schema also mandates a conversational Q&A phase (draft-questions) before research, and a design review phase before planning.

02

Architecture

OpenSpec Schemas (kmhalvin) — Architecture

Distribution

  • Type: standalone-repo (copyable schema folders)
  • Install by copying schema directory into project or user ~/.openspec/schemas/
  • Activation via openspec/config.yaml

Runtime Requirements

  • OpenSpec CLI >= 1.0.0 (npm install -g @fission-ai/openspec@latest)
  • Node.js >= 20 (via OpenSpec)
  • Subagent capability in the AI tool (Task() tool in Claude Code, or external CLI like cline -y)

Directory Structure

openspec/
└── schemas/
    ├── subagent-spec-driven/
    │   ├── README.md
    │   ├── schema.yaml
    │   └── templates/
    │       ├── instruction.md
    │       ├── research-proposal.md
    │       ├── research-feasibility.md
    │       ├── proposal.md
    │       ├── spec.md
    │       ├── design.md
    │       ├── tasks.md
    │       └── ...
    └── qrspi/
        ├── README.md
        ├── schema.yaml
        └── templates/
            ├── questions.md
            ├── research.md
            ├── design-proposal.md
            ├── design.md
            ├── structure.md
            ├── plan.md
            └── ...

Artifacts Written by Schemas

subagent-spec-driven artifact paths

Main agent prep files: .instructions/<artifact>.md Research files: .research/codebase.md, .research/feasibility.md, .research/specs.md, .research/design.md Standard artifacts: proposal.md, specs/**/*.md, design.md, tasks.md

qrspi artifact paths

Alignment files: .alignment/question-research.md, .alignment/design-proposal.md Research files: codebase.md, questions.md Planning files: design.md, structure.md, plan.md

Target AI Tools

Same as OpenSpec (29+ tools) but the subagent capability requirement narrows effective use to Claude Code (Task() tool) or environments that support an external CLI subagent.

Subagent Config

If using an external CLI, configure in openspec/config.yaml:

context: |
  Project rules for AI Agents:
  - Subagent CLI command: 'cline -y'
03

Components

OpenSpec Schemas (kmhalvin) — Components

subagent-spec-driven Artifacts (18)

Paired structure: each *-prep artifact is executed by the main agent; each matching artifact is executed by the subagent.

Artifact ID Executor Output
research-proposal-prep Main .instructions/research-proposal.md
research-proposal Subagent .research/codebase.md
research-feasibility-prep Main .instructions/research-feasibility.md
research-feasibility Subagent .research/feasibility.md
draft-proposal-prep Main .instructions/draft-proposal.md
draft-proposal Subagent proposal.md
research-specs-prep Main .instructions/research-specs.md
research-specs Subagent .research/specs.md
draft-specs-prep Main .instructions/draft-specs.md
draft-specs Subagent specs/**/*.md
research-design-prep Main .instructions/research-design.md
research-design Subagent .research/design.md
draft-design-prep Main .instructions/draft-design.md
draft-design Subagent design.md
draft-tasks-prep Main .instructions/draft-tasks.md
draft-tasks Subagent tasks.md
apply Main Implementation

qrspi Artifacts (10)

Artifact ID Executor Output Context Drop?
question-research-prep Main .instructions/question-research.md No
question-research Subagent .alignment/question-research.md No
draft-questions Main questions.md Yes — after
research-codebase Main codebase.md Yes — after
design-proposal-prep Main .instructions/design-proposal.md No
design-proposal Subagent .alignment/design-proposal.md No
draft-design Main design.md Yes — after
draft-structure Main structure.md Yes — after
draft-plan Main plan.md Yes — after
apply Main Implementation No

Templates

Both schemas ship template files for every artifact in templates/ directories.

Commands/Skills/Hooks

None added by this repo. Standard OpenSpec command surface.

05

Prompts

OpenSpec Schemas (kmhalvin) — Prompts

Excerpt 1: subagent-spec-driven — research-proposal-prep instruction

From openspec/schemas/subagent-spec-driven/schema.yaml:

- id: research-proposal-prep
  instruction: |
    ## Main Agent Instructions
    
    Write detailed instructions for a subagent to research the codebase for this change.
    
    Include:
    - What to explore (directories, files, patterns)
    - What patterns to find (similar features, conventions)
    - Expected output format (file:line references, structured findings)
    ...
    - CRITICAL: Read the XML comments in the template carefully. You MUST replace 
      `{ARTIFACT_ID}` and `{CHANGE_NAME}` with actual execution values, and provide 
      explicit absolute paths.
    
    ## REQUIRED: After Generating `.instructions/research-proposal.md`
    
    Spawn a subagent to execute the next artifact. If your agent has a built-in 
    subagent tool (e.g. Task()), use it directly. Otherwise, read your provided 
    project context to find the configured subagent CLI command.
    CRITICAL: Main Agent MUST replace `{CHANGE_NAME}` with the real change name 
    string before executing so the subagent has the correct context!
    Pass the following prompt to the subagent:
    "/opsx-continue Working on change: {CHANGE_NAME}\n\nExecute ONLY subagent 
    artifacts (research-*, draft-*). Do NOT execute *-prep artifacts."

Technique: Delegation-by-instruction — the main agent writes a file that becomes the subagent's context. The instruction enforces placeholder substitution before dispatch.


Excerpt 2: qrspi — draft-questions Context Drop instruction

From openspec/schemas/qrspi/schema.yaml:

- id: draft-questions
  instruction: |
    ## Main Agent Instructions

    Read the context, original ticket, and `.alignment/question-research.md`. The 
    Subagent has formulated detailed, codebase-specific technical questions inside 
    this document.
    DO NOT immediately write `questions.md`. First, present these technical questions 
    to the user in this chat and work back and forth to resolve them.
    
    ONLY ONCE the Subagent's technical questions are answered and resolved, formalize 
    the final summary and objective research directives into `questions.md`.
    
    ## REQUIRED: Context Drop
    After creating `questions.md`, you MUST perform a Context Drop to clear your 
    session memory before research begins.
    - If your configured agent framework supports starting new tasks autonomously 
      (e.g., via a `new_task` tool), use it to start a new task with the context: 
      `/opsx-continue.md`
    - Otherwise, you MUST halt execution (e.g., using `attempt_completion` or 
      explicitly stopping) and instruct the human: "Please start a New Chat / Task, 
      then run `/opsx-continue.md`"

Technique: Mandatory conversational gate before document production, followed by forced context wipe. The "DO NOT immediately write" instruction prevents the common AI failure mode of skipping human alignment.


Excerpt 3: qrspi — research-codebase instruction (clean session)

- id: research-codebase
  instruction: |
    ## Main Agent Instructions

    Read the answered Q&A in `questions.md`. Deeply explore the codebase without 
    making architectural assumptions, and output objective facts into `codebase.md`.

Technique: Minimal instruction after a Context Drop — the agent reads only questions.md (no ticket history, no prior conversation). Stripped context forces objective analysis.

09

Uniqueness

OpenSpec Schemas (kmhalvin) — Uniqueness

differs_from_seeds

Closest seed: openspec (same CLI, same command surface). The architectural delta is twofold: (1) subagent-spec-driven introduces explicit Main Agent / Subagent orchestration inside the OpenSpec artifact DAG — the main agent writes instruction files that become subagent context, keeping each execution context lean for brownfield codebases. No seed implements this pattern inside OpenSpec; the closest is claude-flow which has subagents but as a separate agent-class system, not as an OpenSpec schema. (2) qrspi introduces mandatory Context Drops (forced session restarts) between planning phases, implementing the ACE-FCA methodology of eliminating accumulated instruction budget exhaustion. This context wipe technique is not present in any seed framework; it is architecturally opposite to seeds like taskmaster-ai and claude-flow which accumulate context across a long session.

Positioning

The two schemas target different failure modes of long AI coding sessions on complex codebases:

  • subagent-spec-driven: prevents context overflow by delegating heavy work to isolated subagents
  • qrspi: prevents hallucination carryover by hard-resetting conversational memory at critical junctures

The QRSPI acronym and mandatory human conversations (Q&A + design review) also reflect a philosophy that AI agents should not be autonomous at the highest-risk decision points.

Observable Failure Modes

  1. Placeholder substitution: both schemas require the main agent to replace {CHANGE_NAME} and {ARTIFACT_ID} before spawning subagents. If the agent fails to substitute, the subagent receives broken paths and produces incorrect outputs.
  2. Manual Context Drop failure: if the AI tool doesn't support new_task, the human must manually start a new chat. If they forget to run /opsx-continue.md, the workflow stalls silently.
  3. Subagent artifact scope creep: the subagent instruction "Execute ONLY subagent artifacts. Do NOT execute *-prep artifacts" can be violated if the subagent has full tool access and proceeds autonomously.
  4. Depth of qrspi: 9 artifacts before a single line of code is written — teams may abandon the workflow on small changes.
04

Workflow

OpenSpec Schemas (kmhalvin) — Workflow

subagent-spec-driven Workflow

Pattern: Alternating Main Agent / Subagent execution for every artifact.

Phase Artifacts Approvals
Proposal prep → research-proposal → prep → research-feasibility → prep → draft-proposal Human review after proposal.md
Specs prep → research-specs → prep → draft-specs Human review
Design prep → research-design → prep → draft-design Human review
Tasks prep → draft-tasks
Apply Implementation Pause on blockers

Key instruction: "CRITICAL: Main Agent MUST replace {CHANGE_NAME} with the real change name string before executing."

Subagent isolation rule: "Execute ONLY subagent artifacts (research-, draft-). Do NOT execute *-prep artifacts."

qrspi Workflow

Pattern: Sequential with mandatory Context Drops between phases.

Phase Artifact Context Drop After? Human Gate?
Pre-question mapping question-research (subagent) No No
Questions draft-questions Yes Yes — Q&A with user
Research research-codebase Yes No
Design Proposal design-proposal (subagent) No No
Design Review draft-design Yes Yes — design approval
Structure draft-structure Yes No
Plan draft-plan Yes No
Implement apply No Verify success criteria

Context Drop Mechanism

After each phase marked "Yes", the agent MUST:

  1. If new_task tool is available: call it with /opsx-continue.md — autonomous restart
  2. Otherwise: halt and instruct human: "Please start a New Chat / Task, then run /opsx-continue.md"

This completely clears conversational memory before the next phase.

Approval Gates

  • qrspi: 2 explicit human-review conversations (questions and design)
  • subagent-spec-driven: proposal.md human review (same as standard OpenSpec)
06

Memory Context

OpenSpec Schemas (kmhalvin) — Memory & Context

State Storage

File-based, per-change folder (extends standard OpenSpec):

openspec/changes/<name>/
├── .instructions/          # Main agent prep files (ephemeral guides)
│   ├── research-proposal.md
│   ├── research-feasibility.md
│   ├── draft-proposal.md
│   └── ...
├── .research/              # Subagent research outputs
│   ├── codebase.md
│   ├── feasibility.md
│   ├── specs.md
│   └── design.md
├── .alignment/             # qrspi alignment artifacts
│   ├── question-research.md
│   └── design-proposal.md
├── proposal.md
├── specs/
├── design.md
├── tasks.md
├── questions.md            # qrspi Q&A formalization
├── codebase.md             # qrspi objective research
├── structure.md            # qrspi structure outline
└── plan.md                 # qrspi implementation plan

Context Management Philosophy

Both schemas are explicitly designed for context isolation:

  • subagent-spec-driven: each subagent starts with only the .instructions/<artifact>.md file and its template — no accumulated conversation context from the main agent
  • qrspi: Context Drops force the main agent to start each planning phase with only the latest artifact files — zero memory of earlier conversations

Persistence

  • Scope: project (per-repository)
  • Cross-session: Yes — files persist; resumable via OpenSpec's standard continue mechanism
  • No compaction needed within a phase — Context Drops serve as compaction points

Handoff Mechanism

  • subagent-spec-driven: main agent writes .instructions/<artifact>.md → spawns subagent → subagent reads instructions → writes output → returns control
  • qrspi: main agent writes phase artifact → performs Context Drop → new session reads only the artifact file
07

Orchestration

OpenSpec Schemas (kmhalvin) — Orchestration

Multi-Agent

Yes (subagent-spec-driven and qrspi). Both schemas implement a two-tier Main Agent / Subagent pattern.

Orchestration Pattern

Sequential with hierarchical dispatch. Not parallel-fan-out — agents are dispatched serially, one at a time. The main agent is always the orchestrator; subagents are ephemeral workers for a single artifact.

Main Agent → Subagent (blind execution) → Main Agent → Subagent → ...

Subagent Definition Format

Inline-instruction: subagent behavior is defined per-artifact in schema.yaml instructions. No persona files. No persistent agent identity.

Spawn Mechanism

  • Primary: Claude Code Task() tool (built-in subagent spawning)
  • Fallback: external CLI configured in openspec/config.yaml (e.g., cline -y)

Isolation Mechanism

Context isolation (not file/process isolation). Each subagent starts with an empty conversation window containing only its explicit instruction file. The main agent's accumulated context is not passed.

qrspi Context Drop achieves stronger isolation than subagent dispatch — the entire main agent session is discarded.

Multi-Model

No. Single model throughout.

Execution Mode

Interactive-loop with human checkpoints at Q&A (qrspi) and design review (qrspi).

Prompt Chaining

Yes. The output of each artifact (especially .instructions/*.md files) becomes the explicit input for the next agent invocation.

Max Concurrent Agents

1 (always sequential).

Consensus Mechanism

None.

Crash Recovery

Files persist between sessions. Resumable via OpenSpec continue mechanism. However, if a Context Drop was manual (human had to start new chat), the human must remember to run /opsx-continue.md in the new session.

08

Ui Cli Surface

OpenSpec Schemas (kmhalvin) — UI & CLI Surface

Dedicated CLI Binary

No. No CLI shipped by this repo.

Local UI

None.

IDE Integration

Standard OpenSpec command surface (inherits from base OpenSpec installation).

Install Procedure

Single-line bash install:

SCHEMA="subagent-spec-driven" && \
mkdir -p openspec/schemas/$SCHEMA && \
curl -sSL https://raw.githubusercontent.com/kmhalvin/openspec-schemas/main/openspec/schemas/$SCHEMA/schema.yaml \
  -o openspec/schemas/$SCHEMA/schema.yaml && \
curl -sSL "https://api.github.com/repos/kmhalvin/openspec-schemas/contents/openspec/schemas/$SCHEMA/templates" \
  | grep '"download_url"' | cut -d '"' -f 4 \
  | xargs -n 1 -I {} sh -c 'mkdir -p "openspec/schemas/'$SCHEMA'/templates" && curl -sSL "{}" -o "openspec/schemas/'$SCHEMA'/templates/$(basename "{}")"'

Update openspec/config.yaml:

schema: subagent-spec-driven

Observability

Beyond standard OpenSpec file artifacts, both schemas create additional intermediate files that serve as a natural audit trail:

  • .instructions/*.md — main agent's explicit directions to subagents
  • .research/*.md — subagent research outputs
  • .alignment/*.md — qrspi pre-design alignment artifacts

Related frameworks

same archetype · same primary tool · same memory type

claude-mem (thedotmack) ★ 78k

Background worker service captures every tool call as an observation, AI-compresses sessions, and auto-injects relevant past…

pi (badlogic/earendil) ★ 55k

A minimal, hackable, multi-provider terminal coding agent that adapts to your workflows via npm-installable TypeScript Extensions…

Agent Skills (Addy Osmani) ★ 46k

Encodes senior-engineer software development lifecycle as 23 auto-routed skills and 7 slash commands for any AI coding agent.

wshobson/agents Plugin Marketplace ★ 36k

Single Markdown source for 83 domain-specialized plugins that auto-generates idiomatic artifacts for five AI coding harnesses.

TabbyML/Tabby ★ 34k

Self-hosted AI coding assistant server (alternative to GitHub Copilot) with admin dashboard, RAG-based completions, and multi-IDE…

Compound Engineering ★ 17k

Make each unit of engineering work compound into easier future work via brainstorm→plan→execute→review→learn cycles.