Chain Commands with && to Keep Claude's Work Atomic
Half-broken refactors are the worst. Claude runs three operations, the second one silently fails, and the third commits broken code anyway.
The fix is simple: when asking Claude Code to run multiple bash operations in sequence, instruct it to chain them with &&.
# Apply a migration and verify before moving on
php artisan migrate && php artisan test --filter=DatabaseTest
# Lint, test, then commit — stops if either fails
npm run lint && npm test && git commit -m "fix: auth token refresh"
# Build then deploy — only reaches deploy if build succeeds
npm run build && npm run deploy:staging
If any step exits with a non-zero code, the chain stops immediately. The tests never run if the edit failed. Nothing gets committed if the tests fail. Only a clean chain reaches the end.
You can tell Claude explicitly: "chain these steps with && so the whole sequence stops if anything fails." Claude Code will honour that instruction and bail at the first failure rather than marching forward into a broken state.
This pattern is especially useful when asking Claude to:
- Lint, test, then commit only if both pass
- Migrate a database then seed it
- Build a project then only deploy if the build succeeds
The pattern also composes well with a final commit or notification step — Claude only reaches it if everything upstream passed cleanly.
One && is the cheapest safety net in your entire workflow — it costs you nothing to add it.
via @AgentLabX
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.