Home / Problems / Enforce test-first work in Claude Code

Workflow problem

Enforce test-first work in Claude Code

A prompt asking for tests first may be skipped when the agent moves quickly into implementation.

The problem

A prompt asking for tests first may be skipped when the agent moves quickly into implementation.

Native approach

Document the expected test-first sequence in project instructions. For an enforced check, configure a `PreToolUse` hook that rejects writes until your test condition is met.

Official Claude Code documentation ↗

Tools to consider

Start by testing the guard against a sample task; blocking rules can interfere with legitimate refactors.

FAQ

Will a CLAUDE.md instruction enforce TDD?

It guides behavior but cannot guarantee that every write is blocked.

What can block an early implementation edit?

A correctly configured hook or a guard tool can reject the edit.