Agent skill

AI Coding Discipline

by luoling8192 in luoling8192/ai-coding-principles

Mandatory coding discipline rules that prevent common AI coding anti-patterns.

MITAuto-check passedDevelopment

Install AI Coding Discipline

skills CLI
$ npx skills add luoling8192/ai-coding-principles --skill ai-coding-discipline -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install luoling8192/ai-coding-principles ai-coding-discipline --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/luoling8192/ai-coding-principles.git skills-src && mkdir -p .claude/skills && cp -r skills-src/ai-coding-discipline .claude/skills/ai-coding-discipline && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
ai-coding-discipline
GitHub stars
173
Token cost
~1.9k tokens
SKILL.md length
552 words
Files
1
Skills in repo
2
Repo updated
First seen
Licence
MIT

At a glance

Mandatory coding discipline rules that prevent common AI coding anti-patterns.

  • Works in 3 steps: Can this value legitimately be… → If it is null, will the fallback produce… → Would a thrown error help me find a bug…
  • Implementing features
  • SKILL.md covers Rule 1: No Silent Fallbacks, Rule 2: No Catch-All try/catch…, Rule 3: Tests Must Fail When… and Rule 4: No Hardcoded…, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

AI Coding Discipline is an agent skill from luoling8192/ai-coding-principles. Mandatory coding discipline rules that prevent common AI coding anti-patterns. MUST be loaded for ALL code writing, editing, reviewing, bug fixing, and testing tasks. Trigger on: writing code, editing code, fixing bugs, writing tests, implementing features, refactoring, code review, creating functions, adding error handling, debugging. This skill enforces fail-fast principles, proper error propagation, meaningful tests, and disciplined debugging workflows. Always active when Claude writes or modifies code.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Debugging and Refactoring. The repository describes itself as: A collection of Claude Code skills that enforce coding discipline and prevent common AI coding anti-patterns. The licence is MIT.

When your agent uses it

  • Implementing features
  • Creating functions
  • Adding error handling

Example prompts

  • “/ai-coding-discipline”

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Can this value legitimately be null/undefined at this point?
  2. If it is null, will the fallback produce a correct result downstream?
  3. Would a thrown error help me find a bug faster?

What it can do on your machine

Read from SKILL.md and the folder at commit 27db986. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

AI Coding Discipline loads about 1.9k tokens when it runs. Until then it costs about 133 tokens; SKILL.md has 552 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~133
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from luoling8192/ai-coding-principles at commit 27db986, republished under its MIT licence (© luoling8192). 552 words, ~1,856 tokens.

Download SKILL.mdSave it as .claude/skills/ai-coding-discipline/SKILL.md (or your agent's skills folder).
name
ai-coding-discipline
description
Mandatory coding discipline rules that prevent common AI coding anti-patterns. MUST be loaded for ALL code writing, editing, reviewing, bug fixing, and testing tasks. Trigger on: writing code, editing code, fixing bugs, writing tests, implementing features, refactoring, code review, creating functions, adding error handling, debugging. This skill enforces fail-fast principles, proper error propagation, meaningful tests, and disciplined debugging workflows. Always active when Claude writes or modifies code.

AI Coding Discipline

These rules override default AI coding tendencies. Follow them in ALL code you write or modify.


Rule 1: No Silent Fallbacks

Never use fallback values to mask data that should not be missing.

typescript
// FORBIDDEN — hides upstream bugs
const price = product?.price ?? 0;
const userName = user?.name || "Unknown";

// CORRECT — fail fast when data contract is violated
if (product.price == null) {
  throw new Error(`Product ${product.id} is missing price`);
}
const price = product.price;

When fallbacks ARE acceptable:

  • User-facing display with explicit design intent (e.g., avatar placeholder)
  • Optional configuration with documented defaults
  • External input parsing where absence is a valid state

Checklist before writing ??, ||, or ?.:

  1. Can this value legitimately be null/undefined at this point?
  2. If it is null, will the fallback produce a correct result downstream?
  3. Would a thrown error help me find a bug faster?

If the answer to #3 is yes, throw instead of falling back.


Rule 2: No Catch-All try/catch in Business Logic

Business logic functions must NOT wrap everything in try/catch. Let errors propagate naturally.

typescript
// FORBIDDEN — swallows all errors into a useless null
async function createOrder(data: OrderInput) {
  try {
    const user = await getUser(data.userId);
    const coupon = await validateCoupon(data.couponCode);
    const order = await saveOrder({ ...data, discount: coupon.value });
    return order;
  } catch (error) {
    console.log('Error creating order:', error);
    return null; // caller gets null, has no idea what failed
  }
}

// CORRECT — let errors bubble up, catch at the boundary
async function createOrder(data: OrderInput) {
  const user = await getUser(data.userId);
  const coupon = await validateCoupon(data.couponCode);
  const order = await saveOrder({ ...data, discount: coupon.value });
  return order;
}

// Catch ONLY at the API/controller boundary
app.post('/orders', async (req, res) => {
  try {
    const order = await createOrder(req.body);
    res.json(order);
  } catch (error) {
    logger.error('Order creation failed', { error, body: req.body });
    res.status(500).json({ error: 'Order creation failed' });
  }
});

Where try/catch IS appropriate:

  • API route handlers / controller boundaries
  • Top-level event handlers (message queues, cron jobs)
  • Operations where partial failure is expected and recovery is defined (e.g., batch processing with per-item error handling)
  • Specific, named error types you intend to handle differently

Never catch Error just to return null, undefined, false, or an empty object.


Rule 3: Tests Must Fail When Code Breaks

Every test must verify specific business outcomes. A test that passes when the core logic is deleted is worthless.

typescript
// FORBIDDEN — passes even if processOrder returns garbage
test('should process order', async () => {
  const result = await processOrder(mockOrder);
  expect(result).toBeDefined();
});

// CORRECT — verifies exact business behavior
test('should calculate total with 10% discount', async () => {
  const result = await processOrder({
    ...mockOrder,
    discount: 0.1,
  });
  expect(result.totalAmount).toBe(900);       // 1000 * 0.9
  expect(result.discountAmount).toBe(100);
  expect(result.status).toBe('confirmed');
});

Test quality checklist:

  1. If I delete the function body, does this test fail? If not, the test is useless.
  2. Am I testing behavior or just testing that "something exists"?
  3. Do my assertions check concrete values, not just truthiness?

Banned weak assertions (unless testing existence is the actual requirement):

  • toBeDefined(), toBeTruthy(), toBeFalsy() as sole assertion
  • toHaveLength(expect.any(Number))
  • expect(result).not.toBeNull() without further value checks

Rule 4: No Hardcoded Lookup-Table Implementations

Never implement business logic by hardcoding return values that match test cases.

typescript
// FORBIDDEN — fake implementation that "fits" the tests
function calculateDiscount(amount: number, level: string): number {
  if (amount === 1000 && level === 'gold') return 100;
  if (amount === 500 && level === 'silver') return 25;
  return 0;
}

// CORRECT — real logic
function calculateDiscount(amount: number, level: string): number {
  const rates: Record<string, number> = { gold: 0.1, silver: 0.05, bronze: 0.02 };
  const rate = rates[level] ?? 0;
  return amount * rate;
}

How to prevent this:

  • Use diverse test data: multiple amounts, edge cases, boundary values
  • Add property-based / fuzzy tests where appropriate
  • Test with values NOT in the original spec to catch lookup-table fakes

Show full SKILL.md (223 more words)Show less

Rule 5: Red-Green Testing (TDD Order)

When fixing a bug, always write the failing test FIRST, then fix the code.

Correct order:
1. Discover bug
2. Write a test that reproduces the bug
3. Run the test — confirm it FAILS (red)
4. Fix the code
5. Run the test — confirm it PASSES (green)

Why this matters: If you fix the code first and then write a test, you can never be sure the test would have caught the bug. The test might pass for the wrong reason.

Never skip step 3. Seeing the test go from red to green is the proof that the test is valid.


Rule 6: Never Remove Debug Logs During a Fix

When debugging, debug logs are removed ONLY after the human confirms the fix works.

FORBIDDEN workflow:
1. Human asks to add debug logs
2. AI adds logs
3. Human runs code, shares log output
4. AI "finds the problem", applies fix AND removes debug logs in the same edit
5. Fix doesn't work — logs are gone, must re-add them

CORRECT workflow:
1. Human asks to add debug logs
2. AI adds logs
3. Human runs code, shares log output
4. AI applies fix ONLY — debug logs stay untouched
5. Human verifies the fix
6. Human decides when to remove debug logs (or asks AI to remove them)

Rule: Never touch debug/diagnostic logs in the same commit as a fix. They are separate concerns.


Quick Reference: Self-Check Before Submitting Code

Before finalizing any code change, run through this checklist:

CheckQuestion
FallbacksDid I use ?? or || to hide a value that should never be missing?
Error handlingDid I add try/catch in business logic that should just let errors propagate?
Test strengthWould my tests still pass if I deleted the implementation?
Test honestyDid I hardcode values to match test cases instead of implementing real logic?
TDD orderFor bug fixes: did I see the test fail before applying the fix?
Debug logsAm I removing diagnostic logs in the same change as the fix?

If any answer is "yes", revise before proceeding.

© luoling8192, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in ai-coding-discipline of luoling8192/ai-coding-principles.

Open the folder on GitHubat commit 27db986

Compare with similar skills

AI Coding Discipline next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

AI Coding Discipline compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
AI Coding Discipline this skillluoling8192/ai-coding-principles173—~1.9kAutomated safety check: PassMIT
Code Review Graph Navigatorhandsontable/handsontable22k—~939Automated safety check: PassCustom licence
Andrej Karpathy Skillduolahypercho/andrej-karpathy-skills248—~793Automated safety check: PassMIT
Verdaccio Change Implementationverdaccio/verdaccio18k—~1.3kAutomated safety check: PassMIT
RoamCranot/roam-code517—~2.4kAutomated safety check: PassApache-2.0
Odoo Workflowunclecatvn/agent-skills143—~4.7kAutomated safety check: PassMIT

Similar skills

  • Code Review Graph Navigator

    handsontable/handsontable

    Queries a pre-built, Tree-sitter-based code graph of the whole monorepo instead of grepping call chains, for exploring, debugging, refactoring or reviewing code.

    22k GitHub stars~939 tokensUpdated today
    DevelopmentAuto-check passed
  • Andrej Karpathy Skill

    duolahypercho/andrej-karpathy-skills

    Apply Andrej Karpathy-inspired coding-agent guidelines in Codex.

    248 GitHub stars~793 tokensUpdated 4 mo ago
    DevelopmentAuto-check passed
  • A workflow for implementing a Verdaccio bug fix, feature or refactor: pick the release lines, check existing options, edit the owning layer, test and add a changeset.

    18k GitHub stars~1.3k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Roam

    Cranot/roam-code

    Codebase comprehension via roam-code CLI. An agent skill from Cranot/roam-code.

    517 GitHub stars~2.4k tokensUpdated 4 days ago
    DevelopmentAuto-check passed
  • Odoo Workflow

    unclecatvn/agent-skills

    Mandatory pre-code gate and definition-of-done for ANY Odoo change (add field, override method, inherit view/xpath, OWL/JS patch, wizard, cron, controller, report, security, migration, bug fix…

    143 GitHub stars~4.7k tokensUpdated 13 days ago
    DevelopmentAuto-check passed
  • Synapse Usage

    S1LV4/th0th

    Use the th0th Synapse cognitive modulation layer to get focused, low-noise retrieval during multi-step coding tasks.

    136 GitHub stars~2.9k tokensUpdated 3 mo ago
    DevelopmentAuto-check passed

More from luoling8192/ai-coding-principles

  • Ddia Principles

    luoling8192/ai-coding-principles

    Designing Data-Intensive Applications (DDIA) distilled reference guide by Martin Kleppmann.

    173 GitHub stars~4.7k tokensUpdated 6 mo ago
    Auto-check passed

Categories

Questions about AI Coding Discipline

What does AI Coding Discipline do?

Mandatory coding discipline rules that prevent common AI coding anti-patterns. AI Coding Discipline is an agent skill from luoling8192/ai-coding-principles. Mandatory coding discipline rules that prevent common AI coding anti-patterns.

When should I use AI Coding Discipline?

AI Coding Discipline fits situations like: implementing features; creating functions; adding error handling.

How do I install AI Coding Discipline in Claude Code?

Run `npx skills add luoling8192/ai-coding-principles --skill ai-coding-discipline -a claude-code`. Or copy the skill folder (ai-coding-discipline in luoling8192/ai-coding-principles) into .claude/skills/ai-coding-discipline in your project. Claude Code loads it when a task matches its description.

How do I install AI Coding Discipline in Codex?

Run `npx skills add luoling8192/ai-coding-principles --skill ai-coding-discipline -a codex`. Or copy the skill folder (ai-coding-discipline in luoling8192/ai-coding-principles) into .agents/skills/ai-coding-discipline in your project. Codex loads it when a task matches its description.

Can I use AI Coding Discipline in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add luoling8192/ai-coding-principles --skill ai-coding-discipline -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ai-coding-discipline, .gemini/skills/ai-coding-discipline, .github/skills/ai-coding-discipline and .opencode/skills/ai-coding-discipline in your project.

What does AI Coding Discipline need to run?

SKILL.md names no scripts, command-line tools or credentials: AI Coding Discipline is instructions for the agent only.

Does AI Coding Discipline access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is AI Coding Discipline safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does AI Coding Discipline use?

AI Coding Discipline is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does AI Coding Discipline use?

About 1.9k tokens (SKILL.md is roughly 7.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to AI Coding Discipline?

Skills that share tags, products or a category with AI Coding Discipline: Code Review Graph Navigator (handsontable/handsontable, 22k stars), Andrej Karpathy Skill (duolahypercho/andrej-karpathy-skills, 248 stars), Verdaccio Change Implementation (verdaccio/verdaccio, 18k stars) and Roam (Cranot/roam-code, 517 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains AI Coding Discipline?

luoling8192 (a GitHub user) maintains it in luoling8192/ai-coding-principles, which has 173 GitHub stars. The repository holds 2 skills in this directory. The repository was last updated on March 26, 2026.

Source: luoling8192/ai-coding-principles on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.