Làm chủ Claude Code trong một tuần (Phần 10): Plugins & Advanced Features
Đây là phần cuối cùng trong series "Làm chủ Claude Code trong một tuần". Trong bài này, chúng ta sẽ tìm hiểu Plugins và Advanced Features để kết hợp mọi thứ đã học.
Plugins là gì?
Plugins là bundled collections — kết hợp nhiều features (slash commands, subagents, MCP configs, hooks) thành một package dễ cài đặt và sử dụng.
┌────────────────────────────────────────────────────────────────┐
│ PLUGIN │
├────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ pr-review Plugin │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────┬───────────┼───────────┬───────────┐ │
│ ▼ ▼ ▼ ▼ ▼ │
│ ┌───────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───────┐ │
│ │Slash │ │ Sub- │ │ MCP │ │ Hooks │ │Memory │ │
│ │Commands│ │ agents │ │ Config │ │ │ │ │ │
│ │/review│ │reviewer │ │ GitHub │ │pre-push │ │CLAUDE │ │
│ │/pr │ │tester │ │ │ │ │ │.md │ │
│ └───────┘ └─────────┘ └─────────┘ └─────────┘ └───────┘ │
│ │
└────────────────────────────────────────────────────────────────┘
Cấu trúc Plugin
plugin-name/
├── plugin.json # Plugin manifest
├── commands/ # Slash commands
│ ├── review.md
│ └── pr.md
├── agents/ # Subagents
│ ├── reviewer.md
│ └── tester.md
├── mcp/ # MCP configurations
│ └── github.json
├── hooks/ # Hook scripts
│ └── pre-push.sh
├── memory/ # CLAUDE.md templates
│ └── project.md
└── README.md # Documentation
plugin.json
{
"name": "pr-review",
"version": "1.0.0",
"description": "Complete PR review workflow",
"author": "your-name",
"dependencies": {
"mcp": ["github"]
},
"install": {
"commands": "commands/",
"agents": "agents/",
"hooks": "hooks/",
"mcp": "mcp/github.json"
},
"setup": [
"Set GITHUB_TOKEN environment variable",
"Run: npm install -g @modelcontextprotocol/server-github"
]
}
Cài đặt Plugin
Via Slash Command
/plugin install pr-review
/plugin install devops-automation
/plugin install documentation
Manual Installation
# Clone plugin
git clone https://github.com/user/plugin-pr-review .claude/plugins/pr-review
# Copy components
cp -r .claude/plugins/pr-review/commands/* .claude/commands/
cp -r .claude/plugins/pr-review/agents/* .claude/agents/
cp -r .claude/plugins/pr-review/hooks/* ~/.claude/hooks/
Plugin Examples
1. PR Review Plugin
Commands:
/review- Start PR review/pr- Prepare PR description/merge-check- Verify merge readiness
Subagents:
@code-reviewer- Code quality review@security-scanner- Security analysis@test-checker- Test coverage analysis
MCP:
- GitHub server for PR data
Hooks:
- Pre-push: Run linting and tests
2. DevOps Automation Plugin
Commands:
/deploy- Deploy to environment/rollback- Rollback deployment/status- Check service status
Subagents:
@deployment-specialist- Deployment expert@monitoring-expert- System monitoring
MCP:
- Kubernetes server
- AWS server
Hooks:
- Pre-deploy: Validation checks
- Post-deploy: Health checks
3. Documentation Plugin
Commands:
/docs- Generate documentation/readme- Generate README/api-docs- Generate API documentation
Subagents:
@doc-writer- Documentation expert@api-documenter- API documentation specialist
Tạo Plugin của bạn
Step 1: Create structure
mkdir -p my-plugin/{commands,agents,hooks,mcp,memory}
touch my-plugin/plugin.json
touch my-plugin/README.md
Step 2: Define plugin.json
{
"name": "my-plugin",
"version": "1.0.0",
"description": "My custom workflow plugin",
"author": "your-name",
"dependencies": {},
"install": {
"commands": "commands/",
"agents": "agents/"
},
"setup": []
}
Step 3: Add components
# Add commands
cat > my-plugin/commands/my-command.md << 'EOF'
# My Command
Instructions for my custom command.
EOF
# Add agents
cat > my-plugin/agents/my-agent.md << 'EOF'
---
name: my-agent
description: My specialized agent
tools:
- Read
---
# My Agent
You are a specialized agent for...
EOF
Step 4: Document
# My Plugin
## Installation
/plugin install my-plugin
## Usage
- `/my-command` - Description
- `@my-agent` - Description
## Configuration
Set environment variable: MY_VAR=value
Advanced Features
1. Planning Mode
Planning Mode cho phép Claude tạo detailed implementation plan trước khi code.
Kích hoạt
# Via environment variable
CLAUDE_PERMISSION_MODE=plan claude
# Via settings
# ~/.claude/settings.json
{
"defaultPermissionMode": "plan"
}
Workflow
User: "Implement authentication system"
Claude (Planning Mode):
## Implementation Plan
### Phase 1: Database Schema
1. Create users table migration
2. Create password_resets table migration
3. Create sessions table migration
### Phase 2: Models
1. Create User model with relationships
2. Create Session model
### Phase 3: Authentication Logic
1. Create AuthService
2. Implement login/logout
3. Implement password reset
### Phase 4: Controllers & Routes
1. Create AuthController
2. Add routes
### Phase 5: Testing
1. Unit tests for AuthService
2. Feature tests for endpoints
---
Proceed with implementation? [Y/n]
Best Practices
- Use for complex features
- Review plan before proceeding
- Adjust plan if needed
- Track progress against plan
2. Extended Thinking
Extended Thinking cho phép Claude "suy nghĩ" sâu hơn cho complex problems.
Kích hoạt
Toggle: Alt+T (Windows/Linux) hoặc Option+T (Mac)
When to Use
- Complex architectural decisions
- Difficult debugging
- Algorithm design
- Security analysis
- Performance optimization
Example
User: "Design a rate limiting system that scales across multiple servers"
Claude (Extended Thinking):
[Thinking...]
- Need to consider distributed state
- Options: Redis, database, in-memory with sync
- Trade-offs: consistency vs performance
- Must handle race conditions
- Consider burst handling
- Think about per-user vs per-IP vs per-endpoint limits
[Response]
## Rate Limiting System Design
### Architecture
Using Redis for distributed state with sliding window algorithm.
### Components
1. **Redis Cluster**: Shared state across servers
2. **Rate Limiter Middleware**: Per-request check
3. **Configuration Store**: Dynamic limits
### Algorithm: Sliding Window Log
```php
public function isAllowed(string $key, int $limit, int $window): bool
{
$now = microtime(true);
$windowStart = $now - $window;
// Remove old entries
$this->redis->zRemRangeByScore($key, 0, $windowStart);
// Count current window
$count = $this->redis->zCard($key);
if ($count >= $limit) {
return false;
}
// Add current request
$this->redis->zAdd($key, $now, $now);
$this->redis->expire($key, $window);
return true;
}
Scaling Considerations
...
## 3. Background Tasks
Background Tasks cho phép chạy long-running operations mà không block main session.
### Kích hoạt
User: "Run full test suite in background"
Claude: Starting background task... Task ID: task_abc123 You can check status with: /task-status task_abc123
### Use Cases
- Full test suite execution
- Large codebase analysis
- Documentation generation
- Database migrations
- Build processes
### Monitoring
/task-status task_abc123
Output: Task: task_abc123 Status: Running (45% complete) Started: 5 minutes ago Estimated: 6 minutes remaining Current: Running integration tests...
## 4. Permission Modes
| Mode | Behavior |
|------|----------|
| `default` | Ask for every permission |
| `acceptEdits` | Auto-accept file edits |
| `plan` | Planning mode only |
| `dontAsk` | Execute without asking |
| `bypassPermissions` | Skip all permission checks |
### Configuration
```json
// ~/.claude/settings.json
{
"defaultPermissionMode": "acceptEdits",
"projectPermissions": {
"/path/to/trusted/project": "dontAsk",
"/path/to/critical/project": "default"
}
}
Use Cases
default: Learning, critical projectsacceptEdits: Normal developmentplan: Architecture planningdontAsk: CI/CD automationbypassPermissions: Fully automated scripts
5. Session Management
Commands
| Command | Description |
|---|---|
/resume <name> |
Resume named session |
/rename <name> |
Rename current session |
/fork |
Fork current session |
/sessions |
List all sessions |
Best Practices
# Name sessions by feature
claude -r "feature-auth" "implement authentication"
# Later, continue work
claude -r "feature-auth" "add password reset"
# Fork for experimentation
# In session:
/fork
# Now in forked session, try different approach
6. Advanced Hooks Configuration
Conditional Hooks
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write",
"condition": {
"path": "*.php"
},
"hooks": ["~/.claude/hooks/php-format.sh"]
},
{
"matcher": "Write",
"condition": {
"path": "*.ts"
},
"hooks": ["~/.claude/hooks/ts-format.sh"]
}
]
}
}
Hook Chains
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write",
"hooks": [
"~/.claude/hooks/format.sh",
"~/.claude/hooks/lint.sh",
"~/.claude/hooks/security-scan.sh",
"~/.claude/hooks/notify.sh"
]
}
]
}
}
Workflow hoàn chỉnh
Scenario: Feature Development
# 1. Start named session
claude -r "feature-user-profile"
# 2. Enable planning mode for design
User: "Design user profile feature with avatar upload"
[Planning mode creates detailed plan]
# 3. Switch to implementation
User: "Proceed with Phase 1 (Database)"
[Claude creates migrations]
# 4. Delegate to subagents
User: "Have @test-engineer create tests for the models"
[Test engineer creates tests]
# 5. Security review
User: "Have @secure-reviewer check the implementation"
[Security reviewer provides analysis]
# 6. Generate documentation
User: "/docs for user profile feature"
[Documentation generated]
# 7. Prepare PR
User: "/pr"
[PR description generated]
# 8. Run CI checks (background)
User: "Run full test suite in background"
[Background task started]
Kết hợp mọi thứ
┌────────────────────────────────────────────────────────────────┐
│ COMPLETE CLAUDE CODE WORKFLOW │
├────────────────────────────────────────────────────────────────┤
│ │
│ 1. CLAUDE.md → Project context loaded │
│ 2. Slash Commands → Quick actions available │
│ 3. Skills → Auto-triggered capabilities │
│ 4. Subagents → Specialized help on demand │
│ 5. MCP → External data access │
│ 6. Hooks → Automated validations │
│ 7. Checkpoints → Safe experimentation │
│ 8. Planning Mode → Detailed planning │
│ 9. Extended Thinking → Deep problem solving │
│ 10. Background Tasks → Non-blocking operations │
│ 11. Plugins → Bundled workflows │
│ │
│ Result: 10x Developer Productivity │
│ │
└────────────────────────────────────────────────────────────────┘
Best Practices tổng kết
1. Start Simple
Week 1: Slash Commands + Memory
Week 2: Skills + Hooks
Week 3: MCP + Subagents
Week 4: Plugins + Advanced Features
2. Version Control Everything
# Add to git
git add CLAUDE.md .claude/
git commit -m "chore: add Claude Code configuration"
3. Document Your Setup
# README Addition
## Claude Code Setup
This project uses Claude Code with:
- Custom slash commands in `.claude/commands/`
- Team subagents in `.claude/agents/`
- Project memory in `CLAUDE.md`
To get started:
1. Install Claude Code
2. Run: `claude` in project root
3. Use `/help` to see available commands
4. Iterate and Improve
- Start with claude-howto templates
- Customize for your workflow
- Share improvements with team
- Contribute back to community
Tổng kết Series
Qua 10 phần của series, bạn đã học:
- Introduction: Overview Claude Code features
- Slash Commands: Quick custom commands
- Memory: Persistent context với CLAUDE.md
- Checkpoints: Safe experimentation
- CLI: Automation và scripting
- Skills: Auto-triggered capabilities
- Hooks: Event-driven automation
- MCP: External service integration
- Subagents: Specialized AI assistants
- Plugins & Advanced: Bundling và power features
Next Steps
- Clone claude-howto
- Copy templates vào project của bạn
- Customize cho workflow
- Share với team
Tài nguyên
Cảm ơn bạn đã theo dõi series! Happy coding với Claude Code! 🚀
Series này được dịch và mở rộng từ claude-howto — MIT License.