# Verify, don't rely on memory

> A separate worktree can't keep your assumptions current. Here's when to stop before a Terraform apply and how to verify the result after deployment.

Date: 2026-11-22  
Author: Nik  
Tags: ai, git, terraform, workflow  
Source: https://devscratch.com/en/posts/verify-dont-recall

The full Terraform plan proposed deleting services that had been created five minutes earlier. They'd been added in another commit. Terraform was doing exactly what we'd asked: showing what would happen if we applied the configuration it had been given.

If the task doesn't call for deleting anything, that's reason enough to stop. The change you wanted can still be right there in the plan.

In [One worktree per agent](/en/posts/worktree-per-agent), we looked at why each agent needs its own worktree. An agent switching branches in its own directory won't change yours. You still have to check how current your branch is, which environment you're targeting, and whether your earlier checks still hold.

## Being on the right branch is only half the answer

Say you pause before lunch and tell the agent to carry on when you get back. The conversation has the branch name and a note that someone reviewed the plan. What changed while you were away?

Start with these commands. Substitute your project's base branch if it's not `master`:

```bash
git status --short --branch
git fetch origin
git rev-list --left-right --count origin/master...HEAD
```

- `git status --short --branch` shows the current branch and uncommitted changes.
- `git fetch origin` refreshes `origin/master`, Git's local record of where `master` points on the remote. If fetching fails, that ref may still point to an old commit. Don't treat the comparison as current.
- `git rev-list` counts commits unique to each side. `3  1` means three commits are only in `origin/master` and one is only in `HEAD`.

If you're three commits behind, look at what changed before deciding whether to update your branch. Maybe it's all documentation. Maybe someone edited the same configuration. Even `0  1` tells you nothing about which environment Terraform is targeting. Check the workspace, backend, or account your project uses.

## Stop at an unexpected deletion

Here's a simplified example, not a log from the incident:

```text
  # example_service.metrics will be destroyed
Plan: 0 to add, 1 to change, 1 to destroy.
```

Suppose the task is to change one setting on an existing service. `1 to change` is what you expected. `1 to destroy` needs an explanation. Watch for replacements too: Terraform can remove and recreate a resource without changing the total resource count.

A useful message from the agent would be:

> I stopped because the plan would also destroy `example_service.metrics`. That's outside the task, and I haven't applied anything. I'll check where the resource is defined in the current configuration and which commit the plan was built from.

Using `-target` to make the warning disappear can hide changes without explaining them. If the configuration, inputs, or target environment change, review a new full plan before applying it.

You can use `-target` in CI/CD, but keep it out of the routine pipeline. If a merge triggers `apply` before anyone reviews the full plan, Terraform can delete or replace resources that had nothing to do with the change. For production, generate a full plan, review and approve it, then apply that exact saved plan. If you regenerate it, review it again.

## Check what actually shipped

At devscratch, we merged a change to an article's SEO title. GitLab showed the merge request as `merged`, but production was still serving the old `<title>`. Once the deployment went through, the new title appeared at the same URL.

The merge request confirmed the change was on the main branch. To see what readers were getting, we checked the `<title>` in the HTML served by `devscratch.com`. Use the same approach after an `apply`: if you changed a service setting, check the setting in the target environment.

Report what you observed: “I checked the production HTML for the Russian article. Its `<title>` now starts with `Git worktree для AI-агентов`.” If you only had access to GitLab, say: “The MR is merged. I haven't verified production.”

## Copy this into AGENTS.md

Use this for actions that change state, such as applying a plan, deploying, running a migration, or modifying an external resource.

```markdown
## Verify state before and after changes

1. State the goal and target environment. Confirm the working directory,
   current commit, and base branch state if they affect the result.
   If a check fails, don't fall back on what you remember.
2. Read the full plan. Stop before applying if you see an unexpected deletion,
   replacement, or out-of-scope change. Name the resource and planned action,
   say that nothing was applied, and ask if proceeding would expand the scope.
3. If the inputs or assumptions change, verify them again. For Terraform,
   generate and review a new plan; don't carry approval over to a different
   set of changes.
4. Check the expected result in the target environment. Report what you
   checked and what you observed. If you couldn't verify the result,
   distinguish what you did from what you couldn't confirm.
```

Ask the agent to show how it knows the facts still hold.
