$ recombobulate _
home / tips / chain-bash-commands-with-to-prevent-half-broken-refactors
0

Chain Commands with && to Keep Claude's Work Atomic

bagwaa @bagwaa · Mar 26, 2026 · Workflows
chain-bash-commands-with-to-prevent-half-broken-refactors

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

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 2 hours ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 2 hours ago
0
Write Property-Based Tests with fast-check and Claude

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.

bagwaa @bagwaa · 2 hours ago