---
name: imdone-template
description: Apply an imdone template to an existing issue using `imdone template`. Use when the user wants to switch an existing issue to a template, add HDD structure to a story that does not already use the HDD template, or repair a story missing the expected template-backed sections and attachment links.
---

# Imdone Template

Use `imdone template` to apply a template to an existing issue.

Start from:

```bash
imdone template --help
```

Command shape:

```bash
imdone template [issueKey] --template [template]
```

Examples:

```bash
imdone template SCRUM-247 --template stock_hypothesis_driven_development
imdone template SCRUM-247 --template story
```

## Workflow

1. Resolve the target issue key.
2. Resolve the template name.
3. Run `imdone template <issueKey> --template <template>`.
4. Read the updated issue file and attachments before doing any downstream refinement work.

## Defaults

- If the user already has an active issue in the conversation, prefer that issue key.
- If the request is to prepare a story for HDD and no template is specified, prefer `hypothesis_driven_development` when that template exists locally; otherwise use `stock_hypothesis_driven_development`.
- If the issue key is still unknown, ask for it or identify the active story from local context before running the command.

## Guidance

- Prefer explicit flags over interactive prompts when the issue key and template are already known.
- Resolve HDD template preference by checking local templates first and choosing `hypothesis_driven_development` over `stock_hypothesis_driven_development` when both are available.
- Treat `#HDD-template` in the issue metadata/comments as the signal that the HDD template is already applied.
- After applying a template, re-read the issue and any attachment files the template creates.
- Existing files are not overwritten by template-backed attachment creation; check what was created versus what already existed.
- If the command fails because the template name is unknown, inspect `.imdone/templates/` and retry with the correct template name.

## Output

Report:
- the issue key
- the template applied
- the updated issue file path
- whether new attachment files were created
