Skip to content
AISeeker

Search

Search reports, topics, companies…

CH.05Tutorials
3 min read
Signal strength: 4/5Major
Verified · 6 Sources

Getting productive with Claude Code: CLAUDE.md, subagents, hooks and skills

A layered setup for Claude Code in a real repo: project memory, a reviewer subagent, deterministic hooks, on-demand skills and team plugins.

Key figures

<200
Target lines per CLAUDE.md
4 hops
Max @import depth

Run Claude Code with default settings and it will forget conventions and format files inconsistently. This tutorial builds a small, layered setup in an existing repository: persistent project instructions, a read-only review subagent, two hooks, one skill and a shared plugin. You need Claude Code installed, a paid Claude plan or an API (Console) account, git, and jq for the hook examples. Everything below was checked against the official docs in late November 2026.

Lay the foundation

1. Install and sanity-check

The native installer is the recommended route on macOS, Linux and WSL, and it updates itself in the background.

bash
curl -fsSL https://claude.ai/install.sh | bash
claude --version
claude doctor   # read-only install and settings diagnostics

2. Give the project a memory

Run /init inside a session. Claude scans the codebase and drafts a CLAUDE.md with build commands and conventions; if one exists, it suggests improvements instead of overwriting. Then trim it. Anthropic's guidance is to target under 200 lines per file, because every line is loaded into every session.

FileScopeCommit it?
~/.claude/CLAUDE.mdYou, all projectsNo
./CLAUDE.md or ./.claude/CLAUDE.mdWhole teamYes
./CLAUDE.local.mdYou, this repoNo (gitignore it)

Instructions that only matter for part of the codebase belong in .claude/rules/. A rule with a paths field loads only when Claude reads or edits a matching file:

markdown
---
paths:
  - "src/api/**/*.ts"
---

# API rules
- Validate every request body with the shared zod schemas.
- Return errors in the standard { code, message } shape.

You can pull other files in with @path/to/file (relative to the importing file, up to four hops deep), but imports only organise text; they do not reduce context cost. If your repo already has an AGENTS.md for other agents, put @AGENTS.md at the top of CLAUDE.md so both tools share one source of truth.

Delegate and enforce

3. Add a focused subagent

Subagents run in their own context window, so a long code review does not flood your main conversation. Project subagents live in .claude/agents/; only name and description are required.

markdown
---
name: reviewer
description: Reviews a diff for bugs, missing tests and security issues. Use after code changes, before committing.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a strict senior reviewer. Run `git diff` to see the change.
Report concrete problems with file and line, ordered by severity.
Do not edit files.

Claude uses the description to decide when to delegate. The tools allowlist is your safety boundary; omit it and the subagent inherits everything.

4. Make the non-negotiables deterministic with hooks

Instructions are suggestions; hooks are guarantees. They are shell commands that run at lifecycle events and receive the event as JSON on stdin. Add this to .claude/settings.json to format every file Claude edits and to block writes to sensitive paths:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "f=$(jq -r '.tool_input.file_path') && npx prettier --write --ignore-unknown \"$f\"" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-files.sh" }
        ]
      }
    ]
  }
}

The guard script reads the target path and exits with code 2 to block the call; whatever it prints to stderr goes back to Claude as the reason.

bash
#!/bin/bash
FILE_PATH=$(jq -r '.tool_input.file_path // empty')
for p in ".env" "package-lock.json" ".git/"; do
  if [[ "$FILE_PATH" == *"$p"* ]]; then
    echo "Blocked: $FILE_PATH is protected" >&2
    exit 2
  fi
done
exit 0

Save it as .claude/hooks/protect-files.sh, run chmod +x on it, then type /hooks in a session to confirm both hooks are registered.

Package and share

5. Turn procedures into skills

A skill is a folder with a SKILL.md. Only its description sits in context until Claude decides it is relevant, so skills are where long checklists and reference material should go. Custom slash commands have been folded into skills: old .claude/commands/*.md files still work, and every skill can be run manually as /skill-name.

markdown
---
name: release-notes
description: Drafts release notes from merged commits. Use when asked for a changelog or release summary.
disable-model-invocation: true
allowed-tools: Bash(git log *)
---

## Recent commits
!`git log --oneline -30`

Group the commits above into Features, Fixes and Internal. One line each.

Save it as .claude/skills/release-notes/SKILL.md. The !`command` line runs before Claude sees the skill, and disable-model-invocation: true means it only runs when you type /release-notes.

6. Share it as a plugin

Plugins bundle skills, subagents, hooks and MCP servers. Anthropic's official marketplace is registered automatically in interactive sessions:

code
/plugin install commit-commands@claude-plugins-official
/plugin marketplace add your-org/claude-plugins

Choosing project scope writes the plugin to .claude/settings.json, but each collaborator still has to install it once per clone (claude plugin install <name>@<marketplace> --scope project).

Pitfalls

  • Context creep. Large CLAUDE.md files, many always-on plugins and imported docs all cost tokens on every turn. Run claude plugin details <name> to see what a plugin adds.
  • Silent AGENTS.md shadowing. Recent versions read AGENTS.md only when no CLAUDE.md or CLAUDE.local.md exists, so adding a personal CLAUDE.local.md can stop your AGENTS.md loading. The explicit import avoids surprises.
  • Hooks run as you. They execute with your user's permissions. Review hook scripts in any repo or plugin before trusting them.
  • Contradictions. If two instruction files disagree, Claude may pick either. Audit them periodically.

Next steps

Steps 2 and 4 deliver most of the value. Add subagents and skills when you catch yourself repeating a request, and promote a stable setup to a plugin once teammates want it.

Researched and drafted with AI assistance under editorial review. Report errors to support@aiseeker.dev.

Sources

This report synthesises the sources below. Primary sources are marked.

  1. [1]
    How Claude remembers your project

    Anthropic (Claude Code Docs)2026.11.28Primary

  2. [2]
    Create custom subagents

    Anthropic (Claude Code Docs)2026.11.28Primary

  3. [3]
    Automate actions with hooks

    Anthropic (Claude Code Docs)2026.11.28Primary

  4. [4]
    Extend Claude with skills

    Anthropic (Claude Code Docs)2026.11.28Primary

  5. [5]
    Install and manage plugins

    Anthropic (Claude Code Docs)2026.11.28Primary

  6. [6]
    Advanced setup

    Anthropic (Claude Code Docs)2026.11.28Primary

Back to Tutorials →