Six Mechanisms, Three Dimensions, One Decision Tree: Deep Dive into Claude Code

This article provides an in‑depth technical analysis of Claude Code’s six extension mechanisms—Hooks, Skills, Slash Commands, MCP, Subagents, and Plugins—organized by three orthogonal dimensions (Trigger, Context, Domain), and shows how a three‑question decision tree and token‑cost considerations guide optimal usage and anti‑patterns.

AI Waka
AI Waka
AI Waka
Six Mechanisms, Three Dimensions, One Decision Tree: Deep Dive into Claude Code

You Will Learn

Claude Code extension taxonomy – three dimensions (who triggers, where context lives, what is delivered) and how each dimension eliminates half the candidates.

Six mechanisms in depth – Hooks (20+ lifecycle events), Skills (front‑matter with progressive disclosure), Slash Commands (bash injection), MCP (Model Context Protocol), Subagents, Plugins.

Channels and Agent Teams – how Claude reacts to Telegram, Discord, webhooks, and the difference between point‑to‑point Agent Mesh and Subagents.

Three orthogonal boundaries – Skill + Bash vs. MCP, Hook as the only deterministic mechanism, Subagent vs. Agent Team.

Optimal context‑management pattern – why Slash Commands and Subagents should delegate to thin Skills and how progressive disclosure reduces token overhead.

Decision tree – five concrete production scenarios that map the three questions to a single mechanism.

Plugin as a distribution layer – why it does not compete with the other five mechanisms and when to use it.

Organizing the Six Mechanisms into Three Dimensions

The most common mistake is treating the six mechanisms as interchangeable alternatives for the same job. In reality each occupies a unique cell in a 3‑D taxonomy:

TRIGGER – Deterministic (system‑driven), Model‑invoked (Claude decides), User‑invoked (explicit command).

CONTEXT – Shared (visible in the main session), Isolated (subagent window with its own 200 K token budget), Stateless (external process with no memory).

DOMAIN – Deterministic control (rules, formatting), Procedural knowledge (how‑to scripts), Access to external systems (processes outside Claude).

Answering three diagnostic questions—does the action need to fire regardless of model decision, where does its context reside, and does it require an external process—narrows the choice to a single mechanism in about 30 seconds.

Three orthogonal axes: TRIGGER, CONTEXT, DOMAIN
Three orthogonal axes: TRIGGER, CONTEXT, DOMAIN

Six Mechanisms in Depth

Hooks – deterministic lifecycle middleware

Hooks attach handlers to more than 20 Claude Code lifecycle events, grouped into five rhythms (session, per‑round, agent loop, compression, environment). Example events include SessionStart, UserPromptSubmit, PreToolUse, PostToolUseFailure, CwdChanged, and newer events such as UserPromptExpansion. Handlers can be of type command (shell script), http (POST), mcp_tool, prompt, or experimental agent. Exit code 0 signals success, 2 signals hard block, other codes allow non‑blocking errors. Structured JSON output on stdout determines the permission decision ( allow, deny, ask, defer). Matching is controlled by the matcher field (e.g., *, Edit|Write, regex). Configuration can live in multiple JSON/YAML files (user, project, managed, plugin) and all matching hooks run in parallel.

Skills – progressive disclosure with front‑matter metadata

A Skill is a directory containing SKILL.md and optional scripts. Its front‑matter defines fields that control when and how the Skill is invoked: name (required, lowercase, max 64 chars) – gives priority over a Slash Command of the same name. description (required) – not user‑facing but tells the main agent when to delegate. Anthropic recommends a strong, proactive description. when_to_use – supplemental trigger phrases. disable-model-invocation: true – prevents automatic model calls; the Skill becomes manual only. user-invocable: false – hides the Skill from the / menu. allowed-tools – pre‑approved tools (e.g., Read, Grep, Bash(git status *)). model – pins a cheaper model (sonnet, opus, haiku) for the Skill. context: fork + agent: Explore – runs the Skill in an isolated subagent. hooks – lifecycle hooks attached to the Skill. paths – glob patterns that trigger the Skill (e.g., src/**/*.ts). shell – default bash, can be changed to powershell. argument-hint + arguments – provide autocomplete and positional parameters.

Progressive disclosure works in three levels: (1) metadata (≈100 tokens) always present, (2) full SKILL.md (≈5 000 tokens) loaded only on invocation, (3) reference files/scripts loaded on demand, keeping token cost low.

Slash Commands – explicit calls with bash injection

Slash Commands are invoked with /. Two formats exist:

Legacy – flat .md files under .claude/commands/ (e.g., commands/git/commit.md/git:commit).

New – a Skill with user-invocable: true. Conflicts give the Skill priority.

Parameters are parsed with shell‑style quoting, allowing constructs like /migrate "Search Bar" React Vue. Claude Code ships with >60 built‑in Slash Commands (e.g., /clear, /model, /permissions, /plugin, /mcp) and dynamic MCP commands ( /mcp__<server>__<prompt>). Real‑time change detection watches the skill/command directories; new files become active without restarting the session (except top‑level skills/).

MCP – Model Context Protocol with three roles and five primitives

MCP defines a client‑server architecture with Host (Claude Code, Claude Desktop, VS Code), Client (maintains a connection per server), and Server (exposes context). Two layers exist:

Data layer – JSON‑RPC 2.0 with primitives Tools, Resources, Prompts.

Transport layer – stdio, Streamable HTTP, deprecated SSE.

Server‑side primitives: Tools – name, title, description, inputSchema, optional outputSchema; can return text, image, resource, audio, resource_link. Resources – data sources identified by URIs (file://, git://, https://, custom schemes) with optional subscription. Prompts – reusable templates exposed as Slash Commands.

Client‑side primitives: Samplingsampling/createMessage requests the LLM to generate text. Elicitationelicitation/create asks the user for extra input via a JSON‑Schema form.

Configuration scopes (local > project > user > plugin > cloud) support environment‑variable expansion. Token cost measurements show Bash adds ≈3 578 tokens per session, a Skill ≈1 831 tokens, and an MCP server 4 000–50 000 tokens, with large servers (e.g., Playwright) consuming ~7 % of a 200 K token context during handshake.

Subagent vs. Agent Team – isolation vs. parallelism

Subagents run in isolated windows, report back via summaries, and never communicate directly—ideal when the main conversation must stay free of test logs or repository exploration. Agent Teams form a mesh where members write to each other’s inboxes ( ~/.claude/teams/) and can run in parallel, costing ~7× a standard session. Use Subagents for single‑review tasks; use Agent Teams when multiple reviewers need to converse.

Optimal Context‑Management Pattern – Delegate to Skills

All five mechanisms load their full definition into the LLM context on each call, inflating token usage. Only Skills avoid this via progressive disclosure: the description field (≈100 tokens) is always present; the full SKILL.md (≈5 000 tokens) loads only when the model matches the description. Therefore, Slash Commands and Subagents should be thin wrappers that delegate to a Skill. Example: a /proofread Slash Command now contains only three lines that invoke the proofreading Skill, whose heavy knowledge lives in ~/.claude/skills/proofreading/SKILL.md. The same pattern applies to Subagents, reducing token cost dramatically and ensuring a single source of truth.

Decision Tree – Five Production Scenarios

The abstract framework becomes concrete through five real‑world scenarios, each starting with “What am I trying to do?” and ending with a single mechanism:

Auto‑format TypeScript on file save – Trigger: Deterministic ( Edit), Context: Stateless, Domain: Deterministic control → Hook on PostToolUse with matcher "Edit|Write" and command npx prettier --write.

Fetch an issue from Linear before handling a ticket – Trigger: Model‑invoked, Context: Stateless external process, Domain: External system → MCP server linear-mcp with OAuth.

Proofread a Polish article with specific style rules – Trigger: Model‑invoked, Context: Shared, Domain: Procedural knowledge → Skill containing language‑specific rules and optional validation script.

Isolated code review of a new PR – Trigger: Model‑invoked or user‑invoked, Context: Isolated window, Domain: Isolated procedural knowledge → Subagent with tools Read, Grep, Glob, Bash.

Deliberate deployment to staging – Trigger: User‑invoked, Context: Shared, Domain: Procedural knowledge with side effects → Slash Command with disable-model-invocation to force manual activation.

A sixth path (Plugin) does not appear because Plugins are merely distribution wrappers, not a functional mechanism.

Plugin as Distribution Layer – Four Controversies

Plugins contain a plugin.json manifest listing commands, agents, skills, hooks, and mcpServers. They provide version control, marketplace integration, and namespacing (e.g., acme:deploy) but add no new capabilities. The four debated statements are clarified:

“MCP is dead, Skills are taking over” – true only for the procedural‑knowledge slice; MCP still dominates external‑system integrations.

“Plugin is a new mechanism” – false; it is a wrapper.

“Slash Commands are just beautified prompts” – partially true; they still offer bash injection, parameter hints, and can be user‑invoked only.

“Hooks break determinism” – opposite; Hooks are the only deterministic mechanism, but they trade off sandbox isolation (shell‑trust).

Anti‑Patterns – When Not to Use a Mechanism

Hook – avoid when you need the model to reason before acting; Hooks fire on every matching event.

Skill – avoid for tasks that require external processes, OAuth, or network calls.

Slash Command – avoid when you want the model to auto‑invoke; use a Skill with user-invocable: true instead.

MCP – avoid for pure procedural knowledge; the overhead of a server, OAuth, and JSON‑RPC is disproportionate.

Subagent – avoid when parallelism is needed; choose Agent Teams instead.

Plugin – avoid for private workflows; the marketplace and version‑control overhead only pays off when distributing to others.

Summary and Core Takeaways

When faced with a new workflow step, ask three questions (who triggers, where context lives, what is delivered) to narrow the choice to a single mechanism within seconds. Skills and MCP are complementary: Skills encode "how" to use a tool, MCP provides the tool itself. Hooks are the only truly deterministic option, but they introduce shell‑trust risks. Plugins are merely packaging and versioning layers; for most private projects, a simple .claude/skills/ directory suffices.

Claude Code mechanism map and decision tree
Claude Code mechanism map and decision tree
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.

MCPHooksSkillsAI extensionsClaude Codesubagents
AI Waka
Written by

AI Waka

AI changes everything

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.