For the complete documentation index, see llms.txt. This page is also available as Markdown.

Mở rộng Claude Code — Skills, Hooks, Subagents và MCP

Hướng dẫn mở rộng Claude Code với Skills (workflow tái sử dụng), Hooks (tự động hóa), Subagents (agent riêng) và MCP (kết nối công cụ bên ngoài).

Claude Code có 4 cơ chế mở rộng chính, mỗi loại phù hợp với mục đích khác nhau. Hiểu lúc nào dùng cái nào giúp bạn build workflow hiệu quả và maintainable.

Tổng quan 4 cơ chế

Cơ chế
Ai trigger
Load khi nào
Dùng cho

Skills

Claude auto hoặc bạn /skill

On-demand, khi relevant

Workflow tái sử dụng, domain knowledge

Hooks

Claude lifecycle events

Mỗi lần event trigger

Deterministic actions, auto-format, lint

Subagents

Bạn yêu cầu Claude

Khi bạn ask "use subagent"

Research trong context riêng

MCP

Claude dùng tool

Session start, khi cần data

Kết nối external services

Skills

Skills extend Claude's knowledge với project-specific hoặc domain-specific information. Claude tự động apply khi relevant, hoặc bạn invoke trực tiếp.

Tạo skill

Tạo thư mục với file SKILL.md trong .claude/skills/:

.claude/skills/api-conventions/SKILL.md
---
name: api-conventions
description: REST API design conventions for our services
---
# API Conventions
- Use kebab-case for URL paths
- Use camelCase for JSON properties
- Always include pagination for list endpoints
- Version APIs in the URL path (/v1/, /v2/)

Skill với workflow

Skills có thể define repeatable workflows bạn invoke trực tiếp:

Gọi skill:

Dùng disable-model-invocation: true cho workflows có side effects mà bạn muốn trigger manually, không để Claude tự invoke.

Hooks

Hooks chạy shell commands tại các lifecycle events cụ thể. Khác với CLAUDE.md (advisory), hooks deterministic — guarantee action happen.

Lifecycle events

Event
Khi nào trigger

PreToolUse

Trước khi tool được execute

PostToolUse

Sau khi tool hoàn thành

SessionStart

Session bắt đầu

SessionEnd

Session kết thúc

UserPromptSubmit

User submit prompt

PreCompact

Trước khi compact context

PostCompact

Sau khi compact

Stop

Claude dừng respond

SubagentStop

Subagent dừng

Notification

Có notification

Ví dụ hook

Tạo hook bằng Claude

Dùng /hooks để browse all configured hooks.

Subagents

Subagents chạy trong context riêng với tools riêng. Hữu ích cho tasks đọc nhiều files hoặc cần specialized focus mà không clutter main conversation.

Tạo subagent

Sử dụng subagent

Writer/Reviewer pattern

Dùng 2 sessions — 1 viết, 1 review:

Session A (Writer)
Session B (Reviewer)

Implement a rate limiter for our API

Review the rate limiter in @src/middleware/rateLimiter.ts

Address the review feedback: [output from B]

MCP (Model Context Protocol)

MCP là open standard kết nối AI tools với external data sources. Claude Code có thể read Google Drive, update Jira tickets, query databases, tích hợp Figma designs qua MCP.

Thêm MCP server

Ví dụ:

Quản lý MCP

Dùng MCP resources

Format: @server:resource — fetch data từ connected MCP servers.

Plugins

Plugins bundle skills, hooks, subagents, và MCP servers thành installable units từ community và Anthropic.

Browse marketplace và cài đặt one-click. Đặc biệt hữu ích:

  • Code intelligence plugin — precise symbol navigation, auto error detection

  • commit-commands — Git commit helpers

  • code-review — Automated code review

Khi nào dùng cái nào?

Nhu cầu
Dùng

Claude cần biết coding conventions

CLAUDE.md hoặc Skill

Workflow có thể tái sử dụng

Skill

Auto-format sau mỗi file edit

Hook

Block action deterministic

Hook

Research codebase không làm sạch context

Subagent

Review code trong context riêng

Subagent

Kết nối Jira, Notion, Figma

MCP

Query database từ Claude

MCP

Cài đặt bundle tools

Plugin

Tài liệu tham khảo

Cập nhật lần cuối