Plugin Best Practices Advanced
Guidelines for building robust, secure, and maintainable Claude Code plugin configurations that work well for individuals and teams.
Plugin Architecture Decisions
| Need | Use This | Not This |
|---|---|---|
| Auto-format after edits | Hooks (postToolUse) | Custom MCP server |
| Database access | MCP server with read-only user | Bash tool with raw SQL |
| Team workflows | Custom commands (.claude/commands/) | Shared shell scripts |
| Third-party API access | MCP server with auth handling | Bash with curl and hardcoded tokens |
| Editor integration | Official VS Code extension | Custom terminal wrapper |
Security Considerations
Secrets Management
Never commit API keys, tokens, or credentials. Use environment variable references in configuration and set values in your shell profile or .env files excluded from git.
Least Privilege
MCP servers should have minimal permissions. Use read-only database users, scoped API tokens, and restricted file system access.
Input Validation
Custom tools must validate all inputs. Never pass user-provided strings directly to SQL queries, shell commands, or API calls without sanitization.
Audit Trail
Log all tool invocations, especially for destructive operations. Include timestamps, parameters, and results in your logs.
Performance Impact
- Hooks are synchronous - Claude Code waits for each hook to finish. Keep hook commands under 2 seconds. For slow operations, use
&to run in the background. - MCP servers run as separate processes - Each server consumes memory. On resource-constrained machines, limit the number of active servers.
- Tool definitions consume tokens - Every MCP tool's description is included in Claude's context. More tools = more overhead per request.
.mcp.json instead of user-level configuration to keep irrelevant servers from loading.
Team Plugin Sharing
project-root/
.claude/
commands/ # Custom slash commands (git-tracked)
deploy.md
code-review.md
test-all.md
settings.json # Project-level hooks (git-tracked)
.mcp.json # MCP server config (git-tracked, no secrets)
.env # API keys and tokens (git-ignored!)
.env.example # Template for .env (git-tracked)
CLAUDE.md # Project context (git-tracked)
Debugging Plugins
-
Use /doctor for diagnostics
Claude Code's
/doctorcommand checks your configuration and reports issues with MCP servers, permissions, and settings. -
Test hooks manually
Run the hook command directly in your terminal with test values for environment variables to verify it works outside of Claude Code.
-
Check MCP server logs
MCP servers may log errors to stderr. Check
~/.claude/logs/for server connection issues. -
Validate JSON configuration
A single misplaced comma in settings.json or .mcp.json can break all plugins. Use a JSON validator.
Common Pitfalls
Committing Secrets
Accidentally committing .mcp.json with hardcoded API keys. Always use environment variable references and add .env to .gitignore.
Slow Hooks
Hooks that run linters on the entire project instead of just the changed file. Always scope hook commands to the specific file being changed.
Too Many MCP Servers
Loading 10+ MCP servers means 10+ processes and potentially hundreds of tool descriptions in context. Only configure what you need.
Not Testing After Updates
Claude Code updates may change hook behavior or MCP protocol versions. Re-test your plugins after major Claude Code updates.
Frequently Asked Questions
Can I disable a hook temporarily?
You can comment out hook entries in your settings.json (JSON does not support comments, so you would need to remove and re-add them) or rename the settings file temporarily. There is no built-in toggle mechanism.
Do MCP servers persist between Claude Code sessions?
No. MCP servers are started when Claude Code launches and stopped when it exits. They do not run in the background. Each new Claude Code session starts fresh MCP server instances.
Can I use MCP servers from Docker containers?
Yes. Set the command to docker run with the appropriate image. This is useful for MCP servers that require specific dependencies or isolation.
How do I share MCP server configurations across multiple projects?
Use user-level configuration (~/.claude/claude_desktop_config.json) for MCP servers you want available everywhere. Use project-level .mcp.json for project-specific servers.
Are there performance benchmarks for hooks?
As a guideline, hooks should complete in under 2 seconds. Formatting a single file with Prettier takes ~200ms, ESLint takes ~500ms. If your hook takes longer, consider running it in the background or scoping it more narrowly.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX