⚙️ Настройка Claude Code
Установка, конфигурация settings.json, permissions, CLAUDE.md шаблон и оптимизация токенов.
🚀 Установка
# Установка глобально через npm
npm install -g @anthropic-ai/claude-code
# Проверка версии
claude --version
# Запуск в папке проекта
cd E:\Clients\myproject
claude
⚙️ settings.json — глобальный конфиг
// ~/.claude/settings.json (или C:\Users\..\.claude\settings.json)
{
"model": "sonnet", // Default модель — Sonnet (дешевле Opus в 5x)
"alwaysThinkingEnabled": true, // Extended thinking по умолчанию
"env": {
"MCP_TOOL_SEARCH": "1", // КРИТИЧНО: -47-95% токенов на MCP
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "400000", // Авто-компактация до 400K токенов
"DISABLE_TELEMETRY": "1", // Отключить телеметрию
"COST_ALERT_THRESHOLD": "5" // Алерт cost-tracker при $5/день
},
"permissions": {
"allow": [
"Read(*)", "Glob(*)", "Grep(*)",
"Edit(*)", "Write(*)", "MultiEdit(*)",
"Bash(git status*)", "Bash(git log*)", "Bash(git diff*)",
"Bash(git add*)", "Bash(git commit*)",
"Bash(php*)", "Bash(composer*)",
"Bash(python*)", "Bash(ruff*)", "Bash(mypy*)",
"Bash(pnpm*)", "Bash(npx*)",
"mcp__docker__*",
"mcp__postgres-pro__query"
],
"deny": [
"Bash(git push --force*)", "Bash(git push -f*)",
"Bash(git reset --hard*)", "Bash(git checkout --*)",
"Bash(*--no-verify*)",
"Bash(*DROP TABLE*)", "Bash(*TRUNCATE*)",
"Bash(psql*)", "Bash(pg_dump*)", "Bash(mysqldump*)",
"Bash(php artisan migrate:fresh*)",
"Bash(php artisan db:wipe*)"
]
},
"hooks": {
"PreToolUse": [
{ "matcher": "Bash", "hooks": [
{ "type": "command", "command": "node .claude/helpers/dangerous-command-guard.cjs" },
{ "type": "command", "command": "node .claude/helpers/bash-mcp-guard.cjs" },
{ "type": "command", "command": "node .claude/helpers/secret-scanner.cjs" }
]},
{ "matcher": "Edit|Write|MultiEdit", "hooks": [
{ "type": "command", "command": "node .claude/helpers/critical-files-guard.cjs" }
]}
],
"PostToolUse": [
{ "matcher": "Edit|Write|MultiEdit", "hooks": [
{ "type": "command", "command": "node .claude/helpers/auto-format.cjs" }
]}
],
"Stop": [
{ "matcher": ".*", "hooks": [
{ "type": "command", "command": "node .claude/helpers/cost-tracker.cjs" }
]}
]
}
}
📄 CLAUDE.md — шаблон проекта
Ограничение: CLAUDE.md читается целиком при каждом запуске. Держать до 150 строк. Длинные файлы могут частично игнорироваться. Детали → в examples/ и docs/.
# CLAUDE.md — шаблон (скопировать и адаптировать)
# Правило: < 150 строк!
## Проект
**Название:** `my-project`
**Цель:** Краткое описание (1-2 строки)
**Прод:** https://site.ru
**Контейнеры:** my-project-backend-1, my-project-db-1
## Стэк
- PHP 8.3 / Laravel 11 (или другой стэк)
- PostgreSQL 16, Redis 7
- Docker Compose, Caddy
## Модель
- **Default:** Sonnet 4.6
- **Opus 4.7:** только /brainstorm и /write-plan
- **Haiku 4.5:** rename, format
## Workflow новой фичи
1. /brainstorm → spec → /write-plan → plan
2. git worktree → claude → /execute-plan
3. /request-code-review → PR → merge
## Стандарты кода
- **PHP:** PSR-12 + Pint. Всегда declare(strict_types=1)
- **Vue/TS:** ESLint flat + Prettier. Только Composition API
## Критические правила
- **БД:** только mcp__postgres__query (read-only)
- **Git:** запрещены --force, --no-verify, reset --hard
- **При буксовании:** /clear + переформулируй
## Запрещённые паттерны
- $request->all() без $fillable
- Eloquent в Controller
- any в TypeScript без обоснования
📊 Модели и стоимость
// Цены ($ за 1M токенов, 2026):
claude-opus-4-7: input $15 / output $75 // Только для планирования
claude-sonnet-4-6: input $3 / output $15 // ← Default для работы
claude-haiku-4-5: input $0.8 / output $4 // Для простых задач
// Переключение в сессии:
// /model sonnet
// /model opus
// /model haiku
Стратегия: Sonnet — ежедневная работа. Opus — только /brainstorm и /write-plan для крупных задач. Haiku — batch-переименования, форматирование. Экономия до 20× при правильном выборе.