{
  "slug": "terragrunt-hooks-receive-additional-tg-ctx-environment-variables-6c8e1faad372",
  "title": "Terragrunt hooks receive additional TG_CTX_* environment variables",
  "tools": [
    "terragrunt"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-06-10T19:50:18.000Z",
  "announced_at": "2026-06-10T19:50:18.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When a shared hook script needs to identify its lifecycle phase or access the unit’s source and config directory, enable `hook-context-env` for the Terragrunt run. Read `TG_CTX_HOOK_TYPE`, `TG_CTX_SOURCE`, and `TG_CTX_TERRAGRUNT_DIR` in the hook script.",
    "examples": [
      "terragrunt run --all --experiment hook-context-env -- apply"
    ],
    "gotchas": [
      "Version: v1.0.8",
      "Availability: experimental",
      "--experiment hook-context-env (required): Enables the `hook-context-env` experiment for the run.",
      "--all (required): Runs the specified OpenTofu/Terraform command across units in the current stack.",
      "TG_CTX_HOOK_TYPE: Identifies the hook lifecycle phase: `before_hook`, `after_hook`, or `error_hook`.",
      "TG_CTX_SOURCE: Resolved source URL: CLI `--source` override, otherwise evaluated `terraform.source` with `--source-map` applied, otherwise `.`.",
      "TG_CTX_TERRAGRUNT_DIR: Directory containing the current Terragrunt config; equivalent to `get_terragrunt_dir()`.",
      "Prerequisite: Enable the `hook-context-env` experiment for the run; it adds the variables to every `before_hook`, `after_hook`, and `error_hook`.",
      "The variables are surfaced to every `before_hook`, `after_hook`, and `error_hook`.",
      "`TG_CTX_HOOK_TYPE` identifies `before_hook`, `after_hook`, or `error_hook`.",
      "`TG_CTX_SOURCE` is the resolved terraform source URL: CLI `--source` override, otherwise evaluated `terraform.source` with source-map applied, otherwise `.`.",
      "`TG_CTX_TERRAGRUNT_DIR` is the directory of the current Terragrunt config."
    ]
  },
  "why_it_matters": "When sharing a hook script across Terragrunt lifecycle phases, read the added context variables inside the hook to identify its phase and access the unit source and config directory.",
  "sources": [
    "https://github.com/gruntwork-io/terragrunt/releases/tag/v1.0.8",
    "https://docs.terragrunt.com/reference/experiments/active/",
    "https://docs.terragrunt.com/reference/cli/commands/run/"
  ],
  "rank": 0.92036,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave2a-20261017",
    "verdict_id": "wave2a-20261017:wave2a-20261017-25308fef7bd0033c-1:gate",
    "evidence_hash": "65465bda51630955ee70203dbbe0ea046e05d005334ce0ac0badb6ca418772a4"
  },
  "review": {
    "draft_hash": "5efc66db315743ab3432bfaecd1bb09a13208023bbf49fe5d67f65f7920f6074",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave2a-20261017:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.92 >= 0.9; 2 needed) and Jev gave 0.65 (>= 0.6 needed)."
  }
}
