OpenSpec icon indicating copy to clipboard operation
OpenSpec copied to clipboard

Enhancement: Rules

Open som45oul opened this issue 10 months ago • 8 comments

CHANGE TYPE

Minor, non breaking change

PROBLEM

Currently, there is no documented standard for adding conventions, standards and decisions to your project, meaning:

  • Rules and conventions are tightly bound to project.md
  • Sharing rules and standards or conventions between projects is difficult
  • Community users have no way to share rules for common platforms, patterns, or design approaches
  • Users are forced to repeatedly respecify standards to their tastes

PROPOSAL

Standardise on having a rules/ folder in the openspec folder

Within this folder are rules files, for example:

typescript.rules.md
python.rules.md
solid.rules.md
performance.rules.md
docs.rules.md

etc.

Each .rules.md file contains constraints and standards for the agent to follow relative to that domain (tech stack, business process, architecture, etc). Creating .rules.md files for specific domains is encouraged to foster portability and sharing between projects and users. Conceptually, this is a technology-agnostic approach similar to the one used by Cursor Directory.

These files can be organised as the project sees fit, and are referenced as necessary in project.md.

The baseline of this proposal is minimal: just add an openspec/rules folder during init, perhaps with an openspec.rules.md by default. The openspec.rules.md file would specify how rules should be created and managed by the agent, enabling customisability and consistency.

While the folder would be created by default, users are not compelled to use it. Its use is entirely optional.

A useful optional addition might be enabling a slash command to add new rules:

/openspec:rules Always use UPPER_CASE for constant names in python

The AGENT would need instructions on how to file such rules into useful .rules.md file groupings based on topic.

Alternatively, users could prefix their rule with the domain: /openspec:rules python Always use UPPER_CASE for constants

The agent could then create or update python.rules.md

An alternative approach to pre-creating the rules folder could then be to create it on demand.

Rules could also be used as a pseudo memory bank for the agent, which could be useful as projects iterate and evolve.

BENEFITS

  • Consistency: Standardises the approach across projects and organisations
  • Visibility: Promotes a modular approach to composing SDD solutions
  • Composability: Encourages logical separation of key rulesets, enabling ease of composition and mixing different domains and platforms
  • Simplicity: Preserves the simple approach embraced by Openspec
  • Modularity: Enables users and AIs alike to reference relevant information without overloading context
  • Portability: Users can bring their kit with them to each new project and remix domains as required
  • Shareability: Opens the opportunity to enable a directory or library of prebuilt rules for various domains and disciplines
  • Efficiency: Avoids the need for explicit repetition of persistent ideas across projects, naturally accelerating progress

CHALLENGES

  • Additional folders and functions should be carefully considered to preserve the purity of the OpenSpec approach
  • Confusion: Users may find the presence of an empty or unexpected folder confusing at first
  • Overthinking: Users may be tempted to over engineer their projects by splitting rules out unnecessarily
  • Placing rules into separate files may make it more difficult for users to synthesise their project scope

som45oul avatar Jan 06 '26 14:01 som45oul

A minor footnote:

If implementing the slash commend option, perhaps using /openspec:rules (plural) is preferable for consistency. Main issue updated to reflect this.

som45oul avatar Jan 06 '26 21:01 som45oul

Also, perhaps the default openspec.rules.md could be the place where the Agent understands how to manage the rules? Main issue updated to reflect this.

som45oul avatar Jan 06 '26 22:01 som45oul

Hey bro, have you considered pointing openspec to the project's CLAUDE.md or AGENTS.md instead?

jasnzhuang avatar Jan 07 '26 01:01 jasnzhuang

Hey bro, have you considered pointing openspec to the project's CLAUDE.md or AGENTS.md instead?

Not sure what you mean, however the point of this proposal is to separate out rules so they can be made portable, reusable and composable. That is, you might develop a typescript.rules.md that applies all the patterns you like / prefer for Typescript, and can then import that into your next project. You could also combine this with other rules files, such as react.rules.md or tailwind.rules.md to build up a collection of rules, rather than having to specify them all in one place uniquely each time.

The end result is you develop (and share) a library of rules.md files that can accelerate agentic development, since you don't have to repeat yourself with every project.

I hope that makes sense.

som45oul avatar Jan 07 '26 01:01 som45oul

I think this proposal misses an important point about separation of concerns.

Rules are already handled by the IDE/coding environment layer (Cursor, Claude, Cline, etc.) through .cursorrules, .clinerules, CLAUDE.md, AGENTS.md and similar files. These tools already provide granular, portable, and composable rule management.

OpenSpec's job is to define the project structure and requirements, not to duplicate IDE-level functionality. If you need portable rules across projects, you should be leveraging your IDE's native rule system - that's literally what those files are for.

The comment about AGENTS.md / CLAUDE.md from @jasnzhuang is exactly on point -- these mechanisms already solve the problem you're describing. If OpenSpec starts managing rules, we're creating redundancy and coupling OpenSpec to IDE concerns.

Separation of concerns:

  • OpenSpec - Project specification and structure
  • IDE/Agent layer - Rules, conventions, coding style

This keeps OpenSpec focused and prevents it from becoming bloated with features that already exist elsewhere in the toolchain.

j2h4u avatar Jan 12 '26 11:01 j2h4u

You make a good point.

Except those things are not platform agnostic or composable.

Agent Skills however may be the right answer here. Albeit that the naming is a little awkward.

som45oul avatar Jan 12 '26 12:01 som45oul

I think there's an aspect of this that can already be addressed today without new features or folders.

The existing openspec/specs/ directory already accumulates project knowledge — architecture patterns, API conventions, data models, established behaviors. The problem is that this knowledge isn't used as context when planning new changes. Currently, the proposal and specs instructions only reference openspec/specs/ mechanically (to find folder names and copy requirement blocks for modifications). A change with only new capabilities never reads existing specs at all. The design instruction doesn't reference them either.

As @j2h4u points out, there's a separation of concerns question — IDE-level rules handle coding style, while OpenSpec handles project specification. But there's a gap between the two: existing specs should inform new specs and designs, and today they don't.

I think this can be solved today using existing config.yaml features, no code changes needed:

Option 1 — context field (injected into ALL artifacts):

context: |
  Key project specs to review before any change:
  - openspec/specs/api-conventions/spec.md — REST API patterns
  - openspec/specs/data-model/spec.md — Entity relationships
  - openspec/specs/error-handling/spec.md — Error response format

Option 2 — rules field (per-artifact, more targeted):

rules:
  design:
    - Read openspec/specs/api-conventions/spec.md before making API decisions
    - Read openspec/specs/data-model/spec.md before proposing schema changes
  specs:
    - Follow patterns established in openspec/specs/error-handling/spec.md

Option 2 is more interesting — each artifact only gets the specs relevant to it, no extra tokens where they don't apply.

For the default spec-driven schema, adding guidance to the design instruction like "review existing project specs at openspec/specs/ to understand established patterns" would make this work out of the box.

This doesn't replace the full rules/ folder proposal (which addresses portability and sharing, as @som45oul describes) — for that, a hierarchical spec structure with a rules/ or _global/ namespace (#662) could be the right model, treating rules as cross-cutting specs rather than a separate concept. But the config.yaml approach covers the immediate gap: existing project specs should inform the planning of new changes. And it works today (or should work) with the existing config.yaml mechanism.

lsmonki avatar Feb 11 '26 10:02 lsmonki

Thanks for raising this, @som45oul 🙏

This is about Standardize a portable/shareable openspec/rules/ folder of .rules.md files (+ optional /rules slash command). — an open-ended feature/design idea rather than a discrete, PR-actionable bug or task. To honor it properly we've moved it to Discussions, where it can keep evolving with community input and you can re-engage anytime:

👉 https://github.com/Fission-AI/OpenSpec/discussions/1549

The original issue (and any comments) stays here for the record, so nothing is lost — please continue the conversation in the discussion above. Closing the issue in favor of that thread.

clay-good avatar Aug 06 '26 18:08 clay-good