HookStack
Back to catalogue
WorkflowTaskCreated

Enforce task naming conventions

Every task ties back to a [TICKET-123]

Blocks task creation when the subject does not start with a ticket reference in the format [PREFIX-123]. Ensures every agent-created task is traceable to a project management ticket before it enters the queue.

What does the Enforce task naming conventions hook do?

Enforce task naming conventions is a Claude Code TaskCreated hook. It fires automatically at that lifecycle event — outside the model, so it can't be skipped or forgotten. Every task ties back to a [TICKET-123].

Because it is a deterministic Node.js script, it executes on every matching event without relying on the model to remember — the guarantee that makes agentic workflows safe to automate.

Use cases

  • Require ticket numbers on all tasks created by agent teams (e.g. [PROJ-42])
  • Enforce consistent task naming in multi-agent CI pipelines
  • Prevent orphaned tasks with no traceability to Linear, Jira or GitHub issues

Tags

#tasks#naming#agent-teams#traceability#conventions

settings.json fragment

{
  "hooks": {
    "TaskCreated": [
      {
        "hooks": [
          {
            "command": "node $CLAUDE_PROJECT_DIR/.claude/hooks/task-created-naming-convention.mjs",
            "type": "command"
          }
        ]
      }
    ]
  }
}

Script · .claude/hooks/task-created-naming-convention.mjs

#!/usr/bin/env node
// @hookstack task-created-naming-convention
// Impose une référence de ticket en tête du sujet d'une tâche (TaskCreated)
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

export function run(input) {
	const subject = input.task_subject ?? "";
	if (/^\[[A-Z]+-\d+\]/.test(subject)) return null;
	return {
		exitCode: 2,
		message:
			`Task subject must start with a ticket reference, e.g. "[PROJ-123] ${subject}". ` +
			"Update the subject to include a valid ticket number.",
	};
}

/* v8 ignore next 6 */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
	const input = JSON.parse(readFileSync(0, "utf8"));
	const result = run(input);
	if (result) {
		process.stderr.write(result.message);
		process.exit(result.exitCode);
	}
}

Learn more

Related hooks