Deploy & Ops
Catch the agent failure mode where a commit imports an uncommitted file: typecheck an isolated worktree of HEAD, not the dirty working tree, before pushing to main.
1 file
Description
Catch the agent failure mode where a commit imports an uncommitted file: typecheck an isolated worktree of HEAD, not the dirty working tree, before pushing to main.
Before every push to a branch that auto-deploys (for example Vercel building main), on a repo where an agent may have left in-progress files in the working tree.
Local checks run against the working tree, which includes files you have not staged. An agent commits code that imports lib/new-thing.ts but leaves that file unstaged. pnpm typecheck passes locally (the file is on disk) and the deploy's tsgo gate fails (the checkout has only the commit). The fix is to check the committed tree, in isolation from the dirty working directory.
Add a detached worktree at HEAD in a temp dir, share node_modules by symlink so install is instant, run the exact deploy gate there, then clean up:
#!/bin/bash
set -euo pipefail
REPO="$(git rev-parse --show-toplevel)"
TMP="$(mktemp -d /tmp/verify-XXXXXX)"
trap 'git -C "$REPO" worktree remove --force "$TMP" 2>/dev/null || true; rm -rf "$TMP"' EXIT
git -C "$REPO" worktree add --detach "$TMP" HEAD --quiet
ln -s "$REPO/node_modules" "$TMP/node_modules"
cd "$TMP"
npx -y @typescript/native-preview --noEmit # the SAME gate the deploy runs
echo "commit tree verifies clean: $(git -C "$REPO" rev-parse --short HEAD)"
Run this exact gate, not just next build; a build can pass where a strict typecheck fails. Because the worktree is HEAD only, an uncommitted import fails here exactly as it will in CI.
node_modules into the temp dir is slow and can race a concurrent build. Symlink it instead.git worktree list and /tmp. Remove it in a trap so it cleans up even on failure.next build succeeding is not the deploy gate if the deploy runs a separate typecheck. Run the same command the deploy runs.Added 2026-07-01. Back to the Skill Library.

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.