claudient 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +42 -0
- package/CONTEXT.md +58 -0
- package/README.md +165 -0
- package/agents/build-resolvers/de/python-resolver.md +64 -0
- package/agents/build-resolvers/de/typescript-resolver.md +65 -0
- package/agents/build-resolvers/es/python-resolver.md +64 -0
- package/agents/build-resolvers/es/typescript-resolver.md +65 -0
- package/agents/build-resolvers/fr/python-resolver.md +64 -0
- package/agents/build-resolvers/fr/typescript-resolver.md +65 -0
- package/agents/build-resolvers/nl/python-resolver.md +64 -0
- package/agents/build-resolvers/nl/typescript-resolver.md +65 -0
- package/agents/build-resolvers/python-resolver.md +62 -0
- package/agents/build-resolvers/typescript-resolver.md +63 -0
- package/agents/core/architect.md +64 -0
- package/agents/core/code-reviewer.md +78 -0
- package/agents/core/de/architect.md +66 -0
- package/agents/core/de/code-reviewer.md +80 -0
- package/agents/core/de/planner.md +63 -0
- package/agents/core/de/security-reviewer.md +93 -0
- package/agents/core/es/architect.md +66 -0
- package/agents/core/es/code-reviewer.md +80 -0
- package/agents/core/es/planner.md +63 -0
- package/agents/core/es/security-reviewer.md +93 -0
- package/agents/core/fr/architect.md +66 -0
- package/agents/core/fr/code-reviewer.md +80 -0
- package/agents/core/fr/planner.md +63 -0
- package/agents/core/fr/security-reviewer.md +93 -0
- package/agents/core/nl/architect.md +66 -0
- package/agents/core/nl/code-reviewer.md +80 -0
- package/agents/core/nl/planner.md +63 -0
- package/agents/core/nl/security-reviewer.md +93 -0
- package/agents/core/planner.md +61 -0
- package/agents/core/security-reviewer.md +91 -0
- package/guides/agent-orchestration.md +231 -0
- package/guides/de/agent-orchestration.md +174 -0
- package/guides/de/getting-started.md +164 -0
- package/guides/de/hooks-cookbook.md +160 -0
- package/guides/de/memory-management.md +153 -0
- package/guides/de/security.md +180 -0
- package/guides/de/skill-authoring.md +214 -0
- package/guides/de/token-optimization.md +156 -0
- package/guides/es/agent-orchestration.md +174 -0
- package/guides/es/getting-started.md +164 -0
- package/guides/es/hooks-cookbook.md +160 -0
- package/guides/es/memory-management.md +153 -0
- package/guides/es/security.md +180 -0
- package/guides/es/skill-authoring.md +214 -0
- package/guides/es/token-optimization.md +156 -0
- package/guides/fr/agent-orchestration.md +174 -0
- package/guides/fr/getting-started.md +164 -0
- package/guides/fr/hooks-cookbook.md +227 -0
- package/guides/fr/memory-management.md +169 -0
- package/guides/fr/security.md +180 -0
- package/guides/fr/skill-authoring.md +214 -0
- package/guides/fr/token-optimization.md +158 -0
- package/guides/getting-started.md +164 -0
- package/guides/hooks-cookbook.md +423 -0
- package/guides/memory-management.md +192 -0
- package/guides/nl/agent-orchestration.md +174 -0
- package/guides/nl/getting-started.md +164 -0
- package/guides/nl/hooks-cookbook.md +160 -0
- package/guides/nl/memory-management.md +153 -0
- package/guides/nl/security.md +180 -0
- package/guides/nl/skill-authoring.md +214 -0
- package/guides/nl/token-optimization.md +156 -0
- package/guides/security.md +229 -0
- package/guides/skill-authoring.md +226 -0
- package/guides/token-optimization.md +169 -0
- package/hooks/lifecycle/cost-tracker.md +49 -0
- package/hooks/lifecycle/cost-tracker.sh +59 -0
- package/hooks/lifecycle/pre-compact-save.md +56 -0
- package/hooks/lifecycle/pre-compact-save.sh +37 -0
- package/hooks/lifecycle/session-start.md +50 -0
- package/hooks/lifecycle/session-start.sh +47 -0
- package/hooks/post-tool-use/audit-log.md +53 -0
- package/hooks/post-tool-use/audit-log.sh +53 -0
- package/hooks/post-tool-use/prettier.md +53 -0
- package/hooks/post-tool-use/prettier.sh +49 -0
- package/hooks/pre-tool-use/block-dangerous.md +48 -0
- package/hooks/pre-tool-use/block-dangerous.sh +76 -0
- package/hooks/pre-tool-use/git-push-confirm.md +46 -0
- package/hooks/pre-tool-use/git-push-confirm.sh +36 -0
- package/mcp/configs/github.json +11 -0
- package/mcp/configs/postgres.json +11 -0
- package/mcp/de/recommended-servers.md +170 -0
- package/mcp/es/recommended-servers.md +170 -0
- package/mcp/fr/recommended-servers.md +170 -0
- package/mcp/nl/recommended-servers.md +170 -0
- package/mcp/recommended-servers.md +168 -0
- package/package.json +45 -0
- package/prompts/project-starters/de/fastapi-project.md +62 -0
- package/prompts/project-starters/de/nextjs-project.md +82 -0
- package/prompts/project-starters/es/fastapi-project.md +62 -0
- package/prompts/project-starters/es/nextjs-project.md +82 -0
- package/prompts/project-starters/fastapi-project.md +60 -0
- package/prompts/project-starters/fr/fastapi-project.md +62 -0
- package/prompts/project-starters/fr/nextjs-project.md +82 -0
- package/prompts/project-starters/nextjs-project.md +80 -0
- package/prompts/project-starters/nl/fastapi-project.md +62 -0
- package/prompts/project-starters/nl/nextjs-project.md +82 -0
- package/prompts/system-prompts/ai-product.md +80 -0
- package/prompts/system-prompts/data-pipeline.md +76 -0
- package/prompts/system-prompts/de/ai-product.md +82 -0
- package/prompts/system-prompts/de/data-pipeline.md +78 -0
- package/prompts/system-prompts/de/saas-backend.md +71 -0
- package/prompts/system-prompts/es/ai-product.md +82 -0
- package/prompts/system-prompts/es/data-pipeline.md +78 -0
- package/prompts/system-prompts/es/saas-backend.md +71 -0
- package/prompts/system-prompts/fr/ai-product.md +82 -0
- package/prompts/system-prompts/fr/data-pipeline.md +78 -0
- package/prompts/system-prompts/fr/saas-backend.md +71 -0
- package/prompts/system-prompts/nl/ai-product.md +82 -0
- package/prompts/system-prompts/nl/data-pipeline.md +78 -0
- package/prompts/system-prompts/nl/saas-backend.md +71 -0
- package/prompts/system-prompts/saas-backend.md +69 -0
- package/prompts/task-specific/changelog.md +81 -0
- package/prompts/task-specific/de/changelog.md +83 -0
- package/prompts/task-specific/de/debugging.md +78 -0
- package/prompts/task-specific/de/pr-description.md +69 -0
- package/prompts/task-specific/debugging.md +76 -0
- package/prompts/task-specific/es/changelog.md +83 -0
- package/prompts/task-specific/es/debugging.md +78 -0
- package/prompts/task-specific/es/pr-description.md +69 -0
- package/prompts/task-specific/fr/changelog.md +83 -0
- package/prompts/task-specific/fr/debugging.md +78 -0
- package/prompts/task-specific/fr/pr-description.md +69 -0
- package/prompts/task-specific/nl/changelog.md +83 -0
- package/prompts/task-specific/nl/debugging.md +78 -0
- package/prompts/task-specific/nl/pr-description.md +69 -0
- package/prompts/task-specific/pr-description.md +67 -0
- package/rules/common/coding-style.md +45 -0
- package/rules/common/de/coding-style.md +47 -0
- package/rules/common/de/git.md +48 -0
- package/rules/common/de/performance.md +40 -0
- package/rules/common/de/security.md +45 -0
- package/rules/common/de/testing.md +45 -0
- package/rules/common/es/coding-style.md +47 -0
- package/rules/common/es/git.md +48 -0
- package/rules/common/es/performance.md +40 -0
- package/rules/common/es/security.md +45 -0
- package/rules/common/es/testing.md +45 -0
- package/rules/common/fr/coding-style.md +47 -0
- package/rules/common/fr/git.md +48 -0
- package/rules/common/fr/performance.md +40 -0
- package/rules/common/fr/security.md +45 -0
- package/rules/common/fr/testing.md +45 -0
- package/rules/common/git.md +46 -0
- package/rules/common/nl/coding-style.md +47 -0
- package/rules/common/nl/git.md +48 -0
- package/rules/common/nl/performance.md +40 -0
- package/rules/common/nl/security.md +45 -0
- package/rules/common/nl/testing.md +45 -0
- package/rules/common/performance.md +38 -0
- package/rules/common/security.md +43 -0
- package/rules/common/testing.md +43 -0
- package/rules/language-specific/de/go.md +48 -0
- package/rules/language-specific/de/python.md +38 -0
- package/rules/language-specific/de/typescript.md +51 -0
- package/rules/language-specific/es/go.md +48 -0
- package/rules/language-specific/es/python.md +38 -0
- package/rules/language-specific/es/typescript.md +51 -0
- package/rules/language-specific/fr/go.md +48 -0
- package/rules/language-specific/fr/python.md +38 -0
- package/rules/language-specific/fr/typescript.md +51 -0
- package/rules/language-specific/go.md +46 -0
- package/rules/language-specific/nl/go.md +48 -0
- package/rules/language-specific/nl/python.md +38 -0
- package/rules/language-specific/nl/typescript.md +51 -0
- package/rules/language-specific/python.md +36 -0
- package/rules/language-specific/typescript.md +49 -0
- package/scripts/cli.js +161 -0
- package/scripts/link-skills.sh +35 -0
- package/scripts/list-skills.sh +34 -0
- package/skills/ai-engineering/agent-construction.md +285 -0
- package/skills/ai-engineering/claude-api.md +248 -0
- package/skills/ai-engineering/de/agent-construction.md +287 -0
- package/skills/ai-engineering/de/claude-api.md +250 -0
- package/skills/ai-engineering/es/agent-construction.md +287 -0
- package/skills/ai-engineering/es/claude-api.md +250 -0
- package/skills/ai-engineering/fr/agent-construction.md +287 -0
- package/skills/ai-engineering/fr/claude-api.md +250 -0
- package/skills/ai-engineering/nl/agent-construction.md +287 -0
- package/skills/ai-engineering/nl/claude-api.md +250 -0
- package/skills/backend/dotnet/csharp.md +304 -0
- package/skills/backend/dotnet/de/csharp.md +306 -0
- package/skills/backend/dotnet/es/csharp.md +306 -0
- package/skills/backend/dotnet/fr/csharp.md +306 -0
- package/skills/backend/dotnet/nl/csharp.md +306 -0
- package/skills/backend/go/de/go.md +307 -0
- package/skills/backend/go/es/go.md +307 -0
- package/skills/backend/go/fr/go.md +307 -0
- package/skills/backend/go/go.md +305 -0
- package/skills/backend/go/nl/go.md +307 -0
- package/skills/backend/nodejs/de/nestjs.md +274 -0
- package/skills/backend/nodejs/de/nextjs.md +222 -0
- package/skills/backend/nodejs/es/nestjs.md +274 -0
- package/skills/backend/nodejs/es/nextjs.md +222 -0
- package/skills/backend/nodejs/fr/nestjs.md +274 -0
- package/skills/backend/nodejs/fr/nextjs.md +222 -0
- package/skills/backend/nodejs/nestjs.md +272 -0
- package/skills/backend/nodejs/nextjs.md +220 -0
- package/skills/backend/nodejs/nl/nestjs.md +274 -0
- package/skills/backend/nodejs/nl/nextjs.md +222 -0
- package/skills/backend/python/de/django.md +285 -0
- package/skills/backend/python/de/fastapi.md +244 -0
- package/skills/backend/python/django.md +283 -0
- package/skills/backend/python/es/django.md +285 -0
- package/skills/backend/python/es/fastapi.md +244 -0
- package/skills/backend/python/fastapi.md +242 -0
- package/skills/backend/python/fr/django.md +285 -0
- package/skills/backend/python/fr/fastapi.md +244 -0
- package/skills/backend/python/nl/django.md +285 -0
- package/skills/backend/python/nl/fastapi.md +244 -0
- package/skills/data-ml/dbt-data-pipelines.md +155 -0
- package/skills/data-ml/de/dbt-data-pipelines.md +157 -0
- package/skills/data-ml/de/pandas-polars.md +147 -0
- package/skills/data-ml/de/pytorch-tensorflow.md +171 -0
- package/skills/data-ml/es/dbt-data-pipelines.md +157 -0
- package/skills/data-ml/es/pandas-polars.md +147 -0
- package/skills/data-ml/es/pytorch-tensorflow.md +171 -0
- package/skills/data-ml/fr/dbt-data-pipelines.md +157 -0
- package/skills/data-ml/fr/pandas-polars.md +147 -0
- package/skills/data-ml/fr/pytorch-tensorflow.md +171 -0
- package/skills/data-ml/nl/dbt-data-pipelines.md +157 -0
- package/skills/data-ml/nl/pandas-polars.md +147 -0
- package/skills/data-ml/nl/pytorch-tensorflow.md +171 -0
- package/skills/data-ml/pandas-polars.md +145 -0
- package/skills/data-ml/pytorch-tensorflow.md +169 -0
- package/skills/database/de/graphql.md +181 -0
- package/skills/database/es/graphql.md +181 -0
- package/skills/database/fr/graphql.md +181 -0
- package/skills/database/graphql.md +179 -0
- package/skills/database/nl/graphql.md +181 -0
- package/skills/devops-infra/de/docker.md +133 -0
- package/skills/devops-infra/de/github-actions.md +179 -0
- package/skills/devops-infra/de/kubernetes.md +129 -0
- package/skills/devops-infra/de/terraform.md +130 -0
- package/skills/devops-infra/docker.md +131 -0
- package/skills/devops-infra/es/docker.md +133 -0
- package/skills/devops-infra/es/github-actions.md +179 -0
- package/skills/devops-infra/es/kubernetes.md +129 -0
- package/skills/devops-infra/es/terraform.md +130 -0
- package/skills/devops-infra/fr/docker.md +133 -0
- package/skills/devops-infra/fr/github-actions.md +179 -0
- package/skills/devops-infra/fr/kubernetes.md +129 -0
- package/skills/devops-infra/fr/terraform.md +130 -0
- package/skills/devops-infra/github-actions.md +177 -0
- package/skills/devops-infra/kubernetes.md +127 -0
- package/skills/devops-infra/nl/docker.md +133 -0
- package/skills/devops-infra/nl/github-actions.md +179 -0
- package/skills/devops-infra/nl/kubernetes.md +129 -0
- package/skills/devops-infra/nl/terraform.md +130 -0
- package/skills/devops-infra/terraform.md +128 -0
- package/skills/finance-payments/de/stripe.md +187 -0
- package/skills/finance-payments/es/stripe.md +187 -0
- package/skills/finance-payments/fr/stripe.md +187 -0
- package/skills/finance-payments/nl/stripe.md +187 -0
- package/skills/finance-payments/stripe.md +185 -0
- package/workflows/code-review.md +151 -0
- package/workflows/de/code-review.md +153 -0
- package/workflows/de/debugging-session.md +146 -0
- package/workflows/de/feature-development.md +155 -0
- package/workflows/de/new-project-bootstrap.md +175 -0
- package/workflows/de/refactor-safely.md +150 -0
- package/workflows/debugging-session.md +144 -0
- package/workflows/es/code-review.md +153 -0
- package/workflows/es/debugging-session.md +146 -0
- package/workflows/es/feature-development.md +155 -0
- package/workflows/es/new-project-bootstrap.md +175 -0
- package/workflows/es/refactor-safely.md +150 -0
- package/workflows/feature-development.md +153 -0
- package/workflows/fr/code-review.md +153 -0
- package/workflows/fr/debugging-session.md +146 -0
- package/workflows/fr/feature-development.md +155 -0
- package/workflows/fr/new-project-bootstrap.md +175 -0
- package/workflows/fr/refactor-safely.md +150 -0
- package/workflows/new-project-bootstrap.md +173 -0
- package/workflows/nl/code-review.md +153 -0
- package/workflows/nl/debugging-session.md +146 -0
- package/workflows/nl/feature-development.md +155 -0
- package/workflows/nl/new-project-bootstrap.md +175 -0
- package/workflows/nl/refactor-safely.md +150 -0
- package/workflows/refactor-safely.md +148 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Token-Optimierungsleitfaden
|
|
2
|
+
|
|
3
|
+
Wie Sie Claude Code-Kosten reduzieren und die Antwortgeschwindigkeit verbessern, ohne die Ausgabequalität zu opfern.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Das Grundprinzip
|
|
8
|
+
|
|
9
|
+
Jeder Token im Kontextfenster von Claude Code kostet Geld und verlangsamt Antworten. Das Ziel ist, das Kontextfenster schlank zu halten — nur das, was Claude braucht, um die aktuelle Aufgabe gut zu erledigen.
|
|
10
|
+
|
|
11
|
+
Es gibt vier Hebel:
|
|
12
|
+
1. **Modellauswahl** — die richtige Modell-Aufgaben-Zuordnung
|
|
13
|
+
2. **Kontextverwaltung** — Kontrolle über den Fensterinhalt
|
|
14
|
+
3. **MCP-Disziplin** — Begrenzung des Tool-Overheads
|
|
15
|
+
4. **Komprimierungsstrategie** — wann und wie der Verlauf komprimiert wird
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 1. Modellauswahl
|
|
20
|
+
|
|
21
|
+
Claude Code unterstützt mehrere Modelle. Das falsche Modell für eine Aufgabe zu wählen ist der teuerste einzelne Fehler.
|
|
22
|
+
|
|
23
|
+
| Modell | Am besten für | Relative Kosten |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| Claude Haiku 4.5 | Einfache Bearbeitungen, Einzeldatei-Aufgaben, repetitive Operationen, Zusammenfassung | Niedrigste |
|
|
26
|
+
| Claude Sonnet 4.6 | Die meiste Entwicklungsarbeit — Multi-Datei-Änderungen, Debugging, Code-Review | Mittel |
|
|
27
|
+
| Claude Opus 4.7 | Komplexe Architekturentscheidungen, Sicherheitsanalyse, Multi-Agent-Orchestrierung | Höchste |
|
|
28
|
+
|
|
29
|
+
**Faustregeln:**
|
|
30
|
+
- Standard: Sonnet 4.6 für allgemeine Entwicklung
|
|
31
|
+
- Wechseln Sie zu Haiku 4.5 für: Linting-Korrekturen, Formatierung, einfache Umbenennungen, Einzelfunktions-Bearbeitungen, Boilerplate-Generierung aus einer Vorlage
|
|
32
|
+
- Eskalieren Sie zu Opus 4.7 nur wenn: das Problem tiefes Reasoning über viele Dateien erfordert, Sicherheitsentscheidungen involviert sind, oder Sie mehrere Sub-Agenten orchestrieren
|
|
33
|
+
|
|
34
|
+
**Haiku spart ~60 % gegenüber Sonnet bei geeigneten Aufgaben.**
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 2. Kontextfensterverwaltung
|
|
39
|
+
|
|
40
|
+
Das Kontextfenster von Claude Code ist groß (bis zu 1M Tokens bei Opus 4.7 und Sonnet 4.6), aber das **nutzbare** Fenster ist kleiner, sobald der Overhead berücksichtigt wird.
|
|
41
|
+
|
|
42
|
+
### Was Kontext verbraucht
|
|
43
|
+
|
|
44
|
+
| Quelle | Ungefähre Kosten |
|
|
45
|
+
|---|---|
|
|
46
|
+
| MCP-Tools (10 aktiviert) | ~30k Tokens |
|
|
47
|
+
| CLAUDE.md (Projekt + Benutzer) | 1k–10k Tokens |
|
|
48
|
+
| Konversationsverlauf | Wächst mit jedem Turn |
|
|
49
|
+
| Dateiinhalte im Kontext | Variiert — oft der größte Faktor |
|
|
50
|
+
| System-Prompt | ~5k–10k Tokens |
|
|
51
|
+
|
|
52
|
+
### Kontext schlank halten
|
|
53
|
+
|
|
54
|
+
**CLAUDE.md:**
|
|
55
|
+
- Halten Sie Projekt-CLAUDE.md unter 500 Zeilen
|
|
56
|
+
- Entfernen Sie Regeln, die nicht mehr für den aktuellen Projektzustand gelten
|
|
57
|
+
- Duplizieren Sie keine Inhalte aus Benutzer-CLAUDE.md in Projekt-CLAUDE.md
|
|
58
|
+
|
|
59
|
+
**Dateilesungen:**
|
|
60
|
+
- Bitten Sie Claude, spezifische Zeilenbereiche statt vollständiger Dateien zu lesen
|
|
61
|
+
- Vermeiden Sie es, dieselbe große Datei mehrmals in einer Sitzung zu lesen
|
|
62
|
+
- Verwenden Sie Sub-Agenten für isolierte Aufgaben — sie erhalten ein frisches Kontextfenster
|
|
63
|
+
|
|
64
|
+
**Konversationsverlauf:**
|
|
65
|
+
- Lange Sitzungen sammeln toten Kontext an
|
|
66
|
+
- Lösen Sie die Komprimierung proaktiv aus, anstatt auf den automatischen Schwellenwert zu warten
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 3. MCP-Disziplin
|
|
71
|
+
|
|
72
|
+
Jeder aktivierte MCP-Server lädt seine Tool-Definitionen beim Sitzungsstart in den Kontext. Mit 10 MCP-Servern und ~8 Tools pro Server verbrauchen Sie ~80 Tool-Slots — etwa 30k Tokens, bevor Sie ein Wort getippt haben.
|
|
73
|
+
|
|
74
|
+
**Auditieren Sie Ihre aktiven MCPs:**
|
|
75
|
+
- Aktivieren Sie nur MCPs, die Sie im aktuellen Projekt verwenden
|
|
76
|
+
- Deaktivieren Sie domänenspezifische MCPs (z.B. Datenbank, Cloud), wenn Sie nicht in diesem Bereich arbeiten
|
|
77
|
+
- Überprüfen Sie `.claude/settings.json` und `~/.claude/settings.json` auf aktivierte Server
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 4. Komprimierungsstrategie
|
|
82
|
+
|
|
83
|
+
Claude Code komprimiert den Konversationsverlauf automatisch, wenn der Kontext seine Grenze erreicht. Der Standardschwellenwert ist spät — er wird bei ~95 % Kapazität ausgelöst.
|
|
84
|
+
|
|
85
|
+
### Komprimierung früher auslösen
|
|
86
|
+
|
|
87
|
+
Verwenden Sie den Befehl `/compact` manuell, bevor Sie eine neue größere Aufgabe beginnen.
|
|
88
|
+
|
|
89
|
+
**Wann manuell komprimieren:**
|
|
90
|
+
- Vor dem Wechsel von einer großen Aufgabe zu einer anderen in derselben Sitzung
|
|
91
|
+
- Nach einer langen Debugging-Sitzung mit vielen fehlgeschlagenen Versuchen im Verlauf
|
|
92
|
+
- Vor dem Start einer Aufgabe, die das Lesen vieler großer Dateien erfordert
|
|
93
|
+
|
|
94
|
+
### Was Komprimierung bewirkt
|
|
95
|
+
|
|
96
|
+
Die Komprimierung fasst den Konversationsverlauf zusammen und ersetzt ihn durch eine komprimierte Darstellung. Sie verlieren den genauen turn-by-turn Verlauf, behalten aber Entscheidungen, geschriebenen Code und Schlüsselkontext.
|
|
97
|
+
|
|
98
|
+
**Pre-Compact-Hook:** Verwenden Sie einen `PreCompact`-Hook, um kritischen Sitzungszustand in eine Datei zu speichern, bevor die Komprimierung ausgelöst wird.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 5. Prompt-Effizienz
|
|
103
|
+
|
|
104
|
+
**Seien Sie spezifisch bezüglich des Umfangs:**
|
|
105
|
+
|
|
106
|
+
Statt: "Behebe die Authentifizierung"
|
|
107
|
+
Verwenden Sie: "Behebe die JWT-Ablaufprüfung in `auth/middleware.py:45` — sie lehnt keine Tokens mit `exp` in der Vergangenheit ab"
|
|
108
|
+
|
|
109
|
+
**Begrenzen Sie die Antwortlänge wenn angemessen:**
|
|
110
|
+
|
|
111
|
+
Für Aufgaben, bei denen Sie eine Code-Änderung, aber keine Erklärung benötigen: "Nehmen Sie die Änderung vor, keine Erklärung nötig."
|
|
112
|
+
|
|
113
|
+
**Bündeln Sie verwandte Anfragen:**
|
|
114
|
+
|
|
115
|
+
Statt fünf separater "füge einen Test für X hinzu"-Anfragen sagen Sie: "Füge Tests für alle fünf Funktionen in `utils.py` hinzu."
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 6. Sub-Agent-Kontextisolierung
|
|
120
|
+
|
|
121
|
+
Sub-Agenten erhalten ein frisches Kontextfenster. Dies ist eine der am meisten unterschätzten Optimierungstechniken.
|
|
122
|
+
|
|
123
|
+
**Verwenden Sie Sub-Agenten wenn:**
|
|
124
|
+
- Eine Aufgabe in sich abgeschlossen ist (klare Eingaben, klare Ausgaben)
|
|
125
|
+
- Die Aufgabe das Lesen vieler Dateien erfordert, die für den Rest der Sitzung nicht relevant sind
|
|
126
|
+
- Sie etwas Repetitives über mehrere Dateien hinweg tun
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 7. Kostenverfolgung
|
|
131
|
+
|
|
132
|
+
Verwenden Sie einen `PostToolUse`-Hook, um Tool-Nutzung zu protokollieren und Kosten pro Sitzung zu schätzen.
|
|
133
|
+
|
|
134
|
+
Siehe `hooks/lifecycle/cost-tracker.sh` für eine fertige Implementierung.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Schnellreferenz
|
|
139
|
+
|
|
140
|
+
| Situation | Aktion |
|
|
141
|
+
|---|---|
|
|
142
|
+
| Einfache Einzeldatei-Bearbeitung | Zu Haiku 4.5 wechseln |
|
|
143
|
+
| Lange Sitzung wird langsam | Manuell komprimieren (`/compact`) |
|
|
144
|
+
| Neue große Aufgabe beginnen | Zuerst komprimieren, dann beginnen |
|
|
145
|
+
| Arbeit in einem Bereich, den Sie nicht anfassen werden | Domain-MCPs deaktivieren |
|
|
146
|
+
| Aufgabe ist in sich abgeschlossen | Sub-Agent verwenden |
|
|
147
|
+
| Vage Anfrage produziert lange Antworten | Als spezifischen, abgegrenzten Prompt neu schreiben |
|
|
148
|
+
| CLAUDE.md über 500 Zeilen | Auditieren und veraltete Regeln entfernen |
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Arbeiten Sie mit uns
|
|
153
|
+
|
|
154
|
+
Claudient wird unterstützt von [Uitbreiden](https://uitbreiden.com/) — wir entwickeln KI-Produkte mit Entwickler-Communities und liefern B2B-KI-Lösungen. Wenn Sie KI-Kosten in großem Maßstab reduzieren, Claude Code-Tooling für Ihr Team aufbauen oder B2B-KI-Produkte liefern möchten — lassen Sie uns sprechen.
|
|
155
|
+
|
|
156
|
+
**[uitbreiden.com](https://uitbreiden.com/)**
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Guía de orquestación de agentes
|
|
2
|
+
|
|
3
|
+
Cómo delegar, paralelizar y especializar trabajo usando el sistema de sub-agentes de Claude Code.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Qué son los sub-agentes
|
|
8
|
+
|
|
9
|
+
Un sub-agente es una instancia Claude separada iniciada por la sesión padre para manejar una tarea específica y acotada. Obtiene:
|
|
10
|
+
- Una ventana de contexto fresca (sin historial de sesión)
|
|
11
|
+
- Un subconjunto específico de herramientas (si está configurado)
|
|
12
|
+
- Una selección de modelo (puede diferir del padre)
|
|
13
|
+
- Un prompt que escribes explícitamente
|
|
14
|
+
|
|
15
|
+
Los sub-agentes no son magia — son una herramienta específica para problemas específicos.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Cuándo usar un sub-agente
|
|
20
|
+
|
|
21
|
+
Usa un sub-agente cuando la tarea tiene **entradas claras** y **salidas claras** y es **independiente del estado de sesión actual**.
|
|
22
|
+
|
|
23
|
+
**Buenos candidatos:**
|
|
24
|
+
- Revisar 10 archivos en busca de problemas de seguridad
|
|
25
|
+
- Ejecutar una búsqueda específica en el código para localizar un patrón
|
|
26
|
+
- Generar boilerplate para un nuevo módulo dado un spec
|
|
27
|
+
- Analizar un archivo de log y devolver un resumen
|
|
28
|
+
|
|
29
|
+
**Malos candidatos:**
|
|
30
|
+
- Tareas que requieren el contexto completo de la sesión
|
|
31
|
+
- Tareas que requieren ida y vuelta — los sub-agentes son de una sola pasada
|
|
32
|
+
- Tareas donde el overhead de lanzamiento supera el trabajo
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 1. Patrón de delegación
|
|
37
|
+
|
|
38
|
+
La sesión padre identifica una tarea acotada y la entrega.
|
|
39
|
+
|
|
40
|
+
**Regla clave:** El prompt del sub-agente debe ser autónomo. No tiene acceso a lo que la sesión padre ha estado haciendo. Briéfalo como un colega que acaba de entrar a la sala.
|
|
41
|
+
|
|
42
|
+
**Qué incluir en el prompt del sub-agente:**
|
|
43
|
+
- Qué estás intentando lograr y por qué
|
|
44
|
+
- Los archivos o directorios específicos
|
|
45
|
+
- El formato de resultado deseado
|
|
46
|
+
- Decisiones ya tomadas
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 2. Patrón de paralelización
|
|
51
|
+
|
|
52
|
+
Múltiples sub-agentes ejecutándose simultáneamente en tareas independientes.
|
|
53
|
+
|
|
54
|
+
**Cuándo paralelizar:**
|
|
55
|
+
- La misma operación debe aplicarse a muchos archivos/módulos
|
|
56
|
+
- Dos tareas genuinamente independientes deben completarse ambas
|
|
57
|
+
- Tareas de investigación que cubren diferentes áreas
|
|
58
|
+
|
|
59
|
+
**Usando git worktrees para cambios de código paralelos:**
|
|
60
|
+
```bash
|
|
61
|
+
git worktree add ../feature-branch-a feature-a
|
|
62
|
+
git worktree add ../feature-branch-b feature-b
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Anti-patrones de paralelización:**
|
|
66
|
+
- Paralelizar tareas que comparten estado (conflictos de escritura)
|
|
67
|
+
- Tareas paralelas donde una depende de la salida de la otra
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 3. Patrón de especialización (cavecrew)
|
|
72
|
+
|
|
73
|
+
Adapta el modelo y las herramientas del sub-agente a la naturaleza de la tarea. Inspirado en el patrón **cavecrew** (fuente: [JuliusBrussee/caveman](https://github.com/JuliusBrussee/caveman)) — ahorra ~60% de tokens comparado con usar Opus para cada sub-agente.
|
|
74
|
+
|
|
75
|
+
| Rol | Modelo | Herramientas | Usar cuando |
|
|
76
|
+
|---|---|---|---|
|
|
77
|
+
| Investigador | Haiku 4.5 | Read, Bash (solo grep/find) | Localizar cosas en el código — solo lectura, rápido |
|
|
78
|
+
| Constructor | Sonnet 4.6 | Read, Edit, Write, Bash | Cambios quirúrgicos de 1–2 archivos |
|
|
79
|
+
| Revisor | Haiku 4.5 | Read | Revisar un diff o conjunto de archivos |
|
|
80
|
+
| Orquestador | Opus 4.7 | Todos | Coordinación compleja multi-paso, decisiones de arquitectura |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 4. Patrón de traspaso de contexto
|
|
85
|
+
|
|
86
|
+
Cuando una sesión ha acumulado contexto significativo y necesitas traspasar el trabajo a un nuevo agente.
|
|
87
|
+
|
|
88
|
+
**Estructura del prompt de traspaso:**
|
|
89
|
+
```
|
|
90
|
+
## Context
|
|
91
|
+
[Qué hace este proyecto, brevemente]
|
|
92
|
+
[En qué estábamos trabajando]
|
|
93
|
+
[Decisiones tomadas durante esta sesión]
|
|
94
|
+
|
|
95
|
+
## Files modified
|
|
96
|
+
[Lista con breve razón para cada cambio]
|
|
97
|
+
|
|
98
|
+
## Current state
|
|
99
|
+
[Qué está hecho, qué no, qué bloquea]
|
|
100
|
+
|
|
101
|
+
## Your task
|
|
102
|
+
[Tarea específica y acotada para el nuevo agente]
|
|
103
|
+
|
|
104
|
+
## Constraints
|
|
105
|
+
[Decisiones tomadas que no deben revisarse]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 5. Dependencias duras vs. suaves
|
|
111
|
+
|
|
112
|
+
**Dependencia dura:** La tarea aguas abajo falla explícitamente sin la configuración aguas arriba.
|
|
113
|
+
- Señálalo explícitamente: "Esta skill requiere configuración — ejecuta `/setup` primero."
|
|
114
|
+
|
|
115
|
+
**Dependencia suave:** La tarea funciona pero produce salida de menor calidad sin configuración.
|
|
116
|
+
- No detener. Degradar graciosamente y anotar la brecha.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 6. Control de alcance para sub-agentes
|
|
121
|
+
|
|
122
|
+
Cada sub-agente debe tener un límite de alcance explícito.
|
|
123
|
+
|
|
124
|
+
**Incluir en cada prompt de sub-agente:**
|
|
125
|
+
```
|
|
126
|
+
## Scope
|
|
127
|
+
- Read: yes
|
|
128
|
+
- Write/Edit: [solo archivos específicos O no]
|
|
129
|
+
- Shell commands: [comandos específicos permitidos O ninguno]
|
|
130
|
+
- Network: [sí/no]
|
|
131
|
+
|
|
132
|
+
## Do not
|
|
133
|
+
- Do not modify files outside [directory]
|
|
134
|
+
- Do not make git commits
|
|
135
|
+
- Do not install packages
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 7. Devolver resultados de sub-agentes
|
|
141
|
+
|
|
142
|
+
**Preferir archivos para:**
|
|
143
|
+
- Listas de hallazgos sobre las que el padre iterará
|
|
144
|
+
- Código generado que el padre revisará
|
|
145
|
+
- Informes referenciados múltiples veces
|
|
146
|
+
|
|
147
|
+
**Preferir mensajes de retorno para:**
|
|
148
|
+
- Respuestas simples sí/no
|
|
149
|
+
- Datos estructurados cortos
|
|
150
|
+
- Informes de estado
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Referencia rápida
|
|
155
|
+
|
|
156
|
+
| Objetivo | Patrón |
|
|
157
|
+
|---|---|
|
|
158
|
+
| Tarea acotada y autónoma | Delegación |
|
|
159
|
+
| Misma tarea en muchos archivos | Paralelización |
|
|
160
|
+
| Búsqueda/localización solo lectura | Investigador (Haiku) |
|
|
161
|
+
| Cambio de código quirúrgico | Constructor (Sonnet) |
|
|
162
|
+
| Revisión de diff/archivo | Revisor (Haiku) |
|
|
163
|
+
| Coordinación compleja multi-paso | Orquestador (Opus) |
|
|
164
|
+
| Traspaso de sesión | Patrón de traspaso de contexto |
|
|
165
|
+
| Salida grande de sub-agente | Escribir a archivo, padre lo lee |
|
|
166
|
+
| Resultado estructurado corto | Mensaje de retorno |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Trabaja con nosotros
|
|
171
|
+
|
|
172
|
+
Claudient está respaldado por [Uitbreiden](https://uitbreiden.com/) — construimos productos de IA con comunidades de desarrolladores y entregamos soluciones de IA B2B. Si estás diseñando sistemas multi-agente, workflows autónomos u orquestación de Claude Code de grado producción — lo hemos construido en producción y podemos ayudarte.
|
|
173
|
+
|
|
174
|
+
**[uitbreiden.com](https://uitbreiden.com/)**
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Primeros pasos con Claudient
|
|
2
|
+
|
|
3
|
+
Esta guía te lleva de cero a un entorno Claude Code funcional con tu primera skill, agente y hook — en menos de 10 minutos.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Requisitos previos
|
|
8
|
+
|
|
9
|
+
- [Claude Code](https://claude.ai/code) instalado y autenticado
|
|
10
|
+
- Un directorio de proyecto en el que estés trabajando activamente
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Paso 1 — Clonar Claudient
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/Claudient/Claudient.git ~/Claudient
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Ahora tienes la biblioteca completa localmente. Nada se ejecuta automáticamente — tú eliges lo que necesitas.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Paso 2 — Configurar el directorio `.claude/` de tu proyecto
|
|
25
|
+
|
|
26
|
+
Claude Code busca la configuración en `.claude/` en la raíz de tu proyecto.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
mkdir -p your-project/.claude/skills
|
|
30
|
+
mkdir -p your-project/.claude/hooks
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
La estructura de tu proyecto debería verse así:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
your-project/
|
|
37
|
+
├── .claude/
|
|
38
|
+
│ ├── skills/ ← las skills van aquí (estándar actual)
|
|
39
|
+
│ ├── hooks/ ← los scripts de hooks van aquí
|
|
40
|
+
│ └── settings.json ← la configuración de hooks va aquí
|
|
41
|
+
├── CLAUDE.md ← las reglas van aquí
|
|
42
|
+
└── src/
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Paso 3 — Añadir tu primera skill
|
|
48
|
+
|
|
49
|
+
Las skills son comandos slash. Copia cualquier archivo `.md` de `skills/` a `.claude/skills/`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Ejemplo: añadir la skill de FastAPI
|
|
53
|
+
cp ~/Claudient/skills/backend/python/fastapi.md your-project/.claude/skills/
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Ahora abre Claude Code en tu proyecto y escribe `/fastapi` — la skill se activa.
|
|
57
|
+
|
|
58
|
+
> **Nota:** `.claude/commands/` sigue funcionando (ruta heredada) pero `.claude/skills/` es el estándar actual. Cuando ambos existen, las skills tienen prioridad.
|
|
59
|
+
|
|
60
|
+
**Cómo elegir una skill:**
|
|
61
|
+
- Navega por `skills/` por categoría
|
|
62
|
+
- Lee la sección "When to activate" al inicio de cada archivo
|
|
63
|
+
- Si coincide con tu tarea actual, cópiala
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Paso 4 — Añadir una regla
|
|
68
|
+
|
|
69
|
+
Las reglas viven en `CLAUDE.md` en la raíz de tu proyecto. Claude lee este archivo al inicio de cada sesión.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Copiar un conjunto de reglas comunes al CLAUDE.md de tu proyecto
|
|
73
|
+
cat ~/Claudient/rules/common/coding-style.md >> your-project/CLAUDE.md
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
O abre `rules/common/` y copia manualmente las secciones relevantes para tu proyecto.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Paso 5 — Añadir tu primer hook
|
|
81
|
+
|
|
82
|
+
Los hooks se ejecutan automáticamente en los eventos de Claude Code. Viven en `.claude/settings.json`.
|
|
83
|
+
|
|
84
|
+
Crea o abre `.claude/settings.json` en tu proyecto:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"hooks": {}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Copia un hook de `hooks/` — cada archivo de hook incluye el JSON exacto a pegar. Por ejemplo, el hook de seguimiento de costes:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"hooks": {
|
|
97
|
+
"PostToolUse": [
|
|
98
|
+
{
|
|
99
|
+
"matcher": "",
|
|
100
|
+
"hooks": [
|
|
101
|
+
{
|
|
102
|
+
"type": "command",
|
|
103
|
+
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/cost-tracker.sh"
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Luego copia el script correspondiente:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cp ~/Claudient/hooks/lifecycle/cost-tracker.sh your-project/.claude/hooks/
|
|
116
|
+
chmod +x your-project/.claude/hooks/cost-tracker.sh
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Paso 6 — (Opcional) Añadir un agente
|
|
122
|
+
|
|
123
|
+
Los agentes son definiciones de sub-agentes que referencias en tus sesiones de Claude. No requieren copiar archivos — los llamas por `subagent_type` en una invocación de la herramienta Agent.
|
|
124
|
+
|
|
125
|
+
Navega por `agents/` para entender qué está disponible. Cuando quieras que Claude delegue una tarea a un especialista (por ejemplo, un revisor de seguridad, un especialista en bases de datos), referencia la definición del agente para entender qué espera y qué devuelve.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Qué hacer a continuación
|
|
130
|
+
|
|
131
|
+
| Objetivo | Dónde buscar |
|
|
132
|
+
|---|---|
|
|
133
|
+
| Escribir tu propia skill | [guides/skill-authoring.md](skill-authoring.md) |
|
|
134
|
+
| Reducir costes de tokens | [guides/token-optimization.md](token-optimization.md) |
|
|
135
|
+
| Entender la memoria y el estado de sesión | [guides/memory-management.md](memory-management.md) |
|
|
136
|
+
| Asegurar tu configuración de Claude Code | [guides/security.md](security.md) |
|
|
137
|
+
| Construir workflows automatizados multi-paso | [guides/agent-orchestration.md](agent-orchestration.md) |
|
|
138
|
+
| Automatizar la calidad con hooks | [guides/hooks-cookbook.md](hooks-cookbook.md) |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Solución de problemas
|
|
143
|
+
|
|
144
|
+
**La skill no aparece como comando slash**
|
|
145
|
+
— Comprueba que el archivo está en `.claude/skills/` (o `.claude/commands/` para la ruta heredada)
|
|
146
|
+
— Comprueba que la extensión del archivo es `.md`
|
|
147
|
+
— Reinicia Claude Code
|
|
148
|
+
|
|
149
|
+
**El hook no se activa**
|
|
150
|
+
— Verifica que el nombre del evento coincide exactamente: `PreToolUse`, `PostToolUse`, `PreCompact`, `Notification`
|
|
151
|
+
— Comprueba que la ruta del script es relativa a la raíz del proyecto
|
|
152
|
+
— Comprueba que el script es ejecutable (`chmod +x`)
|
|
153
|
+
|
|
154
|
+
**CLAUDE.md no se lee**
|
|
155
|
+
— Debe estar en la raíz del proyecto (al mismo nivel que `src/`, `package.json`, etc.)
|
|
156
|
+
— Reinicia la sesión de Claude Code después de editarlo
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Trabaja con nosotros
|
|
161
|
+
|
|
162
|
+
Claudient está respaldado por [Uitbreiden](https://uitbreiden.com/) — construimos productos de IA con comunidades de desarrolladores y entregamos soluciones de IA B2B. Si estás construyendo algo serio con Claude Code y quieres ayuda experta, un socio técnico, o simplemente formar parte de la comunidad — ven a buscarnos.
|
|
163
|
+
|
|
164
|
+
**[uitbreiden.com](https://uitbreiden.com/)**
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Libro de recetas de hooks
|
|
2
|
+
|
|
3
|
+
Patrones de hooks reales y listos para usar para automatizar calidad, seguridad y observabilidad en Claude Code.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Fundamentos de hooks
|
|
8
|
+
|
|
9
|
+
Los hooks son scripts shell o comandos que Claude Code ejecuta automáticamente en respuesta a eventos. Se ejecutan fuera del contexto de Claude — son procesos shell reales, no instrucciones de Claude.
|
|
10
|
+
|
|
11
|
+
**Eventos de hook:**
|
|
12
|
+
| Evento | Cuándo se activa |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `SessionStart` | Cuando una sesión de Claude Code comienza |
|
|
15
|
+
| `PreToolUse` | Antes de que se ejecute cualquier llamada a herramienta |
|
|
16
|
+
| `PostToolUse` | Después de que se completa una llamada a herramienta |
|
|
17
|
+
| `PreCompact` | Antes de que se active la compactación de contexto |
|
|
18
|
+
| `PostCompact` | Después de la compactación de contexto |
|
|
19
|
+
| `Stop` | Cuando Claude termina de responder |
|
|
20
|
+
| `Notification` | Cuando Claude envía una notificación de escritorio |
|
|
21
|
+
|
|
22
|
+
**Códigos de salida:** `0` = permitir, `1` = advertir (Claude ve la salida pero continúa), `2` = bloquear (la llamada a herramienta se cancela).
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Receta 1 — Auto-formateo Prettier al escribir
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"hooks": {
|
|
31
|
+
"PostToolUse": [
|
|
32
|
+
{
|
|
33
|
+
"matcher": "Write|Edit",
|
|
34
|
+
"hooks": [{ "type": "command", "command": "npx prettier --write ${tool_input.file_path}", "async": true }]
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Receta 2 — Bloquear comandos shell peligrosos
|
|
44
|
+
|
|
45
|
+
**.claude/hooks/block-dangerous.sh:**
|
|
46
|
+
```bash
|
|
47
|
+
#!/usr/bin/env bash
|
|
48
|
+
INPUT=$(cat)
|
|
49
|
+
COMMAND=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('command',''))")
|
|
50
|
+
BLOCKED_PATTERNS=("rm -rf" "sudo " "| bash" "| sh" "git push --force" "git reset --hard")
|
|
51
|
+
for pattern in "${BLOCKED_PATTERNS[@]}"; do
|
|
52
|
+
if echo "$COMMAND" | grep -qi "$pattern"; then
|
|
53
|
+
echo "BLOQUEADO: el comando coincide con el patrón peligroso '$pattern'" >&2
|
|
54
|
+
exit 2
|
|
55
|
+
fi
|
|
56
|
+
done
|
|
57
|
+
exit 0
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Receta 3 — Registro de auditoría para cada llamada a herramienta
|
|
63
|
+
|
|
64
|
+
**.claude/hooks/audit-log.sh:**
|
|
65
|
+
```bash
|
|
66
|
+
#!/usr/bin/env bash
|
|
67
|
+
INPUT=$(cat)
|
|
68
|
+
TOOL_NAME=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_name','unknown'))" 2>/dev/null)
|
|
69
|
+
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
70
|
+
LOG_FILE="${CLAUDE_PROJECT_DIR}/.claude/logs/audit.log"
|
|
71
|
+
mkdir -p "$(dirname "$LOG_FILE")"
|
|
72
|
+
echo "${TIMESTAMP} | ${TOOL_NAME}" >> "$LOG_FILE"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Receta 4 — Guardado de sesión antes de la compactación
|
|
78
|
+
|
|
79
|
+
Combina con una instrucción CLAUDE.md: "Cuando PreCompact se active, resume: tarea actual, archivos modificados, decisiones abiertas, próximos pasos — añade a `.claude/memory/session-state.md`."
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Receta 5 — Rastreador de costes
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"hooks": {
|
|
88
|
+
"PostToolUse": [
|
|
89
|
+
{ "matcher": "", "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/cost-tracker.sh", "async": true }] }
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Receta 6 — Verificación de tipos TypeScript al editar
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"hooks": {
|
|
102
|
+
"PostToolUse": [
|
|
103
|
+
{
|
|
104
|
+
"matcher": "Write|Edit",
|
|
105
|
+
"hooks": [{ "type": "command", "command": "bash -c 'echo \"${tool_input.file_path}\" | grep -q \"\\.tsx\\?$\" && npx tsc --noEmit 2>&1 | head -20 || true'", "async": false, "timeout": 30 }]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Receta 7 — Recordatorio de git push
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
#!/usr/bin/env bash
|
|
118
|
+
INPUT=$(cat)
|
|
119
|
+
COMMAND=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('command',''))" 2>/dev/null)
|
|
120
|
+
if echo "$COMMAND" | grep -q "git push"; then
|
|
121
|
+
echo "⚠️ A punto de hacer push al remoto. Confirma que esto es intencional." >&2
|
|
122
|
+
exit 1
|
|
123
|
+
fi
|
|
124
|
+
exit 0
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Receta 8 — Cargador de contexto al inicio de sesión
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"hooks": {
|
|
134
|
+
"SessionStart": [
|
|
135
|
+
{ "matcher": "", "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/session-start.sh" }] }
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Solución de problemas con hooks
|
|
144
|
+
|
|
145
|
+
**El hook no se activa:**
|
|
146
|
+
- Verifica que el nombre del evento sea exacto: `PreToolUse`, `PostToolUse`, `SessionStart`, `PreCompact`
|
|
147
|
+
- Verifica que el script sea ejecutable: `chmod +x .claude/hooks/tu-script.sh`
|
|
148
|
+
|
|
149
|
+
**Probar un hook manualmente:**
|
|
150
|
+
```bash
|
|
151
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | bash .claude/hooks/tu-script.sh
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Trabaja con nosotros
|
|
157
|
+
|
|
158
|
+
Claudient está respaldado por [Uitbreiden](https://uitbreiden.com/) — construimos productos de IA con comunidades de desarrolladores y entregamos soluciones de IA B2B. Si necesitas sistemas de hooks personalizados, puertas de calidad automatizadas o automatización de Claude Code de grado producción para tu equipo — lo construimos para clientes.
|
|
159
|
+
|
|
160
|
+
**[uitbreiden.com](https://uitbreiden.com/)**
|