convention-cqs

Enforce Command-Query Separation so functions either modify state or return data.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sunLeee/optimization --skill convention-cqs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convention-cqs
Source: https://github.com/sunLeee/optimization/tree/main/.claude/skills/reference/philosophy/design/cqs
Command: npx skills add https://github.com/sunLeee/optimization --skill convention-cqs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Commands and queries are mixed in the same functions, leading to side effects in read paths and making code harder to test. This skill enforces the Command-Query Separation by ensuring a function is either a Command (state-changing, no return) or a Query (data retrieval, no side effects).

Core Features & Use Cases

  • Enforces strict separation of Command (state changes, no return) and Query (data retrieval, no side effects).
  • Improves testability, readability, and maintainability of software components, APIs, and services.
  • Use Case: design APIs and modules with predictable behavior and easier reasoning about data flow.

Quick Start

Refactor code so every function is either a Command or a Query; a Command modifies state and returns None, while a Query returns data without side effects.

Frequently Asked Questions about convention-cqs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is command-query separation in software design?

Command-query separation is a design principle requiring functions to be either Commands that modify state and return no data or Queries that retrieve data without side effects, improving predictability and readability.

How do I enforce command-query separation in my API design?

Refactor your API surfaces and module boundaries so every operation either modifies state without returning data or retrieves data without side effects, aligning with strict CQS guidelines.

Why should I separate commands and queries in my codebase?

Separating commands and queries prevents side effects in read paths, making software components significantly easier to test, maintain, and reason about across module boundaries.

When do I need to apply command-query separation?

Apply command-query separation when functions mix state-changing actions with data retrieval, causing unpredictable behavior and reducing the testability of your APIs and services.

Can a command function return data under strict command-query separation?

Under strict command-query separation, command operations must modify state without returning data, requiring queries to handle data retrieval separately to ensure no side effects in read paths.

What are the limitations of strict command-query separation?

Strict command-query separation may require extensive refactoring of existing APIs where state changes and data retrieval are deeply intertwined, potentially increasing initial code complexity.