convention — extract code patterns

Caution

Every project drifts. New developers copy the wrong class, inconsistent naming spreads across modules, anti-patterns accumulate silently. Without explicit etalon classes — reference implementations that define “correct” — code reviews become opinion contests and onboarding takes weeks instead of days.

Tip

One run, three convention documents. The skill spawns up to 10 parallel agents, selects the best etalon per layer, generates .claude/convention/ docs, and optionally extracts rules into .claude/rules/. The outputs persist in your project — they don’t disappear when the session ends.

Quick reference

FieldValue
Command/brewcode:convention
Arguments[full|conventions|rules|paths <p1,p2>]
Modelopus
ToolsRead, Write, Edit, Glob, Grep, Bash, Task, AskUserQuestion, Skill

When to use

  • New team member onboarding — generate etalon docs once, share .claude/convention/ as the canonical style guide
  • Architecture drift prevention — run after a major refactor to re-anchor conventions to current code
  • Rules extraction/brewcode:convention rules turns existing convention docs into .claude/rules/*.md entries
  • Focused module analysis/brewcode:convention paths src/payments,src/billing scopes to changed modules only

Modes

ModeCommandPhasesPrerequisites
full (default)/brewcode:conventionP0–P8None
conventions/brewcode:convention conventionsP0–P6None
rules/brewcode:convention rulesP0, P7, P7.5, P8.claude/convention/ exists
paths/brewcode:convention paths src/a,src/bP0–P7 scopedNone

rules mode skips analysis entirely — it reads existing convention docs and runs the interactive rules extraction flow. Use it to refresh .claude/rules/ without re-scanning the whole project.

conventions mode stops at P6. P7 is Rules Organization, the phase that writes .claude/rules/, so “skip rules extraction” means the run must end one phase earlier — a skip gate at the P7 header enforces it. Only conventions mode leaves .claude/rules/ untouched; full and paths both reach P7.

Examples

# Full analysis — detect stack, analyze all layers, generate docs, extract rules
/brewcode:convention

# Natural language also works
"extract conventions from this project"
"find etalon classes and create convention docs"
# Skip rules extraction — just generate the three convention documents
/brewcode:convention conventions

# Focus on two modules only (large projects with >1000 files)
/brewcode:convention paths src/payments,src/billing
# Rules-only pass on existing convention docs
/brewcode:convention rules

Flow

  1. Stack + project scan (P0)

    Detects primary stack (Java/Kotlin, TypeScript, Python, Rust, Go, or multi-stack) and scans source directories. If total files exceed 1000, warns and recommends paths mode. Sets up .claude/convention/ output directory.

  2. Parallel layer analysis (P2 — 10 agents)

    All agents spawn in a single message. Each covers a specific layer group: build config, utilities, REST endpoints, DI/services, external clients, data access, DTOs/records, DDL/config, test data, and test patterns. Inactive layers for the detected stack are skipped automatically.

  3. Etalon selection (P3 — 1 Plan agent, or the project’s architecture agent)

    Receives all 10 layer reports, scores candidates on pattern coverage, naming adherence, and anti-pattern count. Selects 1–2 etalon classes per layer. Resolves conflicts when the same class appears as a candidate for multiple layers.

  4. Document generation (P4 — 3 parallel agents)

    Produces three documents: reference-patterns.md (~300 lines, main code layers), testing-conventions.md (~150 lines, test layers), project-architecture.md (~200 lines, build/DDL layers). Each document includes etalon class tables, code patterns, and anti-pattern tables.

  5. Text optimization + user review (P5–P6)

    If text-optimizer (brewtools) is installed, three optimizer agents compact the documents in parallel. Then a summary with key etalons is presented — approve, revise (up to 2 iterations), or skip to rules extraction.

  6. Rules extraction + CLAUDE.md update (P7–P7.5)

    Anti-patterns become avoid rules; naming conventions and patterns become best-practice rules. Duplicate detection skips entries already covered at >70% similarity. Interactive batching presents 5–7 rules at a time for accept/reject. Optionally adds an etalon reference table to project CLAUDE.md.

Delegation

Why 10 agents, not 1

A big task handed to one agent = an agent gone for an hour: you cannot observe it, cannot correct it, and it usually drifts off-target.

One subagent = ONE bounded unit — here, ONE layer analysis or ONE document: roughly 5 files, roughly 10 steps. Anything bigger is split into N tasks fired in ONE message. That sizing rule is exactly why P2 runs as 10 layer agents and P4 as 3 document agents rather than one agent owning the whole codebase.

The contract binds every Task spawn in the skill — P2, P3, P4, P5 and P7.4. Every spawn prompt carries six fields; a bare one-line task is never enough:

FieldContent
GOALthe overall task and why it exists — the point beyond the file edit
ROLEwhat this agent owns; what it must NOT touch
SCOPEexact paths/commands in bounds + explicit out-of-bounds
CONTEXTwhat is already done, by whom, what runs in parallel — trimmed to what THIS agent needs
CONSUMERwho or what uses the result next, and the shape it must fit
DONEacceptance criteria + the exact report shape you want back

A P2 layer agent is therefore told: the stack was already detected in P1 (do not re-detect), nine siblings own the other layers (do not report on theirs), and P3 parses its tables as-is — so it must return file paths and scored candidates in the exact column shape, not prose. The same brief is carried in references/rules-guide.md for the P7.4 bc-rules-organizer spawn.

Phase internals — agent prompts, layer table, error handling

Layer → agent mapping (P2)

#AgentLayersFocus
1ExploreL1–L3Build config, dependency management, code generation
2ExploreL4@UtilityClass, static helpers, shared converters
3ExploreL5+L14REST endpoints, security, config, caching
4ExploreL6+L9DI patterns, @Transactional, domain services
5ExploreL7Feign clients, external API integrations
6ExploreL8JOOQ DSL, raw SQL, mappers, query patterns
7ExploreL10+L11Records, @Value @Builder, naming conventions
8ExploreL12+L13DDL scripts, config files, templates
9ExploreT1–T4Test data, base classes, helpers, ExpectedData
10ExploreT5–T6BDD style, assertion patterns, @ParameterizedTest

Active layers by stack

StackActive layers
java, kotlinL1–L14, T1–T6 (all)
typescriptL1–L6, L8, L10–L11, L13–L14, T1–T3, T5–T6
pythonL1–L2, L4–L6, L8, L10, L13–L14, T1–T3, T5–T6
rustL1–L2, L4–L6, L8, L10–L11, T5
goL1–L2, L4–L6, L8, L10, T5
multi-stackUnion of all detected
unknownAll layers — agent determines relevance per layer

Error handling

ConditionAction
No source files foundExit: “No source files found for {STACK}“
rules mode without .claude/convention/Exit: “Run /brewcode:convention conventions first”
>1000 source filesWarn user, suggest paths mode
Unknown stackContinue with generic analysis
Agent timeoutLog warning, continue with available results
Convention doc generation failsRetry once, then present partial results

Output document paths

DocumentPathLines
Main code layers.claude/convention/reference-patterns.md~300
Test layers.claude/convention/testing-conventions.md~150
Build / DDL layers.claude/convention/project-architecture.md~200
📄

Rules skill

Turn analysis outputs into structured .claude/rules/*.md files.

🔗

GitHub source

Source code, scripts, layer definitions, and convention doc templates.

🚀

Brewcode overview

All brewcode skills — setup, spec, plan, start, review, and more.

Updating plugins

Use /brewtools:plugin-update to check and update the brewcode plugin suite in one command. See the FAQ for details.