Mastering Claude Code: From CLAUDE.md to Plugins – A Complete Engineering Guide

This article explains how to turn Claude Code from a forgetful one‑off assistant into a fully engineered teammate by using persistent CLAUDE.md files, on‑demand Skills, independent Subagents, Model Context Protocol (MCP) integrations, Hooks for enforcement, and Plugins for easy packaging and sharing, complete with real‑world examples and step‑by‑step configurations.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Mastering Claude Code: From CLAUDE.md to Plugins – A Complete Engineering Guide

Many developers use Claude Code by simply opening a terminal, typing a request, and waiting for it to finish, only to lose all context when a new session starts. Because the model has no memory across sessions, every new conversation requires re‑explaining the project’s framework, build commands, and immutable files.

Persisting Project Context with CLAUDE.md

Claude Code provides a built‑in solution: place a CLAUDE.md markdown file in the project. The file is automatically read at the start of each session and becomes the foundation for all subsequent interactions. Three placement levels exist:

Global: ~/.claude/CLAUDE.md – applies to all projects.

Project root – the most common level, containing technology stack, commands, and conventions.

Sub‑directory – loaded only when Claude accesses that directory, allowing module‑specific rules.

Example project CLAUDE.md:

# 项目说明
Spring Boot 服务,JDK 8,禁止用高版本语法。

## 常用命令
- 单测:mvn test -pl web
- 打包:mvn clean package -DskipTests

## 铁律
- core 模块是祖传代码,只读,不许改
- 表结构变更必须走 Flyway,不许手写 ALTER TABLE

The file should contain explicit commands (e.g., mvn test -pl web) and hard rules (e.g., "不许改") to avoid ambiguous language.

On‑Demand Knowledge with Skills

For knowledge that is needed only occasionally, Claude Code offers Skills . Each Skill is a folder containing a SKILL.md file with front‑matter metadata (name and one‑sentence description) followed by the full implementation. Claude loads only the description initially; the full content is fetched when the Skill is invoked.

Example code‑review Skill:

---
name: code-review
description: 审查代码改动时使用,包含团队的检查清单和输出格式
---

审查改动时按以下重点检查:
1. 有没有绕过 service 层直接查库
2. 新接口有没有做参数校验
3. 错误处理是吞掉了还是往上抛了
审查结果按「问题、位置、建议」三栏输出。

Parallel Workers with Subagents

When a task becomes too heavy for the main conversation (e.g., scanning an entire repository), you can delegate it to a Subagent . Subagents run in isolated contexts, perform searches, run commands, and return only the final conclusions, keeping the main dialogue clean.

Subagent configuration lives in .claude/agents/ as markdown files with front‑matter and a system prompt. Example code‑reviewer Subagent:

---
name: code-reviewer
description: 代码改动的专项审查,检查安全、性能与规范
tools: Read, Grep, Glob
model: haiku
---

你是团队的代码审查员,只做审查不做修改。
逐个检查改动文件,重点看安全漏洞与性能隐患。
最终只输出问题列表与修改建议,不要贴大段代码原文。

Subagents can run in parallel—for instance, one for security checks, one for performance analysis, and one for test coverage—doubling efficiency.

Connecting to External Systems with MCP

Claude Code cannot directly call external APIs. The Model Context Protocol (MCP) defines a standard client‑server interface that lets Claude invoke tools such as GitHub, databases, or custom services. After registering an MCP server, Claude can request operations like get_pull_request or add_issue_comment without manual copy‑pasting.

Example MCP registration command:

claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer YOUR_GITHUB_TOKEN"

Once connected, a single sentence like "审一下 128 号 PR" triggers the tool, runs the code‑review Skill, and posts the review back to the PR.

Enforcing Rules with Hooks

Hooks act as a door‑lock system that runs shell commands at specific lifecycle events (e.g., before or after a tool use). They guarantee that critical policies are always enforced.

Post‑tool‑use formatting hook:

"hooks": {
  "PostToolUse": [{
    "matcher": "Edit|Write",
    "hooks": [{
      "type": "command",
      "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
    }]
  }]
}

Pre‑tool‑use protection hook that blocks modifications to .env or secret files:

"PreToolUse": [{
  "matcher": "Edit|Write",
  "hooks": [{
    "type": "command",
    "command": "~/.claude/hooks/protect.sh"
  }]
}]

Content of protect.sh:

#!/bin/bash
file=$(jq -r '.tool_input.file_path')
if [[ "$file" == *.env* || "$file" == *secret* ]]; then
  echo "敏感文件禁止修改" >&2
  exit 2
fi

Packaging Everything with Plugins

To avoid manually copying dozens of files across projects, Claude Code supports Plugins —a package manager for all configurations. A plugin is a folder with a fixed structure:

my-review-kit/
├── .claude-plugin/plugin.json   # name, version, description
├── skills/                     # all Skill folders
├── agents/                     # all Subagent folders
├── hooks/                      # Hook JSON files
└── .mcp.json                   # MCP integration config

Publish the plugin to a marketplace (a Git repository) and install it with a single command, e.g.: /plugin install my-review-kit@team-marketplace All team members instantly receive the same review checklist, Subagent, Hooks, and MCP setup, and updates propagate with a new plugin version.

Full End‑to‑End Workflow

When a developer asks Claude to review a PR, the following happens:

Claude loads the project‑level CLAUDE.md (project context).

MCP fetches the PR diff from GitHub.

The request is delegated to the code‑reviewer Subagent, which loads the code‑review Skill and runs the checklist in its own isolated context.

The Subagent returns a concise list of issues; Claude presents only the summary to the user.

If code changes are made, the post‑tool Hook automatically runs prettier on edited files, while the pre‑tool Hook blocks edits to sensitive files.

Finally, the review comments are posted back to the PR via MCP.

This pipeline demonstrates how the six components—CLAUDE.md, Skills, Subagents, MCP, Hooks, and Plugins—work together to make Claude Code behave like a disciplined, collaborative team.

Conclusion

Claude Code’s raw capabilities are impressive, but stable, repeatable results come from engineering scaffolding that mirrors decades‑old software‑engineering practices: onboarding manuals, modular knowledge bases, task delegation, external integrations, enforcement mechanisms, and package management. By building this scaffolding, you turn a forgetful AI assistant into a reliable teammate.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationMCPPrompt EngineeringAI engineeringPluginsClaude Code
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.