Lifecycle actions
Add reusable actions at key checkpoints in your OpenSpec workflow.
Lifecycle actions let you add steps to your agent's workflow at specific checkpoints. For example, link a newly created change to an issue, check its plan against current external requirements before implementation, or update an issue when work begins. Use them when the timing of an action matters, rather than to describe how the agent should do its normal work.
When to use lifecycle actions
Start with the simplest mechanism that fits the job. Keep work needed for a particular change in its tasks, and recurring project conventions in project configuration.
| Use | When | Example |
|---|---|---|
tasks.md | Work needed to deliver this change | Implement the endpoint and add regression tests. |
context | Project facts and constraints | We use PostgreSQL and track work in Linear. |
rules | How planning artifacts should be written | Include the originating issue URL in the proposal when provided. |
operations | How the agent should carry out its normal work | Run relevant tests before marking tasks complete. |
lifecycle | A reusable, discrete action at a meaningful checkpoint | Move the linked issue to In Progress before implementation edits. |
An instruction in operations.apply can also ask the agent to update an issue. Use a lifecycle action when explicit timing, a named reusable action, its own confirmation mode, or ordering with other actions matters. Avoid duplicating the same work in tasks and actions.
Use Verify for a broader assessment of implementation against the plan, preferably in a fresh agent session when you want a more independent review. Use CI or external automation for checks and updates that must run reliably regardless of the agent.
How it works
Define an action once, then choose when and how your agent runs it.
| Concept | Meaning |
|---|---|
| Action | What the agent should do. |
| Hook | A named checkpoint in the workflow. |
| Trigger | Specifies which action to run at a hook and in which mode. |
| Mode | Whether the agent runs the action automatically or asks first. |
Set up your first action
For example, keep your issue tracker up to date when implementation begins. This example uses Linear and assumes your agent has access to a Linear integration with permission to update issues. Adapt the status names to your team's workflow.
Ask your agent
/openspec Help me set up a lifecycle action that automatically moves a change's linked Linear issue from Todo to In Progress when implementation begins. Skip changes without a linked issue and don't move issues backward.Your agent should propose the action and its trigger, then ask before editing your configuration.
Configure it yourself
Add the following to openspec/config.yaml (or your store's config):
lifecycle:
actions:
start-issue:
title: Mark issue as In Progress
instructions: |
Find the Linear issue linked in the change's proposal.
If no issue is linked, skip this action. If the link is ambiguous, ask.
Move the issue from Todo to In Progress only.
Leave issues in other statuses unchanged.
Report any failed lookup or update; continue without it.
triggers:
- on: change.apply.before
action: start-issue
mode: autoInclude the issue URL in a change's proposal, then ask your agent to implement the change as usual. Before implementation edits begin, the agent is instructed to update the issue. You don't need to invoke the action separately.
If you already have a lifecycle: block, add the action and trigger to it rather than creating a second block. Run openspec lifecycle actions to inspect your configuration; add --store <id> when targeting a specific store. The command lists actions without executing them.
What your agent receives
When your agent starts an OpenSpec operation, it reads the instructions for that operation. For Apply, that means a command such as:
openspec instructions apply --change add-rate-limit --jsonOpenSpec resolves the configured actions and includes them in the initial response alongside the normal workflow instructions.
The lifecycle portion of the response for the example above looks like this:
{
"lifecycle": {
"before": [
{
"id": "start-issue",
"mode": "auto",
"title": "Mark issue as In Progress",
"instructions": "Find the Linear issue linked in the change's proposal.\nIf no issue is linked, skip this action. If the link is ambiguous, ask.\nMove the issue from Todo to In Progress only.\nLeave issues in other statuses unchanged.\nReport any failed lookup or update; continue without it."
}
],
"handling": "...instructions for when and how to run the actions..."
}
}The response is shown in part, with the handling instructions abbreviated. OpenSpec resolves the actions. Your agent handles them at the specified checkpoints, using its existing tools, permissions, and context.
Both before and completed actions are loaded when the operation starts. They share the agent's context window with its normal work; they do not automatically start separate sessions. Keep actions focused. For substantial reviews that benefit from fresh context, use a separate workflow.
Create and Archive follow the same delivery pattern through their own instruction commands. See the CLI reference for the full contract.
When actions run
OpenSpec has six built-in hooks: before and after creating, applying, and archiving a change. They fit into the workflows you already use; they do not add new phases.
| Hook | When it runs |
|---|---|
change.create.before | Before creating a change. |
change.create.completed | After the change is created, before writing any planning artifacts. |
change.apply.before | Before starting or resuming implementation when work is ready. |
change.apply.completed | When tracked tasks are complete, or implementation finishes without task tracking. |
change.archive.before | Before syncing specs or moving the change to the archive, after the user has confirmed archiving where required. |
change.archive.completed | After the change moves to the archive, even if specs were not synced. |
Creating a change is not the same as completing its plan. To check the plan before implementation, use change.apply.before.
Modes
| Mode | What happens | Use it for |
|---|---|---|
auto | Run without asking first. | Routine actions, such as moving a linked issue to In Progress. |
suggest | Offer the action and wait for your answer. | Optional steps, such as drafting a release-note entry. |
With suggest, your agent might ask, "Draft release notes for this change?" If you accept, it runs the action. If you decline, it skips the action and continues. The title and optional description help you decide.
With auto, the agent can still ask questions when the action needs your input. Both modes respect the agent's normal tool permissions.
Use mode to decide whether the agent asks before running an action. Use the action's instructions to decide what happens when it finds a problem.
You can attach an action to several hooks or run several actions at the same hook. Actions at a hook run in trigger order.
What's possible
Lifecycle actions are useful for keeping work connected as it moves through the workflow.
| Example | Hook |
|---|---|
| Flag overlapping active changes before creating a duplicate. | change.create.before |
| Record the new change ID on its originating issue, if one was supplied. | change.create.completed |
| Compare the plan with the linked issue's current requirements, or mark the issue In Progress. | change.apply.before |
| Move a linked issue to In Review when implementation finishes, if that matches your team's workflow. | change.apply.completed |
| Check whether the associated pull request has merged if your team archives after merging. | change.archive.before |
| Add the archived change's location to the linked issue. | change.archive.completed |
These are examples you can adapt to your tools, not integrations built into OpenSpec. Use explicit issue or pull request links. Apply completion does not mean the work is verified or merged, and archiving does not necessarily mean it has shipped.
You don't need an integration to use lifecycle actions. For example, configure an optional handoff after archiving:
/openspec Help me set up a lifecycle action that offers to draft a release-note entry after archiving a change. If I accept, draft it from the archived artifacts for my review without publishing anything.Writing effective actions
- Keep actions focused: Specify the intended result, the tools or evidence to use, and when to skip. Avoid large reviews or instructions that duplicate the normal workflow.
- Handle missing inputs and failures: Say what to do when an issue is not linked, a tool is unavailable, or a check fails. Specify whether to continue or ask the user.
- Make actions safe to repeat: Check the current state before writing, avoid duplicate comments or links, and never move an issue backward unintentionally.
For example, instead of "Update the issue," use "Find the linked issue. If it is in Todo, move it to In Progress. Leave other statuses unchanged. Report any failed update."
If an action needs to run an existing script, put the command and instructions for handling its output in instructions. The agent runs it using its available tools; there is no separate command: field.
Good to know
- Execution: Actions are agent instructions, not background jobs or guaranteed event delivery. Direct CLI commands such as
openspec new changeandopenspec archivedo not run actions. - Enforcement: An action can ask the agent to pause or report a failure, but OpenSpec does not enforce action results as policy gates. Use CI for checks that must run independently of the agent or block merging.
- Repeated and interrupted runs: Actions may run again when you resume Apply or revisit completed work. OpenSpec does not track action execution or automatically retry failed updates. Resuming an existing change does not replay Create actions, and failed creation skips
change.create.completed. - Configuration: Workflows use the action list from their initial instruction read. Config edits apply on the next operation. Run
openspec lifecycle actionsto diagnose invalid configuration; a returned lifecycle error stops the relevant edits.
After upgrading OpenSpec, run openspec update to refresh your skills.
See the configuration reference for exact syntax and validation rules, and the CLI reference for operation-specific behavior.
Building your own workflow? Define a custom. hook and use openspec lifecycle actions --at <hook> to retrieve its actions from your own skill or orchestrator.