Files
registry/registry/coder/modules/coder-utils
Atif Ali 3b64d99fb1 refactor(registry/coder/modules/coder-utils)!: derive names from module_directory (#874)
## Summary

Derives `coder-utils` script names from `module_directory` instead of a
separate `agent_name` input. The `module_directory` already encodes both
the namespace and the module name, so carrying both is redundant and
error-prone. Callers like `claude-code` no longer need to pass
`agent_name`.

Scripts this module materializes lose the `${agent_name}-utils-` prefix
because `module_directory` already namespaces them per-caller.

We will address multiple instances of coder-utils per caller in a future
iteration if needed.

## Versioning Note

Previous tags (`v1.0.0` through `v1.3.0`) have been deleted because no
published module ever consumed them — the module was effectively
unreleased. This PR ships the first real public version as **`v0.0.1`**,
treating it as a fresh start rather than a breaking bump from a version
that was never in production use.

## Changes

- Remove `agent_name` variable.
- Derive `caller_name = "${namespace}-${module_name}"` from
`module_directory`.
- Validate `module_directory` matches
`$HOME/.coder-modules/<namespace>/<module-name>`.
- Rename script files on disk from `${agent_name}-utils-<phase>.sh` to
plain `<phase>.sh`.
- Add a TS test for the `module_directory` validation.
- Ship as `v0.0.1` (first published version; all prior tags removed).

## Breaking Changes

| Before | After |
|---|---|
| `agent_name = "myagent"` | removed (derived from `module_directory`) |
| `module_directory = ".my-module"` | `module_directory =
"$HOME/.coder-modules/<ns>/<name>"` (validated) |
| Script files `${agent_name}-utils-install.sh` | `install.sh` |
| Script sync names `${agent_name}-install_script` |
`${namespace}-${module_name}-install_script` |

No callers were depending on the old format (prior tags were
unpublished).

## Validation

- `terraform fmt -recursive` clean
- `terraform validate` clean
- `terraform test` → 17/17 pass
- `bun test registry/coder/modules/coder-utils` → 5/5 pass
- `prettier --check` clean

## Consumer

coder/registry#861 (`claude-code`) consumes this and is currently pinned
to the commit SHA until this merges and ships as `v0.0.1`.

> 🤖 This PR was created with the help of Coder Agents, and needs a human
review. 🧑‍💻
2026-04-24 17:16:10 +05:00
..

display_name, description, icon, verified, tags
display_name description icon verified tags
Coder Utils Building block for modules that need orchestrated script execution ../../../../.icons/coder.svg false
internal
library

Coder Utils

Caution

We do not recommend using this module directly. It is intended primarily for internal use by Coder to create modules with orchestrated script execution.

The Coder Utils module is a building block for modules that need to run multiple scripts in a specific order. It uses coder exp sync for dependency management and is designed for orchestrating pre-install, install, post-install, and start scripts.

module "coder_utils" {
  source  = "registry.coder.com/coder/coder-utils/coder"
  version = "0.0.1"

  agent_id         = coder_agent.main.id
  module_directory = "$HOME/.coder-modules/coder/claude-code"

  pre_install_script = <<-EOT
    #!/bin/bash
    echo "Running pre-install tasks..."
    # Your pre-install logic here
  EOT

  install_script = <<-EOT
    #!/bin/bash
    echo "Installing dependencies..."
    # Your install logic here
  EOT

  post_install_script = <<-EOT
    #!/bin/bash
    echo "Running post-install configuration..."
    # Your post-install logic here
  EOT

  start_script = <<-EOT
    #!/bin/bash
    echo "Starting the application..."
    # Your start logic here
  EOT
}

Execution Order

The module orchestrates scripts in the following order:

  1. Pre-Install Script (optional) - Runs before installation
  2. Install Script (required) - Main installation
  3. Post-Install Script (optional) - Runs after installation
  4. Start Script (optional) - Starts the application

Each script waits for its prerequisites to complete before running using coder exp sync dependency management.

Customizing Script Display

By default each coder_script renders in the Coder UI as plain "Install Script", "Pre-Install Script", etc. Downstream modules can brand them:

module "coder_utils" {
  source  = "registry.coder.com/coder/coder-utils/coder"
  version = "0.0.1"

  agent_id         = coder_agent.main.id
  module_directory = "$HOME/.coder-modules/coder/claude-code"
  install_script   = "echo installing"

  display_name_prefix = "Claude Code" # yields "Claude Code: Install Script", etc.
  icon                = "/icon/claude.svg"
}

Both variables are optional. display_name_prefix defaults to "" (no prefix), and icon defaults to null (use the Coder provider's default).

Log file locations

The module writes each script's stdout+stderr to ${module_directory}/logs/:

  • pre_install.log
  • install.log
  • post_install.log
  • start.log

Each coder_script mkdir -ps this subdirectory before its tee runs, so the first script to execute creates it.

Script file locations

The module materializes each script to ${module_directory}/scripts/ before running it:

  • pre_install.sh
  • install.sh
  • post_install.sh
  • start.sh

The pre-install and install coder_scripts mkdir -p this subdirectory; post-install and start sync-depend on install, so the directory already exists by the time they run.