mirror of
https://github.com/anthropics/claude-code.git
synced 2026-04-19 01:52:42 +00:00
Compare commits
5 Commits
claude/sla
...
claude/sla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cad2569360 | ||
|
|
4392352687 | ||
|
|
c27c6f4e4a | ||
|
|
0dde1fef97 | ||
|
|
e4f682030b |
@@ -102,6 +102,17 @@
|
||||
"source": "./plugins/learning-output-style",
|
||||
"category": "learning"
|
||||
},
|
||||
{
|
||||
"name": "mcp-context-warning",
|
||||
"description": "Warns users when MCP servers are consuming significant context (>20k tokens), helping prevent unexpected context exhaustion",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Anthropic",
|
||||
"email": "support@anthropic.com"
|
||||
},
|
||||
"source": "./plugins/mcp-context-warning",
|
||||
"category": "productivity"
|
||||
},
|
||||
{
|
||||
"name": "plugin-dev",
|
||||
"description": "Comprehensive toolkit for developing Claude Code plugins. Includes 7 expert skills covering hooks, MCP integration, commands, agents, and best practices. AI-assisted plugin creation and validation.",
|
||||
|
||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -1,5 +1,31 @@
|
||||
# Changelog
|
||||
|
||||
## 2.0.71
|
||||
|
||||
- Added /config toggle to enable/disable prompt suggestions
|
||||
- Added `/settings` as an alias for the `/config` command
|
||||
- Fixed @ file reference suggestions incorrectly triggering when cursor is in the middle of a path
|
||||
- Fixed MCP servers from `.mcp.json` not loading when using `--dangerously-skip-permissions`
|
||||
- Fixed permission rules incorrectly rejecting valid bash commands containing shell glob patterns (e.g., `ls *.txt`, `for f in *.png`)
|
||||
- Bedrock: Environment variable `ANTHROPIC_BEDROCK_BASE_URL` is now respected for token counting and inference profile listing
|
||||
- New syntax highlighting engine for native build
|
||||
|
||||
## 2.0.70
|
||||
|
||||
- Added Enter key to accept and submit prompt suggestions immediately (tab still accepts for editing)
|
||||
- Added wildcard syntax `mcp__server__*` for MCP tool permissions to allow or deny all tools from a server
|
||||
- Added auto-update toggle for plugin marketplaces, allowing per-marketplace control over automatic updates
|
||||
- Added `plan_mode_required` spawn parameter for teammates to require plan approval before implementing changes
|
||||
- Added `current_usage` field to status line input, enabling accurate context window percentage calculations
|
||||
- Fixed input being cleared when processing queued commands while the user was typing
|
||||
- Fixed prompt suggestions replacing typed input when pressing Tab
|
||||
- Fixed diff view not updating when terminal is resized
|
||||
- Improved memory usage by 3x for large conversations
|
||||
- Improved resolution of stats screenshots copied to clipboard (Ctrl+S) for crisper images
|
||||
- Removed # shortcut for quick memory entry (tell Claude to edit your CLAUDE.md instead)
|
||||
- Fix thinking mode toggle in /config not persisting correctly
|
||||
- Improve UI for file creation permission dialog
|
||||
|
||||
## 2.0.69
|
||||
|
||||
- Minor bugfixes
|
||||
|
||||
@@ -22,23 +22,29 @@ Performs automated code review on a pull request using multiple specialized agen
|
||||
- **Agent #4**: Analyze git blame/history for context-based issues
|
||||
5. Scores each issue 0-100 for confidence level
|
||||
6. Filters out issues below 80 confidence threshold
|
||||
7. Posts review comment with high-confidence issues only
|
||||
7. Outputs review (to terminal by default, or as PR comment with `--comment` flag)
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
/code-review
|
||||
/code-review [--comment]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `--comment`: Post the review as a comment on the pull request (default: outputs to terminal only)
|
||||
|
||||
**Example workflow:**
|
||||
```bash
|
||||
# On a PR branch, run:
|
||||
# On a PR branch, run locally (outputs to terminal):
|
||||
/code-review
|
||||
|
||||
# Post review as PR comment:
|
||||
/code-review --comment
|
||||
|
||||
# Claude will:
|
||||
# - Launch 4 review agents in parallel
|
||||
# - Score each issue for confidence
|
||||
# - Post comment with issues ≥80 confidence
|
||||
# - Skip posting if no high-confidence issues found
|
||||
# - Output issues ≥80 confidence (to terminal or PR depending on flag)
|
||||
# - Skip if no high-confidence issues found
|
||||
```
|
||||
|
||||
**Features:**
|
||||
@@ -114,17 +120,23 @@ This plugin is included in the Claude Code repository. The command is automatica
|
||||
### Standard PR review workflow:
|
||||
```bash
|
||||
# Create PR with changes
|
||||
# Run local review (outputs to terminal)
|
||||
/code-review
|
||||
|
||||
# Review the automated feedback
|
||||
# Make any necessary fixes
|
||||
|
||||
# Optionally post as PR comment
|
||||
/code-review --comment
|
||||
|
||||
# Merge when ready
|
||||
```
|
||||
|
||||
### As part of CI/CD:
|
||||
```bash
|
||||
# Trigger on PR creation or update
|
||||
# Automatically posts review comments
|
||||
# Use --comment flag to post review comments
|
||||
/code-review --comment
|
||||
# Skip if review already exists
|
||||
```
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ Note: Still review Claude generated PR's.
|
||||
|
||||
6. Filter out any issues that were not validated in step 5. This step will give us our list of high signal issues for our review.
|
||||
|
||||
7. Finally, comment on the pull request.
|
||||
7. Finally, output the review.
|
||||
- If the `--comment` argument is provided, post the review as a comment on the pull request using `gh pr comment`
|
||||
- Otherwise (default), output the review directly to the terminal for local viewing
|
||||
When writing your comment, follow these guidelines:
|
||||
a. Keep your output brief
|
||||
b. Avoid emojis
|
||||
|
||||
9
plugins/mcp-context-warning/.claude-plugin/plugin.json
Normal file
9
plugins/mcp-context-warning/.claude-plugin/plugin.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "mcp-context-warning",
|
||||
"version": "1.0.0",
|
||||
"description": "Warns users when MCP servers are consuming significant context (>20k tokens), helping prevent unexpected context exhaustion",
|
||||
"author": {
|
||||
"name": "Anthropic",
|
||||
"email": "support@anthropic.com"
|
||||
}
|
||||
}
|
||||
164
plugins/mcp-context-warning/hooks/check_mcp_context.py
Executable file
164
plugins/mcp-context-warning/hooks/check_mcp_context.py
Executable file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
MCP Context Warning Hook for Claude Code
|
||||
|
||||
This hook runs at session start and warns users when their MCP servers
|
||||
are consuming significant context (>20k tokens). This helps users understand
|
||||
why they might be burning through context quickly.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Threshold in tokens for showing a warning
|
||||
TOKEN_WARNING_THRESHOLD = 20000
|
||||
|
||||
# Estimated tokens per MCP tool (based on real-world data:
|
||||
# Asana: ~836/tool, Gmail: ~833/tool, Google Calendar: ~1867/tool, Google Drive: ~1260/tool)
|
||||
# Using 1000 as a conservative average
|
||||
TOKENS_PER_TOOL_ESTIMATE = 1000
|
||||
|
||||
# Base overhead per MCP server (connection info, auth, etc.)
|
||||
BASE_TOKENS_PER_SERVER = 500
|
||||
|
||||
|
||||
def find_mcp_configs(cwd: str) -> list[tuple[str, dict]]:
|
||||
"""
|
||||
Find all MCP configuration files that might be loaded.
|
||||
|
||||
Returns list of (path, config) tuples.
|
||||
"""
|
||||
configs = []
|
||||
|
||||
# Check project-level .mcp.json
|
||||
project_mcp = Path(cwd) / ".mcp.json"
|
||||
if project_mcp.exists():
|
||||
try:
|
||||
with open(project_mcp) as f:
|
||||
configs.append((str(project_mcp), json.load(f)))
|
||||
except (json.JSONDecodeError, IOError):
|
||||
pass
|
||||
|
||||
# Check user-level MCP config (~/.claude/.mcp.json)
|
||||
user_mcp = Path.home() / ".claude" / ".mcp.json"
|
||||
if user_mcp.exists():
|
||||
try:
|
||||
with open(user_mcp) as f:
|
||||
configs.append((str(user_mcp), json.load(f)))
|
||||
except (json.JSONDecodeError, IOError):
|
||||
pass
|
||||
|
||||
return configs
|
||||
|
||||
|
||||
def count_servers_and_estimate_tools(configs: list[tuple[str, dict]]) -> tuple[dict, int]:
|
||||
"""
|
||||
Count MCP servers and estimate their tool counts.
|
||||
|
||||
Returns (server_info dict, total_estimated_tokens).
|
||||
"""
|
||||
server_info = {}
|
||||
|
||||
for path, config in configs:
|
||||
# MCP config format: {"mcpServers": {"server-name": {...}}}
|
||||
mcp_servers = config.get("mcpServers", {})
|
||||
|
||||
for server_name, server_config in mcp_servers.items():
|
||||
if server_name in server_info:
|
||||
continue # Skip duplicates
|
||||
|
||||
# Try to get tool count from config if available
|
||||
# Otherwise use a default estimate
|
||||
tool_count = server_config.get("toolCount", 10) # Default 10 tools
|
||||
|
||||
server_info[server_name] = {
|
||||
"source": path,
|
||||
"estimated_tools": tool_count,
|
||||
}
|
||||
|
||||
# Calculate total estimated tokens
|
||||
total_tokens = 0
|
||||
for server_name, info in server_info.items():
|
||||
server_tokens = BASE_TOKENS_PER_SERVER + (info["estimated_tools"] * TOKENS_PER_TOOL_ESTIMATE)
|
||||
info["estimated_tokens"] = server_tokens
|
||||
total_tokens += server_tokens
|
||||
|
||||
return server_info, total_tokens
|
||||
|
||||
|
||||
def format_warning_message(server_info: dict, total_tokens: int) -> str:
|
||||
"""Format a warning message about MCP context usage."""
|
||||
|
||||
# Build server breakdown table
|
||||
lines = [
|
||||
f"Your MCP servers are using an estimated ~{total_tokens:,} tokens of context.",
|
||||
"",
|
||||
"Server breakdown:",
|
||||
]
|
||||
|
||||
# Sort servers by token usage (highest first)
|
||||
sorted_servers = sorted(
|
||||
server_info.items(),
|
||||
key=lambda x: x[1]["estimated_tokens"],
|
||||
reverse=True
|
||||
)
|
||||
|
||||
for server_name, info in sorted_servers:
|
||||
tokens = info["estimated_tokens"]
|
||||
tools = info["estimated_tools"]
|
||||
lines.append(f" - {server_name}: ~{tokens:,} tokens ({tools} tools)")
|
||||
|
||||
lines.extend([
|
||||
"",
|
||||
"Consider disabling MCP servers you're not actively using to conserve context.",
|
||||
"You can manage MCP servers with `/mcp disable <server-name>` or by editing .mcp.json.",
|
||||
])
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main hook function."""
|
||||
# Read input from stdin
|
||||
try:
|
||||
raw_input = sys.stdin.read()
|
||||
input_data = json.loads(raw_input) if raw_input.strip() else {}
|
||||
except json.JSONDecodeError:
|
||||
# If we can't parse input, exit silently
|
||||
sys.exit(0)
|
||||
|
||||
# Get current working directory from hook input or environment
|
||||
cwd = input_data.get("cwd", os.environ.get("CLAUDE_PROJECT_DIR", os.getcwd()))
|
||||
|
||||
# Find MCP configurations
|
||||
configs = find_mcp_configs(cwd)
|
||||
|
||||
if not configs:
|
||||
# No MCP configs found, nothing to warn about
|
||||
sys.exit(0)
|
||||
|
||||
# Count servers and estimate tokens
|
||||
server_info, total_tokens = count_servers_and_estimate_tools(configs)
|
||||
|
||||
if not server_info:
|
||||
# No servers configured
|
||||
sys.exit(0)
|
||||
|
||||
# Check if we're over the warning threshold
|
||||
if total_tokens >= TOKEN_WARNING_THRESHOLD:
|
||||
warning_message = format_warning_message(server_info, total_tokens)
|
||||
|
||||
# Output JSON with systemMessage for Claude to see
|
||||
output = {
|
||||
"continue": True,
|
||||
"systemMessage": warning_message
|
||||
}
|
||||
print(json.dumps(output))
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
17
plugins/mcp-context-warning/hooks/hooks.json
Normal file
17
plugins/mcp-context-warning/hooks/hooks.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"description": "Warns users when MCP servers consume significant context (>20k tokens)",
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "*",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/check_mcp_context.py",
|
||||
"timeout": 10
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: Hook Development
|
||||
description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", "teleport hook", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
|
||||
description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
|
||||
version: 0.1.0
|
||||
---
|
||||
|
||||
@@ -239,12 +239,7 @@ Execute when user submits a prompt. Use to add context, validate, or block promp
|
||||
|
||||
Execute when Claude Code session begins. Use to load context and set environment.
|
||||
|
||||
**Matchers for SessionStart:**
|
||||
- `*` - All session starts
|
||||
- `teleport` - Only when session started via teleport (web → CLI)
|
||||
- `fresh` - Only for fresh sessions (not teleported)
|
||||
|
||||
**Example (general context loading):**
|
||||
**Example:**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
@@ -261,58 +256,12 @@ Execute when Claude Code session begins. Use to load context and set environment
|
||||
}
|
||||
```
|
||||
|
||||
**Example (teleport-specific setup):**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "teleport",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Example script (post-teleport.sh):**
|
||||
```bash
|
||||
#!/bin/bash
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||
|
||||
# Pull latest changes from the teleported branch
|
||||
if [ -d ".git" ]; then
|
||||
echo "🔄 Pulling latest changes..."
|
||||
git pull origin "$(git branch --show-current)" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Install dependencies if needed
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install --silent
|
||||
fi
|
||||
|
||||
# Start dev server (example for common workflow)
|
||||
if [ -f "package.json" ] && grep -q '"dev"' package.json; then
|
||||
echo "🚀 Starting dev server..."
|
||||
npm run dev &
|
||||
fi
|
||||
```
|
||||
|
||||
**Special capability:** Persist environment variables using `$CLAUDE_ENV_FILE`:
|
||||
```bash
|
||||
echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
|
||||
```
|
||||
|
||||
**Teleport-specific input fields:**
|
||||
- `is_teleport`: Boolean indicating if this session started via teleport
|
||||
- `source`: Where the session came from ("web" or "cli") - only present for teleports
|
||||
- `branch`: The git branch that was teleported - only present for teleports
|
||||
|
||||
See `examples/load-context.sh` and `examples/post-teleport.sh` for complete examples.
|
||||
See `examples/load-context.sh` for complete example.
|
||||
|
||||
### SessionEnd
|
||||
|
||||
@@ -689,7 +638,7 @@ echo "$output" | jq .
|
||||
| UserPromptSubmit | User input | Context, validation |
|
||||
| Stop | Agent stopping | Completeness check |
|
||||
| SubagentStop | Subagent done | Task validation |
|
||||
| SessionStart | Session begins | Context loading (use `teleport` matcher for teleport-specific setup) |
|
||||
| SessionStart | Session begins | Context loading |
|
||||
| SessionEnd | Session ends | Cleanup, logging |
|
||||
| PreCompact | Before compact | Preserve context |
|
||||
| Notification | User notified | Logging, reactions |
|
||||
@@ -730,7 +679,6 @@ Working examples in `examples/`:
|
||||
- **`validate-write.sh`** - File write validation example
|
||||
- **`validate-bash.sh`** - Bash command validation example
|
||||
- **`load-context.sh`** - SessionStart context loading example
|
||||
- **`post-teleport.sh`** - SessionStart teleport matcher setup example
|
||||
|
||||
### Utility Scripts
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Example SessionStart hook with "teleport" matcher for setting up environment
|
||||
# after teleporting from web to CLI. This script pulls changes, installs
|
||||
# dependencies, and starts the dev server.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Navigate to project directory
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||
|
||||
echo "Setting up environment after teleport..."
|
||||
|
||||
# Pull latest changes if in a git repository
|
||||
if [ -d ".git" ]; then
|
||||
current_branch=$(git branch --show-current)
|
||||
echo "🔄 Pulling latest changes for branch: $current_branch"
|
||||
git pull origin "$current_branch" 2>/dev/null || echo "Could not pull (may be offline or no upstream)"
|
||||
fi
|
||||
|
||||
# Install dependencies based on project type
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Installing Node.js dependencies..."
|
||||
npm install --silent 2>/dev/null || npm install
|
||||
fi
|
||||
|
||||
if [ -f "requirements.txt" ]; then
|
||||
echo "🐍 Installing Python dependencies..."
|
||||
pip install -r requirements.txt --quiet 2>/dev/null || pip install -r requirements.txt
|
||||
fi
|
||||
|
||||
if [ -f "Cargo.toml" ]; then
|
||||
echo "🦀 Building Rust project..."
|
||||
cargo build 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Start development server if available
|
||||
if [ -f "package.json" ]; then
|
||||
# Check for common dev server scripts
|
||||
if grep -q '"dev:staging"' package.json; then
|
||||
echo "🚀 Starting staging dev server..."
|
||||
npm run dev:staging &
|
||||
elif grep -q '"dev"' package.json; then
|
||||
echo "🚀 Starting dev server..."
|
||||
npm run dev &
|
||||
elif grep -q '"start"' package.json; then
|
||||
echo "🚀 Starting server..."
|
||||
npm start &
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "✅ Teleport complete! Environment ready."
|
||||
exit 0
|
||||
@@ -344,64 +344,3 @@ fi
|
||||
- Per-project settings
|
||||
- Team-specific rules
|
||||
- Dynamic validation criteria
|
||||
|
||||
## Pattern 11: Teleport Workflow Automation
|
||||
|
||||
Automate setup when teleporting sessions from web to CLI using the `teleport` matcher:
|
||||
|
||||
**SessionStart hook with teleport matcher:**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "teleport",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**post-teleport.sh:**
|
||||
```bash
|
||||
#!/bin/bash
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||
|
||||
# Pull latest changes
|
||||
if [ -d ".git" ]; then
|
||||
echo "🔄 Pulling latest changes..."
|
||||
git pull origin "$(git branch --show-current)" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Install dependencies
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install --silent
|
||||
fi
|
||||
|
||||
# Start dev server
|
||||
if [ -f "package.json" ] && grep -q '"dev:staging"' package.json; then
|
||||
echo "🚀 Starting staging dev server..."
|
||||
npm run dev:staging &
|
||||
elif [ -f "package.json" ] && grep -q '"dev"' package.json; then
|
||||
echo "🚀 Starting dev server..."
|
||||
npm run dev &
|
||||
fi
|
||||
|
||||
echo "✅ Teleport complete! Environment ready."
|
||||
```
|
||||
|
||||
**Available matchers for SessionStart:**
|
||||
- `*` - All session starts (both fresh and teleported)
|
||||
- `teleport` - Only teleported sessions (web → CLI)
|
||||
- `fresh` - Only fresh sessions (not teleported)
|
||||
|
||||
**Use for:**
|
||||
- Seamless web-to-CLI workflow transitions
|
||||
- Automatic dev server startup after teleporting
|
||||
- Pulling latest changes and installing dependencies
|
||||
- Running project-specific setup scripts
|
||||
|
||||
Reference in New Issue
Block a user