Claude Code Patterns

Claude Code patterns I’ve actually used. Every entry has a date and context.

2026-04-03: Parallel Agent Orchestration for Bulk Operations

Problem: Need to rename 57 occurrences of "t16g" to "p16g" across 10 files — too many for manual editing, too scattered for a single sed pass

Context: P16g deployment, hostname was corrected mid-project. 18 partials, 12 phases, 40+ stale references.

The Fix:

Two parallel Claude Code agents with distinct responsibilities:

  1. Explore agent audited all 18 partials — found 5 critical, 1 high, 4 medium issues

  2. Findings presented to user with severity levels — user approved: "pronto now!!"

  3. Two background agents launched simultaneously:

    • Agent 1: mass t16g→p16g rename (57 changes, 10 files)

    • Agent 2: bug fixes — vault creds, zsh noclobber, hostname vars (4 fixes, 3 files)

  4. Both agents completed in ~50 seconds

  5. User committed from terminal

Rule: For bulk file operations, split into audit agent (produces manifest) + execution agent (applies changes). Parallel agents maximize throughput. This mirrors plan/apply in infrastructure-as-code — never apply without reviewing the plan first.

Worklog: WRKLOG-2026-04-03


2026-03: CLAUDE.md Layered Configuration

Problem: Different repos need different Claude Code behaviors (permissions, rules, agents)

Context: Managing 15+ domus-* repos, each with different documentation and tooling needs

The Pattern:

~/.claude/CLAUDE.md           — Global: role, standards, security rules
~/.claude/settings.json       — Global: permissions, hooks, env vars
~/.claude/rules/              — Global: file-type rules (*.adoc, *.sh, *.lua)
~/.claude/agents/             — Global: reusable agents
project/.claude/CLAUDE.md     — Project: repo-specific context
project/.claude/agents/       — Project: project-specific agents

Rule: Layer from global to project. Global handles identity and standards. Project handles repo-specific context. Rules auto-load by file type — no manual activation needed.


2026-03: Hooks for Automated Quality Checks

Problem: Need automated validation on every file write (AsciiDoc linting, ShellCheck, security scanning)

Context: Claude Code settings.json hook configuration

The Pattern:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write",
        "command": "~/.claude/hooks/validate-write.sh"
      }
    ]
  }
}

Rule: Hooks run shell commands on Claude Code events. Use PostToolUse hooks for validation, PreToolUse for confirmation gates. The hook script receives the tool name and parameters — filter by file extension for targeted validation.