AI Coding Workflow with Rules and Skills: A Practical Guide for AI Coding Tools
This article explains how to build a complete AI-assisted development workflow using two configuration types: Rules and Skills. It covers how project-level rules and reusable skill modules define coding standards, naming conventions, immutability, error handling, and security practices. It also shows how to structure a layered standards system, write skills for logging and cloud-native engineering, and close the loop from code generation to AI-assisted review and documentation. Teams can use this approach to reduce repeated explanations, keep code style consistent, and shift security requirements earlier in development.
In AI-assisted collaborative development, coding standards and best practices are mainly defined and managed through two types of configuration files: Rules and Skills. This mechanism captures individual or team coding habits, quality standards, and security requirements, then lets the AI load and apply them automatically. The result is consistent code quality and a fundamental fix for the problem of having to explain the same rules over and over.
This article takes a deep look at how to use these two configuration types to build a complete development workflow, covering everything from basic standard definitions to complex engineering practices.
1. Building a Standards System with Rules and Skills
There are two core modes for managing code standards: Rules and Skills. Understanding how they differ and combining them sensibly is the prerequisite for an efficient workflow.
- Rules: Usually located in a dedicated configuration folder at the project root (such as
.claude/rules/), these are project-level mandatory or guiding constraints. They define common standards that apply across the entire codebase, ensuring all developers and the AI work from the same baseline. - Skills: Usually located in a
skills/directory, these are reusable knowledge modules. They package best practices for specific technology stacks, or personal and team-specific workflows and habits. Compared with rules, skills focus more on conveying a “methodology.”
1.1 A Layered Architecture for Defining Standards
A mature industrial-grade project should have a layered and extensible standards system. Below is a typical layered architecture for defining standards:
| Layer | Configuration File Example | Purpose and Content |
|---|---|---|
| General Project Rules | .claude/rules/coding-style.md |
Defines the basic style followed across the project, such as indentation rules (2 or 4 spaces), file organization, immutability requirements, and so on. |
| Project-Specific Rules | CLAUDE.md (project root) |
Project-level specific standards file. It can contain particular business constraints, such as “variable names must use camelCase” or “never call the database directly from the controller layer.” |
| Multi-Language Best Practices | skills/coding-standards/ |
Packages general coding standards and defensive programming techniques for multiple programming languages. |
| Language-Specific Skills | skills/go-style/, skills/python-best-practices/ |
Provides advanced conventions, idioms, and performance optimization guidance for specific languages such as Go, Python, and TypeScript. |
| Personal/Team Habits | skills/my-coding-style/ or skills/team-workflow/ |
Captures a team’s unique coding style, commenting habits, Git commit message format, or error handling patterns. |
With the above files configured, the AI automatically retrieves and follows these built-in rules when writing or reviewing code, without developers having to remind it in the chat every time. This “define once, apply everywhere” mechanism is the cornerstone of automated quality control.
2. Core Coding Standards in Detail
Within the framework above, the specific content of the standards determines code maintainability. The following sections focus on best practices for several key dimensions.
2.1 Naming Conventions
Naming is the first line of defense for code readability. In a custom skill (such as my-coding-style), the following mandatory rules should be made explicit:
- Variables: Use camelCase consistently. Variable names should be nouns and should be self-explanatory.
- Recommended:
userName,dataList,orderTotal - Not recommended:
a,temp,data1
- Recommended:
- Functions/Methods: Must start with a verb that clearly expresses the action being performed.
- Recommended:
getUserData(),calculateTotal(),validateInput() - Not recommended:
userData(),total(),check()
- Recommended:
- Constants: All uppercase with words separated by underscores, representing immutable global configuration.
- Examples:
MAX_RETRY_COUNT,API_BASE_URL
- Examples:
- Classes/Interfaces: Usually PascalCase, and class names should be nouns.
2.2 Code Structure and Immutability
Modern frontend and backend development increasingly favors functional programming ideas, and AI-generated code should follow this trend:
Immutability requirements: Declare variables with
constby default and avoidvar. For operations on objects and arrays, prefer returning a new object rather than mutating in place.// Recommended: return a new arrayconst newList = list.map(item => ({ ...item, processed: true }));// Not recommended: mutate in placelist.forEach(item => item.processed = true);
- Single Responsibility Principle (SRP): Each function or module should be responsible for only one thing. When generating code, the AI should be constrained to split large functions into several smaller ones, with a recommended limit of no more than 50 lines per function.
- Error handling pattern: Silently swallowing exceptions is forbidden. The skill file should require that all asynchronous operations include
try-catchor.catch()handling, and that they must either log the error or throw a meaningful error message.
2.3 Security Practices
Security is a red line in coding standards that cannot be ignored. When generating code, the AI must have the following security rules built in:
- Input validation: All external input (API requests, user forms) must be validated and sanitized.
- Sensitive information management: Hardcoding keys, tokens, or database connection strings in code is strictly prohibited; they must rely on environment variables or a configuration center.
- Dependency management: When introducing third-party libraries, check their license compatibility and known vulnerabilities.
3. Writing and Applying Skills
Skills are more than a collection of rules; they are operation manuals for complex tasks. For example, for a specific technology stack (such as a particular cloud vendor’s SDK or a specific microservice framework), we can create a dedicated skill module.
3.1 Example of Building a Skill Module
Suppose a team needs to follow a complex logging standard. You can create a skill named logging-standards:
- Skill directory:
skills/logging-standards/ - Skill content: The output format for structured logs, the scenarios for using each log level (such as ERROR, WARN, INFO), and how to call the integrated logging service API.
When the AI needs to write business code that involves logging, it automatically refers to this skill, ensuring the log output format is compatible with the team’s existing log collection system and avoiding later troubleshooting difficulties caused by inconsistent formats.
3.2 Engineering Practices with Cloud Services
In real enterprise-level development, coding standards are often closely tied to infrastructure. For example, when building cloud-native applications, a skill file can define the following practices:
- Object storage interaction: Specify that file upload logic must include multipart upload, resumable upload, and retry-on-failure mechanisms, packaged as a common utility function.
- Message queue usage: Define that producers must handle compensation for failed message delivery (such as a dead letter queue), and consumers must implement idempotency checks.
- Containerized deployment: Specify Dockerfile conventions, such as requiring multi-stage builds to reduce image size and prohibiting the use of the
latesttag.
By distilling these “common industry technical solutions” into skills, the code the AI generates when assisting with cloud application development will naturally have high availability and scalability.
4. Closing the Workflow Loop: From Writing to Review
A complete development workflow is not just “writing code”; it also includes code review and continuous integration.
- Rule-driven development: The developer describes the requirement, and the AI automatically generates a first version of the code based on the standards in
CLAUDE.mdand underrules/. At this point, the AI plays the role of a “junior programmer,” producing a code skeleton that conforms to basic standards. - AI-assisted review: Using the same skill files, have the AI act as a “senior reviewer.” You can feed the written code to the AI with an instruction such as: “Review the following code against
coding-style.mdandsecurity-rules, and point out anything that does not conform to the standards.” - Automatic documentation generation: If the standards require a commenting convention (such as JSDoc or Python Docstring), the AI can batch-complete the documentation, ensuring project docs stay in sync with the code.
5. Summary
By systematically configuring Rules and Skills, developers are essentially building a “digital coding standards manual” for the AI. This not only turns the team’s best practices into executable configuration but also enables the scalable replication of code quality.
For teams, this means:
- Lower communication costs: No need to repeatedly explain to the AI whether to use camelCase or snake_case.
- A unified technology stack: Ensures all members (including the AI) produce code with a highly consistent style.
- A higher security baseline: Moves security coding requirements earlier, reducing the cost of fixing vulnerabilities later.
Start organizing your .claude/rules directory and skills library now, turn your team’s knowledge into AI productivity, and begin a new chapter of efficient, standardized intelligent development.
