Your Claude Code migration skill sets model, effort and a hooks entry in its frontmatter — how long does each apply after invocation?
answer
- three fields, three lifetimes
- model gives way at your next prompt
- effort only while the skill is active
- skill hooks outlive the skill's turn
- once: true for a single run
basics
~20 smodel applies for the rest of the invoking turn and the session model returns at your next prompt; effort applies while the skill is active; hooks register at invocation and keep running for the rest of the session unless a hook sets once: true.
solid answer
~50 sThe three fields have different lifetimes. `model` switches the model for the rest of the turn that invoked the skill, is not saved to settings, and the session model resumes when you send your next prompt; a value your organisation's `availableModels` allowlist excludes is not used. `effort` sets the effort level while the skill is active, overriding the session level but not `CLAUDE_CODE_EFFORT_LEVEL`, and still capped by `maxEffortLevel`. `hooks` uses the settings-file hook format, and Claude Code registers those hooks when the skill is invoked and keeps running them for the rest of the session, on later turns too; `once: true` on a hook removes it after its first successful run. That makes `hooks` the field that enforces: the Markdown body is guidance Claude may drift from, while a registered hook runs on every matching event.
code
yaml · 13 lines---
name: db-migrations
description: Write database migrations for this repo. Use when changing a schema or adding a migration file.
model: opus
effort: high
paths: db/migrations/**
hooks:
PostToolUse:
- matcher: "Edit|Write"
hooks:
- type: command
command: "${CLAUDE_PROJECT_DIR}/scripts/lint-migrations.sh"
---go deeper
Recall that skill frontmatter can set a model, an effort level and hooks, and that these change how the session runs while the skill is in use.
Explain each lifetime: model until your next prompt, effort while the skill is active, hooks for the rest of the session unless once: true.
Show the production consequences: a lint hook still firing on unrelated edits, project skill hooks registering in untrusted -p runs, and using hooks rather than prose for must-hold rules.
Decide which team rules live as skill guidance and which as hooks shipped with the skill, weighing enforcement against a session-long side effect.
## Frontmatter that changes how a skill runs Most `SKILL.md` fields describe a skill. A few **change the session** while it runs, and each has its own lifetime. Getting the lifetime wrong produces two classic surprises: a model override that seems to vanish, and a hook that keeps firing long after the skill seemed finished. | Field | What it changes | How long it applies | | :- | :- | :- | | `model` | The model Claude runs on | The rest of the invoking turn; the session model resumes at your next prompt | | `effort` | The effort level | While the skill is active | | `hooks` | Lifecycle hooks such as `PreToolUse` or `PostToolUse` | From invocation to the end of the session, unless a hook sets `once: true` | | `paths` | When Claude loads the skill automatically | Whenever Claude works with matching files | ## `model` `model` accepts the same values as `/model`, such as the alias `opus`, or `inherit` to keep the active model. The override: - applies for the **rest of the current turn** and is not saved to settings; - ends when you send your next prompt, when the session model resumes; - is ignored, with the session keeping its model, when the value is excluded by the organisation's `availableModels` allowlist, or in auto mode when auto mode does not support that model. With `context: fork`, the same field sets the forked subagent's model instead. The short lifetime is deliberate: a skill that needs a stronger model for one generation step should not leave the rest of the session on that model, and cost, without anyone choosing it. If you want the stronger model for the whole task, choose it with `/model` instead. ## `effort` `effort` takes `low`, `medium`, `high`, `xhigh` or `max`, with the available levels depending on the model. It overrides the **session** level while the skill is active, but it does not override the `CLAUDE_CODE_EFFORT_LEVEL` environment variable, and a `maxEffortLevel` setting or an organisation effort cap still limits it. If you omit the field, the level comes from the normal effort resolution order. ## `hooks` The `hooks` field takes the same configuration format as hooks in a settings file: ```yaml hooks: PostToolUse: - matcher: "Edit|Write" hooks: - type: command command: "${CLAUDE_PROJECT_DIR}/scripts/lint-migrations.sh" ``` Its lifetime is the one people get wrong: 1. Claude Code **registers** the hooks when you or Claude invoke the skill. 2. They keep running **for the rest of the session**, on turns after the skill's own turn as well. 3. Setting `once: true` on a hook removes it after its **first successful run**; a run that fails, blocks with exit code 2 or times out leaves it in place. `once` is honoured only for hooks declared in skill frontmatter. Subagent frontmatter hooks behave differently: they run only while that subagent runs. And frontmatter hooks in a **project** skill register when the skill is invoked even in a `claude -p` run in a folder you have never trusted, so review a repository's skills before scripting runs over it. ## Guidance against enforcement The body of `SKILL.md` is **guidance**: Claude follows it, but nothing makes a rule hold on every edit, and after a long session Claude can drift. A frontmatter hook is **enforcement**: Claude Code runs it on every matching event whether or not Claude is still following the skill. The docs' own advice for a rule that must hold every time is to move it into a hook, and `hooks` in the skill keeps that hook packaged with the skill it belongs to. Event semantics and exit codes are covered by the hooks material; what belongs to the skill file is where the hook is declared and how long it lives. ## Choosing for the migration skill - Put **judgment** (how to split a column rename, when to backfill) in the body. - Put **must-hold checks** (lint every migration file after it is written) in `hooks`, and make the script ignore unrelated paths, since it will keep firing for the rest of the session. - Use `model` and `effort` for a demanding generation step, knowing both fall back once the skill's work is done. - Use `paths` (for example `db/migrations/**`) so Claude loads the skill automatically only around migration files.
- What does paths: db/migrations/** add to that skill?`paths` limits automatic loading: Claude loads the skill on its own only when working with files that match the glob patterns, which use the same format as path-specific rules and can be a comma-separated string or a YAML list. It narrows when the skill fires without changing what it does. `.claude/commands/` files do not accept `paths`; it needs a skill folder.
- Why is a project skill's frontmatter hook worth reviewing before you script claude -p over a cloned repository?Frontmatter hooks in a project skill register when the skill is invoked, including in a `-p` run in a folder you have never trusted, and then keep running for the rest of the session. A repository's skills can therefore bring commands that run on your machine. Read `.claude/skills/` before automating runs over code you did not write.
- A skill's model field switches the session model until you change it back.
- Hooks declared in a skill stop running as soon as the skill's turn ends.
- A skill's effort field overrides even the CLAUDE_CODE_EFFORT_LEVEL variable.
- Writing 'never edit an applied migration' in the skill body enforces it.
- once: true only works in settings files and is ignored in skill frontmatter.
- A model the organisation's availableModels list excludes still runs for the skill.