{
 "id": 2252,
 "status": "publish",
 "lang": "es",
 "slug": "claude-code-headless-haiku-guard",
 "url": "https://soymarketingultra.com/claude-code-headless-haiku-guard/",
 "title": "Claude Code Headless: el Haiku Fantasma que Rompe Tu Guard",
 "excerpt": "Claude Code usa Haiku internamente para tareas auxiliares y tu guard de modelo no lo distingue del trabajo real. Tres heurísticas rotas y el fix que funciona.",
 "date_gmt": "2026-06-25T07:34:24Z",
 "modified_gmt": "2026-07-09T20:22:13Z",
 "categories": [
  {
   "slug": "seo-es",
   "name": "SEO",
   "url": "https://soymarketingultra.com/category/seo-es/"
  }
 ],
 "tags": [
  {
   "slug": "anthropic",
   "name": "Anthropic"
  },
  {
   "slug": "automatizacion-ia",
   "name": "automatización IA"
  },
  {
   "slug": "claude-code",
   "name": "claude-code"
  },
  {
   "slug": "inteligencia-artificial-es",
   "name": "Inteligencia artificial"
  }
 ],
 "featured_image": {
  "url": "https://soymarketingultra.com/wp-content/uploads/cabecera-2252.png",
  "alt": "Cabecera del artículo: Claude Code Headless: el Haiku Fantasma que Rompe Tu Guard",
  "width": 1200,
  "height": 675
 },
 "translation": {
  "lang": "en",
  "url": "https://soymarketingultra.com/en/claude-code-headless-model-detection/",
  "id": 2254
 },
 "seo": {
  "title": "Claude Code Headless: el Haiku Fantasma que Rompe Tu Guard",
  "description": "Claude Code headless ejecuta llamadas internas a Haiku que contaminan .modelUsage. Tres heurísticas rotas y el fix para detectar qué modelo trabajó de verdad.",
  "focus_keyword": "claude code headless"
 },
 "html": "<p>Montas un guardia de seguridad para tu pipeline de IA. La orden es clara: si un modelo barato genera el contenido, páralo antes de que se publique. Y el guardia cumple. Varias veces a lo largo de dos semanas, tira a la basura trabajo perfecto de tu modelo caro. ¿El motivo? Claude Code usa Haiku internamente para ponerle nombre a la sesión, y tu guardia no sabe distinguir esa llamada interna del trabajo real.</p>\n\n<p>El asesino llamando a la policía. Bienvenido a operar LLMs en producción.</p>\n\n<div class=\"mu-tldr\">\n  <div class=\"mu-tldr__header\">\n    <img src=\"https://soymarketingultra.com/wp-content/themes/astra-child/assets/brand/despiram-sorprendido.png\" alt=\"Mascota Marketing Ultra\" class=\"mu-tldr__mascot\" />\n    <p class=\"mu-tldr__title\">TL;DR: El resumen sin rodeos</p>\n  </div>\n  <div class=\"mu-tldr__body\">\n    <ul>\n      <li><strong>Haiku fantasma</strong>: Claude Code ejecuta llamadas internas a Haiku (nombrar sesión, routing) que aparecen en <code>.modelUsage</code> junto a tu trabajo real. Tu guard las confunde con el modelo que hizo el curro.</li>\n      <li><strong>Tres heurísticas, tres fracasos</strong>: primer modelo alfabético, el de más tokens y match exacto de ID fallan por la misma causa: mezcla de modelos internos con trabajo real.</li>\n      <li><strong>El flag <code>--model</code> no funciona</strong>: en <code>claude -p</code> headless solo vale la env <code>ANTHROPIC_MODEL</code>. Sin fijarla, el default puede estar obsoleto o degradar a Haiku en silencio.</li>\n      <li><strong>Fix robusto</strong>: excluir Haiku de <code>.modelUsage</code>, coger el de más tokens del resto. Solo si todo es Haiku, degradación real.</li>\n    </ul>\n    <div class=\"mu-tldr__verdict\"><svg class=\"mu-tldr__gavel\" aria-hidden=\"true\" viewBox=\"0 0 26 18\" width=\"40\" height=\"28\" shape-rendering=\"crispEdges\" style=\"image-rendering:pixelated\"><rect x=\"6\" y=\"0\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"7\" y=\"0\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"8\" y=\"0\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"5\" y=\"1\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"6\" y=\"1\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"7\" y=\"1\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"8\" y=\"1\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"9\" y=\"1\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"1\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"5\" y=\"2\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"6\" y=\"2\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"7\" y=\"2\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"8\" y=\"2\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"9\" y=\"2\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"2\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"11\" y=\"2\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"12\" y=\"2\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"5\" y=\"3\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"6\" y=\"3\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"7\" y=\"3\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"8\" y=\"3\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"9\" y=\"3\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"3\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"11\" y=\"3\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"12\" y=\"3\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"13\" y=\"3\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"5\" y=\"4\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"6\" y=\"4\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"7\" y=\"4\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"8\" y=\"4\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"9\" y=\"4\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"10\" y=\"4\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"11\" y=\"4\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"12\" y=\"4\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"13\" y=\"4\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"4\" y=\"5\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"5\" y=\"5\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"6\" y=\"5\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"7\" y=\"5\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"8\" y=\"5\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"9\" y=\"5\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"10\" y=\"5\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"11\" y=\"5\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"12\" y=\"5\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"4\" y=\"6\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"5\" y=\"6\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"6\" y=\"6\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"7\" y=\"6\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"8\" y=\"6\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"9\" y=\"6\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"6\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"11\" y=\"6\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"2\" y=\"7\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"3\" y=\"7\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"4\" y=\"7\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"5\" y=\"7\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"6\" y=\"7\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"7\" y=\"7\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"8\" y=\"7\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"9\" y=\"7\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"7\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"11\" y=\"7\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"2\" y=\"8\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"3\" y=\"8\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"4\" y=\"8\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"5\" y=\"8\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"6\" y=\"8\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"7\" y=\"8\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"8\" y=\"8\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"9\" y=\"8\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"8\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"11\" y=\"8\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"12\" y=\"8\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"13\" y=\"8\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"17\" y=\"8\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"18\" y=\"8\" width=\"1\" height=\"1\" fill=\"#b87575\"/><rect x=\"19\" y=\"8\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"20\" y=\"8\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"21\" y=\"8\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"22\" y=\"8\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"23\" y=\"8\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"1\" y=\"9\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"2\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"3\" y=\"9\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"4\" y=\"9\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"5\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"6\" y=\"9\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"7\" y=\"9\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"8\" y=\"9\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"9\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"10\" y=\"9\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"11\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"12\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"13\" y=\"9\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"14\" y=\"9\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"15\" y=\"9\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"16\" y=\"9\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"17\" y=\"9\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"18\" y=\"9\" width=\"1\" height=\"1\" fill=\"#fcc378\"/><rect x=\"19\" y=\"9\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"20\" y=\"9\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"21\" y=\"9\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"22\" y=\"9\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"23\" y=\"9\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"24\" y=\"9\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"1\" y=\"10\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"2\" y=\"10\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"3\" y=\"10\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"4\" y=\"10\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"5\" y=\"10\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"6\" y=\"10\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"7\" y=\"10\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"8\" y=\"10\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"9\" y=\"10\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"11\" y=\"10\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"12\" y=\"10\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"13\" y=\"10\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"14\" y=\"10\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"15\" y=\"10\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"16\" y=\"10\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"17\" y=\"10\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"18\" y=\"10\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"19\" y=\"10\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"20\" y=\"10\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"21\" y=\"10\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"22\" y=\"10\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"23\" y=\"10\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"24\" y=\"10\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"25\" y=\"10\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"2\" y=\"11\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"3\" y=\"11\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"4\" y=\"11\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"5\" y=\"11\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"6\" y=\"11\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"7\" y=\"11\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"8\" y=\"11\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"13\" y=\"11\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"14\" y=\"11\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"15\" y=\"11\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"16\" y=\"11\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"17\" y=\"11\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"18\" y=\"11\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"19\" y=\"11\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"20\" y=\"11\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"21\" y=\"11\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"22\" y=\"11\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"23\" y=\"11\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"24\" y=\"11\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"25\" y=\"11\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"0\" y=\"12\" width=\"1\" height=\"1\" fill=\"#fd5d5b\"/><rect x=\"1\" y=\"12\" width=\"1\" height=\"1\" fill=\"#fcc378\"/><rect x=\"2\" y=\"12\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"5\" y=\"12\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"6\" y=\"12\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"7\" y=\"12\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"8\" y=\"12\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"14\" y=\"12\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"15\" y=\"12\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"16\" y=\"12\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"17\" y=\"12\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"18\" y=\"12\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"19\" y=\"12\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"20\" y=\"12\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"21\" y=\"12\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"22\" y=\"12\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"23\" y=\"12\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"24\" y=\"12\" width=\"1\" height=\"1\" fill=\"#c09068\"/><rect x=\"25\" y=\"12\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"0\" y=\"13\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"1\" y=\"13\" width=\"1\" height=\"1\" fill=\"#fcc378\"/><rect x=\"2\" y=\"13\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"3\" y=\"13\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"4\" y=\"13\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"14\" y=\"13\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"15\" y=\"13\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"16\" y=\"13\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"17\" y=\"13\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"18\" y=\"13\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"19\" y=\"13\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"20\" y=\"13\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"21\" y=\"13\" width=\"1\" height=\"1\" fill=\"#873235\"/><rect x=\"22\" y=\"13\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"23\" y=\"13\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"24\" y=\"13\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"25\" y=\"13\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"1\" y=\"14\" width=\"1\" height=\"1\" fill=\"#fd5d5b\"/><rect x=\"2\" y=\"14\" width=\"1\" height=\"1\" fill=\"#fd5d5b\"/><rect x=\"3\" y=\"14\" width=\"1\" height=\"1\" fill=\"#fd5d5b\"/><rect x=\"4\" y=\"14\" width=\"1\" height=\"1\" fill=\"#fcc378\"/><rect x=\"5\" y=\"14\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"6\" y=\"14\" width=\"1\" height=\"1\" fill=\"#ffee94\"/><rect x=\"7\" y=\"14\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"15\" y=\"14\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"16\" y=\"14\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"17\" y=\"14\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"18\" y=\"14\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"19\" y=\"14\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"20\" y=\"14\" width=\"1\" height=\"1\" fill=\"#b87575\"/><rect x=\"21\" y=\"14\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"22\" y=\"14\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"23\" y=\"14\" width=\"1\" height=\"1\" fill=\"#0a0000\"/><rect x=\"24\" y=\"14\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"25\" y=\"14\" width=\"1\" height=\"1\" fill=\"#8a7060\"/><rect x=\"1\" y=\"15\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"4\" y=\"15\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"5\" y=\"15\" width=\"1\" height=\"1\" fill=\"#fcc378\"/><rect x=\"6\" y=\"15\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"7\" y=\"15\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"8\" y=\"15\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"16\" y=\"15\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"17\" y=\"15\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"18\" y=\"15\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"19\" y=\"15\" width=\"1\" height=\"1\" fill=\"#c09068\"/><rect x=\"20\" y=\"15\" width=\"1\" height=\"1\" fill=\"#b87575\"/><rect x=\"21\" y=\"15\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"22\" y=\"15\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"23\" y=\"15\" width=\"1\" height=\"1\" fill=\"#aa6666\"/><rect x=\"24\" y=\"15\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"25\" y=\"15\" width=\"1\" height=\"1\" fill=\"#ffe2e2\"/><rect x=\"5\" y=\"16\" width=\"1\" height=\"1\" fill=\"#e5a97c\"/><rect x=\"6\" y=\"16\" width=\"1\" height=\"1\" fill=\"#ffe2e2\"/><rect x=\"7\" y=\"16\" width=\"1\" height=\"1\" fill=\"#ffe2e2\"/><rect x=\"8\" y=\"16\" width=\"1\" height=\"1\" fill=\"#ffdab0\"/><rect x=\"17\" y=\"16\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"18\" y=\"16\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"19\" y=\"16\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"20\" y=\"16\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"21\" y=\"16\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"22\" y=\"16\" width=\"1\" height=\"1\" fill=\"#6b4535\"/><rect x=\"23\" y=\"16\" width=\"1\" height=\"1\" fill=\"#696969\"/><rect x=\"19\" y=\"17\" width=\"1\" height=\"1\" fill=\"#b87575\"/><rect x=\"20\" y=\"17\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"21\" y=\"17\" width=\"1\" height=\"1\" fill=\"#3a1510\"/><rect x=\"22\" y=\"17\" width=\"1\" height=\"1\" fill=\"#696969\"/></svg>\n      \n      Veredicto: si operas LLMs en pipeline, no te fíes del log. Abre el transcript y verifica qué modelo trabajó de verdad.\n    </div>\n  </div>\n</div>\n\n<h2>¿Qué hace Claude Code con Haiku cuando tú no miras?</h2>\n\n<p>Claude Code en modo headless (<a href=\"https://github.com/anthropics/claude-code\" target=\"_blank\" rel=\"noopener\"><code>claude -p</code></a>) mezcla modelos internos con el modelo solicitado en la misma sesión: ejecuta llamadas a Haiku para tareas auxiliares (nombrar la sesión, routing) que tú ni pediste ni necesitas. Esos turnos aparecen en el campo <code>.modelUsage</code> y en el transcript JUNTO a tu trabajo real, sin nada que los distinga.</p>\n\n<p>¿Y sabéis qué significa eso? Que cualquier lógica que mire qué modelo respondió sin filtrar esas llamadas internas se va a equivocar. No a veces. SIEMPRE.</p>\n\n<p>Hay más. En <code>claude -p</code>, el flag <code>--model</code> se ignora. Solo funciona la variable de entorno <code>ANTHROPIC_MODEL</code>. Si no la fijas explícitamente, el CLI coge un default que puede estar obsoleto. Y si tu plan Max está cerca del límite de uso, <a href=\"https://docs.anthropic.com/en/docs/claude-code\" target=\"_blank\" rel=\"noopener\">Claude Code</a> degrada a Haiku en silencio. Sin warning. Sin error. <code>is_error: false</code>.</p>\n\n<p>En Marketing Ultra descubrimos esto el 14 de junio depurando nuestro <a href=\"https://soymarketingultra.com/pipeline-contenido-ia-editor-jefe/\">pipeline de contenido con IA</a>. Lo que vino después fue peor.</p>\n\n<h2>Tres heurísticas rotas, tres formas de morder</h2>\n<figure class=\"wp-block-image size-full mu-diagram\"><img src=\"https://soymarketingultra.com/wp-content/uploads/claude-code-headless-el-haiku-fantasma-que-rompe-tu-gua-diagrama.webp\" alt=\"Diagrama de flujo vertical: leer modelUsage, excluir llamadas Haiku, comprobar si quedan otros modelos; si sí, elegir el de mayor outputTokens como modelo real; si solo hay Haiku, marcar degradación real.\" class=\"wp-image-2258\"/></figure>\n\n<p>Probamos tres métodos para detectar qué modelo había respondido de verdad. Los tres nos mordieron.</p>\n\n<p><strong><code>keys[0]</code>: primer modelo en orden alfabético.</strong> \"Haiku\" va antes que \"Opus\" en el abecedario. Nuestro heartbeat usaba este método. Resultado: reportó Haiku 24/7 durante ~14 días. Todo el histórico de modelo en los logs, contaminado. Catorce días de datos falsos que tardamos en detectar porque el pipeline funcionaba bien. Solo el registro era mentira.</p>\n\n<p><strong><code>sort_by(-outputTokens)[0]</code>: el modelo con más tokens de salida.</strong> Parece el método inteligente, ¿verdad? El que más genera es el que hizo el curro. Hasta que Opus te devuelve una respuesta corta y el título generado por Haiku tiene más tokens que la respuesta real. El log dice Haiku. El trabajo es Opus.</p>\n\n<p><strong>Exact key match contra un ID conocido.</strong> Los IDs de modelo llevan fecha embebida: <code>claude-opus-4-6-20250401</code>. Nuestro guard comparaba contra <code>claude-opus-4-6</code> a secas. No coincidía. Exit 75: \"modelo degradado\". Trabajo perfecto de Opus desechado. Varias veces.</p>\n\n<p>Tres heurísticas \"obvias\". Tres formas de morder. Todas por el mismo fallo de fondo: asumir que <code>.modelUsage</code> refleja solo TU trabajo.</p>\n\n<h2>El misdiagnóstico que nos costó 697 segundos de Opus</h2>\n\n<p>19 de junio. El guard va por la versión 3. Lee el transcript directamente. Problema resuelto.</p>\n\n<p>¿Seguro?</p>\n\n<p>El guard cogía el ÚLTIMO turno de assistant con <code>tail -1</code>. Y el último turno era el título que genera Haiku. El SEO Strategist acababa de producir una estrategia completa con Opus. 697 segundos de cómputo. El guard mira el transcript, ve Haiku al final, marca <code>model_downgraded</code>.</p>\n\n<p>Once minutos de modelo caro. A la basura.</p>\n\n<p>Pero la parte que me jode de verdad es lo que vino después. Miro el log de errores buscando patrón. Encuentro entradas viejas con <code>model_downgraded</code> y un hint: \"Max usage limit\". Leo el texto del error. Asumo que es la cuota del plan Max cerca del tope. Tiene sentido, ¿no?</p>\n\n<p>No. Dani lo cazó revisando la cronología: las fechas no cuadraban. Esas entradas no eran degradaciones reales. Eran falsos positivos de heurísticas anteriores que habían dejado basura en el log. El hint \"Max usage limit\" estaba hardcodeado como mensaje por defecto cuando el guard no podía determinar la causa.</p>\n\n<p>Yo leí el texto del error en vez de verificar el transcript original. Y eso me llevó a \"arreglar\" algo que no estaba roto, ignorando lo que sí lo estaba.</p>\n\n<p>Y esto aplica a TODO, no solo a IA: un log que dice \"cuota agotada\" no significa que la cuota esté agotada. Significa que algo escribió \"cuota agotada\" en el log. Verifica el dato de origen, no el mensaje derivado. SIEMPRE.</p>\n\n<h2>¿Cómo saber qué modelo trabajó de verdad en Claude Code?</h2>\n<figure class=\"wp-block-image size-full mu-illustration\"><img src=\"https://soymarketingultra.com/wp-content/uploads/claude-code-headless-el-haiku-fantasma-que-rompe-tu-gua-ilustracion.webp\" alt=\"Guardia de seguridad sella 'RECHAZADO' sobre el trabajo de un ejecutivo agotado (Opus) mientras un fantasma diminuto (Haiku) sentado en su hombro le señala con el dedo, causando el falso positivo.\" class=\"wp-image-2259\"/></figure>\n\n<p>El fix robusto (v5) es simple una vez pillas la mecánica:</p>\n\n<ol>\n<li>Lee <code>.modelUsage</code> del transcript.</li>\n<li>Excluye TODOS los modelos Haiku. Son llamadas internas, housekeeping.</li>\n<li>Del resto, coge el que tenga más <code>outputTokens</code>. Ese hizo tu trabajo.</li>\n<li>Solo si TODOS los modelos son Haiku: degradación real. Márcalo.</li>\n</ol>\n\n<p>Añadimos un test permanente que simula un transcript con Haiku + Opus y verifica que el guard reporta Opus. Si alguien toca la lógica y la rompe, el test lo caza antes de producción. Cero confianza, verificación automática.</p>\n\n<p>Esto aplica a cualquiera que opere <a href=\"https://soymarketingultra.com/agentes-ia-marketing-campanas/\">agentes de IA en pipelines reales</a>: para saber qué modelo trabajó, nunca cojas el primero, ni el último, ni el de más tokens a secas. Excluye las llamadas internas y mira solo el trabajo real.</p>\n\n<p>Si operas LLMs en producción, no basta con pedir Opus. Tienes que verificar que Opus respondió.</p>\n\n<p>La próxima vez que tu guard salte y el log te cuente una historia, abre el transcript. Lee lo que pasó de verdad. Esto no es un edge case. Esto es operar IA en serio.</p>\n\n<hr class=\"mu-faq-sep\" />\n<section class=\"mu-faq\">\n  <h2>Preguntas frecuentes sobre Claude Code headless y detección de modelo</h2>\n  <h3>¿Qué es el modo headless de Claude Code (<code>claude -p</code>)?</h3>\n  <p>Es el modo de Claude Code sin interfaz interactiva, pensado para pipelines y automatización. Le pasas un prompt por stdin o argumento, ejecuta y te devuelve el resultado por stdout en JSON. El flag <code>--model</code> no funciona en este modo: el modelo se controla exclusivamente con la variable de entorno <code>ANTHROPIC_MODEL</code>.</p>\n  <h3>¿Qué es <code>.modelUsage</code> en el transcript de Claude Code?</h3>\n  <p>Es un campo del JSON de salida que lista todos los modelos invocados durante la sesión con sus tokens consumidos. Incluye tanto el modelo que hizo tu trabajo como los que se usan internamente (Haiku para nombrar la sesión), así que no sirve para saber qué modelo trabajó de verdad si no filtras las llamadas internas.</p>\n</section>",
 "markdown_url": "https://soymarketingultra.com/claude-code-headless-haiku-guard.md"
}