claude-code-tool-patterns
3
总安装量
3
周安装量
#60698
全站排名
安装命令
npx skills add https://github.com/shimo4228/claude-code-learned-skills --skill claude-code-tool-patterns
Agent 安装分布
replit
3
openclaw
3
mcpjam
2
claude-code
2
windsurf
2
zencoder
2
Skill 文档
Claude Code Tool Patterns & Gotchas
Extracted: 2026-02-09 (consolidated 2026-02-10) Context: Claude Code ã®ãã¼ã«ä½¿ç¨æã«çºçããã¡ãªåé¡ã¨ãã®åé¿ç
1. Large File Write Performance
Problem
Very large files (>3000 lines) in a single Write tool call become extremely slow and may appear to hang.
Symptoms:
- Write operation takes >60 seconds
- User interrupts thinking it’s stuck
- No feedback on progress
Solution
Split large files into modular components:
- Identify logical boundaries (chapters, sections, domains)
- Create multiple focused files (200-800 lines each)
- Add navigation file (README/index) to tie them together
- Write files in parallel when possible
# BAD: Single monolithic file
/docs/architecture.md (4000 lines) â 90+ seconds
# GOOD: Modular files
/docs/architecture/
âââ README.md (200 lines)
âââ 00-overview.md (600 lines)
âââ 01-adr-backend.md (500 lines)
âââ ...
â Each write completes in ~5-10 seconds
2. File Edit Refresh Pattern
Problem
Edit tool fails with “File has been modified since read” when file state has changed since last Read.
Solution
Always Read immediately before Edit:
# BAD: Edit without recent Read
- Earlier: Read file.py
- (Multiple other operations)
- Later: Edit file.py # May fail
# GOOD: Read immediately before Edit
- Earlier: Read file.py
- (Multiple other operations)
- Later: Read file.py # Refresh state
- Then: Edit file.py # Safe to edit
When to Apply
- Before every Edit call in sessions with multiple file operations
- After file state might have changed through other tools
- In long-running sessions (context near limits)
- When you see “File has been modified” errors
3. Hook Command JSON Escape Trap
Problem
settings.json ã® hooks ã«ã·ã§ã«ã³ãã³ããç´æ¥æ¸ãã¨ã\", $, \n ãªã©ã®
ç¹æ®æåã JSON ãã¼ã¹ã¨ã©ã¼ï¼”Bad control character in string literal”ï¼ãå¼ãèµ·ããã
Solution
å¤é¨ã¹ã¯ãªãããã¡ã¤ã«ã«åãåºã:
# ~/.claude/hooks/my-hook.sh
#!/bin/bash
file=$(jq -r '.tool_input.file_path // empty')
if [ -n "$file" ] && echo "$file" | grep -q '\.py$'; then
ruff format "$file" 2>/dev/null
fi
exit 0
// settings.json â ã·ã³ãã«ãªã³ãã³ãã ããè¨è¿°
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "bash ~/.claude/hooks/my-hook.sh"
}]
}]
}
}
When to Apply
- Hook ã³ãã³ãã«å¼ç¨ç¬¦ã夿°å±éããã¤ããæ¡ä»¶åå²ãå«ã¾ããå ´å
- settings.json ã® JSON validation ã¨ã©ã¼ãåºãå ´å
When to Use
- Planning to write a file >1000 lines
- Editing files after many intervening tool calls
- In complex multi-step workflows with frequent file operations
- Hook ã«è¤éãªã·ã§ã«ã³ãã³ããè¨å®ããå ´å