Claude
Skills
Sign in
Back

claude-code-best-practice

Included with Lifetime
$97 forever

```markdown

Writing & Docs

What this skill does

```markdown
---
name: claude-code-best-practice
description: Master Claude Code features, patterns, and agentic workflows using community best practices
triggers:
  - "how do I use Claude Code effectively"
  - "what are Claude Code best practices"
  - "set up subagents in Claude Code"
  - "create a slash command for Claude"
  - "configure CLAUDE.md memory"
  - "orchestrate agents with Claude Code"
  - "use skills in Claude Code"
  - "vibe coding with Claude"
---

# Claude Code Best Practice

> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.

Community-curated best practices and patterns for [Claude Code](https://code.claude.com) — Anthropic's agentic coding tool. Covers subagents, commands, skills, memory, hooks, MCP servers, orchestration workflows, and advanced features like Auto Mode, Agent Teams, and Scheduled Tasks.

---

## What Claude Code Is

Claude Code is an AI coding agent that runs in your terminal (and web/IDE). It can read, write, and execute code; browse the web; call tools; and spawn subagents. Configuration lives in `.claude/` inside your project.

```
.claude/
├── settings.json       # permissions, model, output style
├── agents/             # subagent definitions
├── commands/           # slash command templates
├── skills/             # skill bundles (SKILL.md)
├── hooks/              # event-driven scripts
└── rules/              # scoped memory rules
CLAUDE.md               # root memory file (always loaded)
.mcp.json               # MCP server connections
```

---

## Installation & Setup

```bash
# Install Claude Code CLI
npm install -g @anthropic/claude-code

# Authenticate
claude auth login

# Launch interactive session
claude

# Launch with auto-permissions (no prompts)
claude --permission-mode auto

# Launch headless (pipe a prompt)
claude -p "Refactor src/utils.ts to use async/await"
```

---

## Core Concepts

### Memory — `CLAUDE.md`

The root memory file is always injected into context. Use it to define project conventions, tech stack, and rules.

```markdown
# CLAUDE.md

## Project
TypeScript monorepo. Node 20. pnpm workspaces.

## Rules
- Never commit directly to `main`
- All new files need a unit test
- Use `zod` for runtime validation

## @imports
@.claude/rules/typescript.md
@.claude/rules/testing.md
```

Import scoped rule files with `@path`:

```bash
# .claude/rules/typescript.md
- Prefer `type` over `interface` for unions
- Enable `strict: true` in tsconfig
```

Auto memory writes: Claude can append learnings to `CLAUDE.md` automatically when you ask it to "remember this".

---

### Subagents — `.claude/agents/<name>.md`

Subagents run in a **fresh isolated context** with their own tools, permissions, model, and identity.

```markdown
<!-- .claude/agents/code-reviewer.md -->
---
name: code-reviewer
description: Reviews PRs for bugs, style issues, and security vulnerabilities
model: claude-opus-4-5
tools:
  - read_file
  - search_code
permissions:
  - read
---

You are a senior code reviewer. When invoked:
1. Read the diff provided
2. Check for security issues (injections, secrets, unvalidated input)
3. Flag style violations against CLAUDE.md rules
4. Suggest improvements with code examples
5. Return a structured review with LGTM / REQUEST_CHANGES verdict
```

Invoke a subagent from a command or prompt:

```
/review-pr diff: <paste diff here>
```

Or spawn programmatically in headless mode:

```bash
claude -p "Use the code-reviewer agent to review the changes in the last commit" \
  --agent code-reviewer
```

---

### Commands — `.claude/commands/<name>.md`

Commands inject a **prompt template** into the current context. They're simple, fast, and user-invoked with `/`.

```markdown
<!-- .claude/commands/fix-types.md -->
---
description: Fix all TypeScript type errors in the current file
---

Look at the currently open file. Run `tsc --noEmit` scoped to this file.
For each type error:
1. Explain what's wrong in one sentence
2. Apply the minimal fix
3. Re-run tsc to confirm it's resolved

Do not change logic — only fix types.
```

Usage in Claude Code:

```
/fix-types
```

---

### Skills — `.claude/skills/<name>/SKILL.md`

Skills are **discoverable knowledge bundles** with frontmatter triggers. Claude auto-loads them when a trigger phrase is detected.

```
.claude/skills/
└── openapi-codegen/
    └── SKILL.md
```

```markdown
<!-- .claude/skills/openapi-codegen/SKILL.md -->
---
name: openapi-codegen
description: Generate TypeScript clients from OpenAPI specs
triggers:
  - "generate API client"
  - "create types from OpenAPI"
  - "scaffold from swagger"
---

# OpenAPI Codegen Skill

Use `openapi-typescript` to generate types:

```bash
npx openapi-typescript ./openapi.yaml -o src/types/api.d.ts
```

Then use `openapi-fetch` for type-safe calls:

```typescript
import createClient from "openapi-fetch";
import type { paths } from "./types/api.d.ts";

const client = createClient<paths>({ baseUrl: process.env.API_BASE_URL });

const { data, error } = await client.GET("/users/{id}", {
  params: { path: { id: "123" } },
});
```
```

---

### Settings — `.claude/settings.json`

```json
{
  "model": "claude-opus-4-5",
  "permissionMode": "auto",
  "outputStyle": "minimal",
  "fastMode": true,
  "statusLine": {
    "show": true,
    "items": ["context", "model", "cost", "session"]
  },
  "permissions": {
    "allow": ["read", "write", "execute"],
    "deny": ["network:external"]
  },
  "keybindings": {
    "voice": "ctrl+shift+v"
  }
}
```

Global settings live in `~/.claude/settings.json`. Project settings override globals.

---

### MCP Servers — `.mcp.json`

Connect external tools, databases, and APIs via the Model Context Protocol.

```json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "${DATABASE_URL}"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/workspace"]
    }
  }
}
```

---

### Hooks — `.claude/hooks/`

Hooks are scripts that fire on Claude Code events **outside the agentic loop**.

```json
// .claude/settings.json
{
  "hooks": {
    "postToolUse": ".claude/hooks/post-tool.sh",
    "onSessionEnd": ".claude/hooks/summarize.sh",
    "preFileWrite": ".claude/hooks/lint-check.sh"
  }
}
```

```bash
#!/bin/bash
# .claude/hooks/lint-check.sh
# Runs before Claude writes a file — blocks if lint fails

FILE=$CLAUDE_HOOK_FILE
npx eslint "$FILE" --max-warnings 0
exit $?
```

---

## Orchestration Workflow Pattern

The recommended pattern: **Command → Agent → Skill**

```
User types /weather-orchestrator city=London
        │
        ▼
┌─────────────────┐
│    Command      │  Parses args, sets up context
│ weather-        │  Invokes subagent with task
│ orchestrator.md │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│    Subagent     │  Isolated context, specialized model
│ weather-        │  Uses skills for domain knowledge
│ fetcher.md      │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│     Skill       │  Auto-loaded by trigger phrase
│ weather-api/    │  Provides API patterns + examples
│ SKILL.md        │
└─────────────────┘
```

```markdown
<!-- .claude/commands/weather-orchestrator.md -->
---
description: Fetch and display weather for a city
args:
  city: string
---

Fetch weather for {{city}}.
Use the weather-fetcher subagent.
Format the result as a concise summary with temperature, conditions, and 3-day forecast.
```

---

## Advanced Features

### Agent Teams (parallel agents)

```bash
# Enable via env var
export CLAUDE_AGENT_TEAMS=true
claude
```

```
/team-task
  agent-1: Refactor the auth module
  agent-2: Write tests for the auth module
  agent-3: Update the auth documentation
```

Agents share 

Related in Writing & Docs