3.1

Configure CLAUDE.md files with appropriate hierarchy, scoping, and modular organization

A new teammate clones the repo but never receives your coding conventions — because the instructions live in your personal ~/.claude/CLAUDE.md, which is not shared with teammates via version control. CLAUDE.md loads as a hierarchy: user-level (~/.claude/CLAUDE.md, personal), project-level (.claude/CLAUDE.md or root CLAUDE.md, committed and shared), and directory-level (a CLAUDE.md inside a subdirectory). To diagnose that teammate gap, move the shared rules from user-level into project-level configuration.

Keep the file modular instead of monolithic: use the @import syntax (@.claude/rules/testing.md) so each package's CLAUDE.md pulls in only the standards relevant to its maintainer, or split a large CLAUDE.md into topic files under .claude/rules/testing.md, api-conventions.md, deployment.md. When behavior is inconsistent across sessions, run /memory to verify exactly which memory files are loaded.

  • Hierarchy: ~/.claude/CLAUDE.md (user, personal) → .claude/CLAUDE.md or root CLAUDE.md (project, shared) → subdirectory CLAUDE.md (directory scope)
  • User-level settings apply only to that user — ~/.claude/CLAUDE.md is not shared via version control, so team-wide instructions must live at project level
  • @import references external files (@.claude/rules/testing.md) so each package includes only the standards relevant to its domain
  • Split a large CLAUDE.md into focused .claude/rules/ topic files: testing.md, api-conventions.md, deployment.md
  • /memory shows which memory files are currently loaded — use it to diagnose inconsistent behavior across sessions
Domain 3 Task 3.1 — CLAUDE.md configuration hierarchy diagram
  • Placing team-shared instructions in user-level ~/.claude/CLAUDE.md and expecting teammates to receive them — it is never shared via version control
  • Diagnosing inconsistent cross-session behavior without running /memory to confirm which files actually loaded
  • Keeping one monolithic CLAUDE.md when @import or .claude/rules/ topic files would keep context focused
  • Assuming a directory-level CLAUDE.md propagates upward to the whole project — it only scopes its own subtree
# CLAUDE.md — project root (committed, shared with the whole team)

## Project standards (kept modular via @import)
@.claude/rules/testing.md
@.claude/rules/api-conventions.md
@.claude/rules/deployment.md
Claude Docs (official): How Claude remembers your project · CLAUDE.md hierarchy, @import, and /memory
Anthropic Academy on Skilljar (optional): Claude Code in Action — Modules 2 + 3 · Project setup · Adding context (M2) · Controlling context (M3)
3.2

Create and configure custom slash commands and skills

You want a /review command that every developer gets when they clone or pull the repo — so create it in the project-scoped .claude/commands/ directory (shared via version control), not ~/.claude/commands/, which is personal. Skills are different: they live in .claude/skills/ as SKILL.md files whose frontmatter configures behavior — context: fork runs the skill in an isolated sub-agent context so its verbose output never pollutes the main conversation, allowed-tools restricts which tools it may call, and argument-hint prompts the developer for required parameters when they invoke it bare.

The choice between a skill and CLAUDE.md is about loading: a skill is invoked on-demand for a task-specific workflow, while CLAUDE.md is always loaded as universal standards. To customize a team skill without affecting teammates, create a personal variant in ~/.claude/skills/ under a different name.

  • Project commands go in .claude/commands/ (shared via version control); personal commands in ~/.claude/commands/
  • Skills are .claude/skills/ + SKILL.md; frontmatter supports context: fork, allowed-tools, and argument-hint
  • context: fork isolates verbose (codebase analysis) or exploratory (brainstorming alternatives) output in a sub-agent, keeping the main session clean
  • allowed-tools restricts tool access during skill execution (e.g. limit to file writes to prevent destructive actions); argument-hint prompts for missing parameters
  • Skills = on-demand task-specific workflows; CLAUDE.md = always-loaded universal standards; personal skill variants go in ~/.claude/skills/ under a different name
Domain 3 Task 3.2 — slash commands vs skills vs CLAUDE.md comparison diagram
  • Putting a team-shared command in ~/.claude/commands/ — that location is personal and not shared via version control
  • Treating CLAUDE.md as a command container — it holds project instructions and context, not command definitions
  • Defining commands in a .claude/config.json with a commands array — no such mechanism exists in Claude Code
  • Letting a verbose skill pollute the main conversation instead of isolating it with context: fork
---
name: review-checklist
description: Run the team's standard code-review checklist
context: fork          # isolate verbose output in a sub-agent
allowed-tools: Read, Grep, Glob   # restrict tool access during execution
argument-hint: <pr-number>        # prompt when invoked without arguments
---
Claude Docs (official): Extend Claude with skills · SKILL.md frontmatter (allowed-tools, invocation control) and custom commands
Anthropic Academy on Skilljar (optional): Claude Code — Module 3 + Introduction to Agent Skills · Custom commands (CC) · What are skills? · Creating your first skill · Configuration and multi-file skills (IAS)
Peace Of Code (YouTube, optional): Ep 11 — Custom Slash Commands & Skills
3.3

Apply path-specific rules for conditional convention loading

Your test files sit next to the code they test (Button.test.tsx beside Button.tsx), scattered across every directory, and you want all of them to follow the same conventions automatically. A .claude/rules/ file with YAML frontmatter paths globs does exactly this: paths: ["**/*.test.tsx"] makes the rule load only when Claude edits a matching file, applying conventions by file type regardless of location — and irrelevant rules stay out of context, reducing token usage.

This beats a subdirectory CLAUDE.md, which is directory-bound and can't follow files spread throughout the codebase. Choose glob-pattern path rules whenever a convention must apply to files of a type wherever they live (e.g. paths: ["terraform/**/*"] for all Terraform); reserve directory-level CLAUDE.md for conventions that really are confined to one directory.

  • .claude/rules/ files use YAML frontmatter paths: globs for conditional activation (paths: ["terraform/**/*"])
  • Path-scoped rules load only when editing matching files — irrelevant context stays out, cutting token usage
  • Glob patterns apply conventions by file type regardless of directory (**/*.test.tsx for every test file)
  • Choose path-specific rules over a subdirectory CLAUDE.md when conventions span multiple directories
  • A subdirectory CLAUDE.md is directory-bound; it cannot cover files scattered across the codebase
Domain 3 Task 3.3 — path-scoped rules vs subdirectory CLAUDE.md diagram
  • Consolidating conventions in the root CLAUDE.md "under headers for each area" — relies on Claude inferring which section applies, not explicit matching
  • Creating "skills for each code type" as automatic convention loaders — skills require manual invocation, not automatic path matching
  • Placing a separate CLAUDE.md in each subdirectory for cross-directory conventions — directory-bound, can't handle files spread across many directories
---
description: Conventions for all test files, wherever they live
paths: ["**/*.test.tsx"]   # loads only when editing a matching file
---
- Use Testing Library queries; avoid container.querySelector
- One behavioral assertion per test where practical
Claude Docs (official): Path-specific rules · .claude/rules/ with paths glob frontmatter for conditional loading
Anthropic Academy on Skilljar (optional): Claude Code in Action — Modules 2 + 3 + Introduction to Agent Skills — Module 4 · Adding context · Controlling context (CC) · Skills vs. other Claude Code features (IAS)
3.4

Determine when to use plan mode vs direct execution

You're asked to restructure a monolith into microservices — dozens of files, decisions about service boundaries and module dependencies. Start in plan mode: it lets Claude explore the codebase and design an approach before committing to any change, which prevents the costly rework that comes from discovering dependencies late. Plan mode is for complex tasks — large-scale changes, multiple valid approaches, architectural decisions, multi-file modifications.

Reserve direct execution for simple, well-scoped changes: a single-file bug fix with a clear stack trace, adding one date-validation conditional. During verbose discovery phases, hand the work to the Explore subagent so its output is isolated and only a summary returns — keeping the main conversation's context window from filling up. The combined pattern is the expert move: plan the migration in plan mode, then switch to direct execution to implement it.

  • Plan mode: large-scale changes, multiple valid approaches, architectural decisions, multi-file modifications (e.g. a library migration affecting 45+ files)
  • Direct execution: simple, well-scoped changes — a single validation check, a one-file bug fix with a clear stack trace
  • Plan mode enables safe exploration and design before committing to changes, preventing costly rework
  • The Explore subagent isolates verbose discovery output and returns summaries, preserving the main context window
  • Combine both: plan mode for investigation, then direct execution for the planned implementation
Domain 3 Task 3.4 — plan mode vs direct execution decision flowchart
  • "Start with direct execution and make changes incrementally" for an architectural task — risks costly rework when dependencies surface late
  • "Switch to plan mode only if you encounter unexpected complexity" — the complexity is already stated in the requirements, not something that might emerge
  • Direct execution "with comprehensive upfront instructions" — assumes you already know the right structure without exploring the code
  • Entering plan mode for a trivial, well-scoped single-file change — unnecessary overhead
Claude Docs (official): Plan mode · analyze & propose before editing; when to plan vs execute directly
Anthropic Academy on Skilljar (optional): Claude Code in Action — Module 2 (Getting Hands On) · Making changes · Adding context
Peace Of Code (YouTube, optional): Ep 12 — Plan Mode vs Execute
3.5

Apply iterative refinement techniques for progressive improvement

When a prose description gets interpreted inconsistently, the most effective fix is to show 2–3 concrete input/output examples of the transformation you want — examples communicate intent that adjectives can't. Pair that with test-driven iteration: write a test suite covering expected behavior, edge cases, and performance first, then iterate by sharing the failing tests so Claude converges on correct behavior. To fix a specific edge case (null values in a migration script), give a test case with the exact example input and expected output.

In an unfamiliar domain, use the interview pattern — have Claude ask you questions up front to surface considerations you might not have anticipated (cache-invalidation strategy, failure modes) before it implements. Finally, batch your fixes by dependency: put multiple interacting issues in one detailed message so the fixes account for each other; handle independent issues sequentially.

  • Provide 2–3 concrete input/output examples when natural-language descriptions produce inconsistent results
  • Test-driven iteration: write tests for behavior, edge cases, and performance first, then iterate by sharing failures
  • Interview pattern: have Claude ask questions to surface design considerations (cache invalidation, failure modes) in unfamiliar domains
  • Give a specific test case with example input and expected output to fix edge-case handling (e.g. null values in migration scripts)
  • Interacting issues → one detailed message (fixes interact); independent issues → fix sequentially
Domain 3 Task 3.5 — iterative refinement techniques process diagram
  • Adding more prose description when it's interpreted inconsistently, instead of giving concrete input/output examples
  • Fixing independent issues all in one message, or interacting issues one at a time — mismatching batching to dependency
  • Implementing in an unfamiliar domain without the interview pattern to surface hidden considerations first
  • Iterating without a test suite, so there is no concrete failure signal to guide progressive improvement
Claude Docs (official): Best practices for Claude Code · verify with concrete examples & tests; the interview pattern
Anthropic Academy on Skilljar (optional): Claude Code in Action — Module 2 + Building a Claude App — Module 4 · Making changes (CC) · Being clear and direct · Being specific · Providing examples (BCA)
3.6

Integrate Claude Code into CI/CD pipelines

Your pipeline runs claude "Analyze this pull request" and the job hangs forever — Claude Code is waiting for interactive input. The fix is the -p (--print) flag, which runs it non-interactively so automated jobs don't hang. To make the output machine-parseable for posting as inline PR comments, pair --output-format json with --json-schema so findings come back in a fixed, enforced structure.

Feed project context through CLAUDE.md — testing standards, fixture conventions, review criteria — so CI-invoked Claude Code generates higher-value output. When re-running a review after new commits, include the prior findings in context and instruct Claude to report only new or still-unaddressed issues so it doesn't post duplicate comments; likewise, provide existing test files so generated tests don't duplicate scenarios already covered. One subtlety of session context isolation: the same session that generated the code is less effective at reviewing its own changes — use an independent review instance.

  • -p (--print) runs Claude Code non-interactively so CI jobs don't hang waiting for input
  • --output-format json with --json-schema produces machine-parseable structured findings for automated inline PR comments
  • Provide project context via CLAUDE.md (testing standards, fixtures, review criteria) to CI-invoked Claude Code
  • Re-running after new commits: include prior findings and instruct Claude to report only new/unaddressed issues to avoid duplicate comments; supply existing test files to avoid duplicate test scenarios
  • An independent review instance reviews more effectively than the session that generated the code (session context isolation)
Domain 3 Task 3.6 — Claude Code in a CI/CD pipeline sequence diagram
  • Setting CLAUDE_HEADLESS=true to run in CI — that environment variable does not exist
  • Adding a --batch flag for non-interactive mode — no such flag exists
  • Redirecting stdin from /dev/null as the CI fix — a Unix workaround that doesn't address Claude Code's command syntax
  • Reusing the same session that generated the code to review it — less effective than an independent review instance
# CI pipeline step — non-interactive run, machine-parseable findings
claude -p "Review this diff for security issues" \
  --output-format json \
  --json-schema ./review-schema.json
Claude Docs (official): Claude Code GitHub Actions · run Claude Code in CI to review PRs, with CLAUDE.md context
Anthropic Academy on Skilljar (optional): Claude Code in Action — Modules 3 + 4 · GitHub integration (M3) · The Claude Code SDK (M4)
Peace Of Code (YouTube, optional): Ep 13 — Claude Code CI/CD Pipelines

Further Reading — Claude Docs

Official Anthropic documentation for the concepts in this domain.

CLAUDE.md hierarchy & path-specific rules How Claude remembers your project
Custom commands & skills Extend Claude with skills
Plan mode vs direct execution Choose a permission mode — Plan mode
Iterative refinement Best practices for Claude Code
CI/CD integration Claude Code GitHub Actions

Further Reading — Anthropic Academy on Skilljar

Optional self-paced courses.

Anthropic Academy on Skilljar

Further Viewing — Peace Of Code (YouTube)

Watch if a topic is still unclear.

CCA Full Course — Peace Of Code

Custom slash commands & skills Ep 11 — Custom Slash Commands & Skills
Plan mode vs direct execution Ep 12 — Plan Mode vs Execute
CI/CD pipeline integration Ep 13 — Claude Code CI/CD Pipelines