Mastering Claude Code: Skills, Hooks, Subagents and More – Official Guidance
The article explains the seven ways to steer Claude Code—CLAUDE.md files, rules, skills, subagents, hooks, output styles, and appending system prompts—detailing when each loads, how compression affects them, their context cost, and the scenarios where they are most appropriate.
Overview
Claude can be customized to follow your workflow, and Claude Code adds seven distinct mechanisms for directing its behavior: CLAUDE.md files , rules , skills , subagents , hooks , output styles , and appending system prompts . Each method influences three dimensions: when the instruction is loaded into the context, whether it persists through long sessions (compression), and its token cost.
Comparison of the Seven Methods
CLAUDE.md (root) – loaded at session start and stays for the whole session; high token cost because every line is always in context; ideal for build commands, monorepo layout, coding conventions, and team policies.
CLAUDE.md (subdirectory) – loaded on demand when Claude reads a file in that subdirectory; low token cost; suited for directory‑specific conventions.
Rules – user‑level rules load at session start; path‑scoped rules load only when a matching file is touched; medium token cost; good for constraints such as “all API handlers must validate input with Zod”.
Skills – name and description load at session start; full content loads only when the skill is invoked (e.g., /code‑review); low token cost; perfect for workflow‑type instructions like deployment checklists.
Subagents – name, description, and tool list load at session start; the body loads only when an agent tool calls the subagent; low token cost; useful for isolated side‑tasks such as deep search, log analysis, or dependency audit.
Hooks – user‑defined commands, HTTP endpoints, or prompts that fire on specific Claude lifecycle events (file edit, tool use, session start); never compressed; low token cost because they live outside the main context; ideal for deterministic actions like running a linter after every edit or sending a Slack notification after a task completes.
Output styles – files under .claude/output‑styles/ inject instructions into the system prompt; never compressed; medium token cost; they have the highest instruction weight and should be used cautiously.
Appending system prompts – a CLI flag that adds extra text to the default system prompt for a single call; token cost can be higher than other methods but does not persist across calls.
Practical Guidance
CLAUDE.md : keep the file under 200 lines, assign an owner, and review changes like code. In monorepos, give each team its own sub‑directory CLAUDE.md and use claudeMdExcludes to skip unrelated files. For organization‑wide standards, deploy a centrally managed CLAUDE.md via MDM.
Rules : prefer path‑scoped rules for file‑level constraints; avoid global rules that consume tokens in unrelated work.
Skills : place process‑oriented instructions (deployment runbooks, release checklists) here. Skills are invoked via slash commands or automatic matching and share a token budget that evicts the earliest calls when exhausted.
Subagents : use when you need isolation and the result does not need to be referenced later (e.g., deep search, log analysis). They run in a separate context window and return only a final summary.
Hooks : employ for deterministic actions that must always happen, such as formatting with Prettier after every edit or blocking disallowed commands with PreToolUse. Managed hooks provide organization‑level guardrails.
Output styles : modify only when you want to change Claude’s overall role; otherwise keep the built‑in styles (Proactive, Explanatory, Learning) which already cover most needs.
Appending system prompts : best for supplementing specific coding standards or domain knowledge; avoid overloading as too many additions reduce compliance, especially when they conflict.
Quick Decision Framework
If you find yourself writing “always do X after Y” in CLAUDE.md, move it to a hook. If you write “never do Z” in CLAUDE.md, use a hook or permission guard. Long procedural flows belong in skills, not CLAUDE.md. Directory‑specific constraints should be expressed with path‑scoped rules.
Getting Started
Follow the official Claude Code best‑practice guide for environment setup and parallel session extensions. Once the basic mechanisms work, package skills, subagents, hooks, and output styles into a plugin for easy sharing across teams or projects.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Tech Publishing
In the fast-evolving AI era, we thoroughly explain stable technical foundations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
