agentleFS
terrene-foundationterrene-foundation/pact/.claude/skills/30-claude-code-patterns/SKILL.md

claude-code-patterns

Skill0 starsChanged 7 months agoApache-2.0View on GitHub

Claude Code architecture patterns, artifact design, context management, and agentic system patterns. Use when creating, auditing, or improving CC artifacts.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never parse text for "I'm done" (natural language termination)

    line 33
  2. Distinctive:

    Never use arbitrary iteration caps (trust the model's signal)

    line 34
  3. Very specific:

    Only required fields that are always in the source — required = fabrication pressure

    line 89

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Claude Code Architecture Patterns

Reference patterns for designing effective Claude Code artifacts and understanding CC's internal architecture.

Quick Reference: Artifact Types

TypeLayerPurposeToken TargetQuality Test
AgentL1 IntentTeach judgment + procedure150-400 linesCompletes task without clarification
SkillL2 ContextTeach knowledge + reference150-250 lines (SKILL.md)Answers 80% of routine questions
RuleL3 GuardrailsEnforce boundaries50-150 linesZero violations in scope
CommandL4 InstructionsOrchestrate workflows50-150 linesPredictable, verifiable output
HookL3 GuardrailsDeterministic prevention20-80 lines (JS)100% enforcement, no exceptions

Agentic Architecture Patterns

The Agentic Loop

send → check stop_reason → execute tools → append → repeat
  • stop_reason == "end_turn" is the ONLY termination signal
  • Never parse text for "I'm done" (natural language termination)
  • Never use arbitrary iteration caps (trust the model's signal)
  • Claude returns text AND tool_use in the same response — check stop_reason, not content type

Multi-Agent Memory Isolation

Subagents do NOT share memory with coordinator or each other. All context must be passed explicitly via structured metadata (source URLs, doc names, page numbers).

Attention Dilution

14+ items in single pass → inconsistent depth. Fix: per-item analysis pass, then cross-item synthesis pass.

Session Management

StrategyWhenMechanism
ResumeSame task, no external changes--resume
ForkExplore alternative approachParallel worktrees
Fresh + SummaryStale context, switching focusNew session + /wrapup notes

Tool Design Patterns

Descriptions Are Selection Mechanism

Tool descriptions are for the MODEL, not humans. Include: what it does, inputs, example queries, boundaries vs similar tools.

4-5 Tool Limit Per Agent

18+ tools → <70% selection accuracy. Split into specialized subagents.

Error Categories

CategoryRetryableAction
TransientYesWait and retry
ValidationAfter fixFix input, retry
BusinessNoAlternative workflow
PermissionNoEscalate

Distinguish access failure ("DB unreachable") from valid empty result ("no orders found").

Prompt Engineering Patterns

Explicit Criteria Beat Vague Instructions

"Be conservative" → fails intermittently. "Flag only when claimed behavior contradicts code" → reliable.

Few-Shot: 2-4 Examples with Reasoning

Include a "resist extraction" example (when NOT to act). Reasoning blocks teach generalization, not pattern matching.

Schema Design

  • "type": ["string", "null"] for optional fields (not "nullable": true)
  • "unclear" enum value for genuine ambiguity
  • "other" + detail field for extensible categories
  • Only required fields that are always in the source — required = fabrication pressure

Validation-Retry Boundaries

Works for: format errors, structural errors, misplaced values. Fails for: information not in source, fabrication, genuine ambiguity.

Context Management Patterns

Progressive Summarization Trap

Transactional data ($247.83, order #8891) gets compressed to "customer wants refund." Fix: persistent case facts block, never summarized.

Lost-in-the-Middle

Critical info at beginning/end of context. Middle gets less attention. Trim tool results to needed fields.

Hooks vs Prompts Decision

StakesEnforcement
Money, security, complianceHook (100% deterministic)
Style, formatting, preferencesPrompt (~95% probabilistic)

Token Efficiency Patterns

  1. Path-scope rules via YAML frontmatter globs (60-80% savings)
  2. Progressive disclosure in skills: SKILL.md summary vs full directory
  3. Agent descriptions under 120 chars (loaded on every selection)
  4. Commands are prompts (50-150 lines), not documentation
  5. Don't duplicate CLAUDE.md in rules — CLAUDE.md is always loaded
  6. Consolidate overlapping rules — one rule beats five saying similar things

Detailed Reference

  • Artifact Design Guide — Templates, frontmatter, structural patterns
  • Anti-Patterns Catalog — Common mistakes and fixes
  • Token Budget Guide — Measurement and optimization

When to Use This Skill

  • Creating a new agent, skill, rule, command, or hook
  • Auditing existing artifacts for quality
  • Optimizing token efficiency of the .claude/ directory
  • Understanding how CC components interact

Support

  • claude-code-architect — Primary expert for CC artifact work
  • co-reference skill — CO methodology (principles, layers)
  • co-reference skill — COC methodology (five-layer implementation)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.