<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z" -->

---
title: Claude Code kept shipping broken code until I added this...
description: Claude Code hooks let developers run shell commands automatically at defined lifecycle events, such as when the agent marks a task complete. By registering a...
canonical: https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Claude Code kept shipping broken code until I added this one automation | daily.dev
og:description: Claude Code hooks let developers run shell commands automatically at defined lifecycle events, such as when the agent marks a task complete. By registering a...
og:url: https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z
og:image: https://api.daily.dev/og/posts/iHPtPJH7z.png
og:image:alt: Claude Code kept shipping broken code until I added this one automation
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code kept shipping broken code until I added this one automation

**[XDA Developers](https://daily.dev/sources/xda-developers)** · 4 min read · 0 upvotes · 0 comments

## Summary

Claude Code hooks let developers run shell commands automatically at defined lifecycle events, such as when the agent marks a task complete. By registering a script on the 'TaskCompleted' event that runs the project's test suite and exits with a non-zero status on failure, Claude Code is forced to fix failing tests before declaring a task done, instead of silently shipping broken code. The tradeoff is heavier consumption of Claude Code's usage limits, since failed tests trigger more tool calls and re-runs.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.xda-developers.com/claude-code-shipping-broken-code-added-automation>

## Questions this post answers

### How do I make Claude Code run tests automatically before it marks a task as complete?

Add a hook on the TaskCompleted event in .claude/settings.json that points to an executable shell script running your test suite (e.g. npm test). The script should exit 0 if tests pass, or exit with a non-zero status and print the failure output to stderr if they fail; Claude Code treats a non-zero exit as a hard block and won't proceed until it fixes the failures.

_daily.dev surfaces practical Claude Code automation patterns like hook-based test enforcement._

### What is the TaskCompleted event in Claude Code hooks used for?

TaskCompleted is a Claude Code hook event that fires specifically when the agent finishes a task, unlike the more general Stop trigger which fires on every response. Using TaskCompleted instead of Stop lets a review or test script run only after actual work is done, avoiding unnecessary checks on simple explanations or discussions.

_Developers tuning agent automation can track Claude Code hook behavior through daily.dev._

### Does adding a test-verification hook to Claude Code increase usage limit consumption?

Yes, forcing Claude Code to verify every completed task with a test run before finishing increases usage consumption because a failed test sends the agent back into the code, triggers more tool calls, and re-runs the hook once it believes the task is complete again. This can strain Claude Code's usage window, which is already considered limited during regular use.

_Anyone weighing Claude Code usage limits against reliability gains can follow related workflow tips on daily.dev._

## Similar posts on daily.dev

- [Claude Code's output got dramatically better when I stopped letting it decide when it was done](https://daily.dev/posts/claude-code-s-output-got-dramatically-better-when-i-stopped-letting-it-decide-when-it-was-done-mln6fekdq) · XDA Developers · 0 upvotes · 1 comments
- [How to Improve Claude Code Performance with Automated Testing](https://daily.dev/posts/how-to-improve-claude-code-performance-with-automated-testing-xkejpz4rd) · Towards Data Science · 0 upvotes · 0 comments
- [I'm Building Agents That Run While I Sleep](https://daily.dev/posts/i-m-building-agents-that-run-while-i-sleep-psrvg5tk0) · Hacker News · 2 upvotes · 0 comments
- [Claude Code — A Practical Guide to Automating Your Development Workflow](https://daily.dev/posts/claude-code-a-practical-guide-to-automating-your-development-workflow-pbqztpxro) · We Are .NET · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#ai-agents](https://daily.dev/tags/ai-agents), [#automation](https://daily.dev/tags/automation), [#claude-code](https://daily.dev/tags/claude-code), [#shell](https://daily.dev/tags/shell)

[View this post on daily.dev](https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Claude Code kept shipping broken code until I added this one automation","url":"https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z"},"datePublished":"2026-08-26T16:34:55.080Z","dateModified":"2026-08-27T08:48:50.537Z","description":"Claude Code hooks let developers run shell commands automatically at defined lifecycle events, such as when the agent marks a task complete. By registering a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/64b26f8755cd920615bf6380d2266d5f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/64b26f8755cd920615bf6380d2266d5f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"XDA Developers","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"XDA Developers","logo":"https://media.daily.dev/image/upload/s--kCg6yyAP--/f_auto,q_auto/v1774964407/logos/xda-developers?_a=BAMAMiWQ0","url":"https://daily.dev/sources/xda-developers"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,ai-agents,automation,claude-code,shell","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"XDA Developers","item":"https://daily.dev/sources/xda-developers"},{"@type":"ListItem","position":3,"name":"Claude Code kept shipping broken code until I added this one automation"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/claude-code-kept-shipping-broken-code-until-i-added-this-one-automation-ihptpjh7z#faq","mainEntity":[{"@type":"Question","name":"How do I make Claude Code run tests automatically before it marks a task as complete?","acceptedAnswer":{"@type":"Answer","text":"Add a hook on the TaskCompleted event in .claude/settings.json that points to an executable shell script running your test suite (e.g. npm test). The script should exit 0 if tests pass, or exit with a non-zero status and print the failure output to stderr if they fail; Claude Code treats a non-zero exit as a hard block and won't proceed until it fixes the failures. daily.dev surfaces practical Claude Code automation patterns like hook-based test enforcement."}},{"@type":"Question","name":"What is the TaskCompleted event in Claude Code hooks used for?","acceptedAnswer":{"@type":"Answer","text":"TaskCompleted is a Claude Code hook event that fires specifically when the agent finishes a task, unlike the more general Stop trigger which fires on every response. Using TaskCompleted instead of Stop lets a review or test script run only after actual work is done, avoiding unnecessary checks on simple explanations or discussions. Developers tuning agent automation can track Claude Code hook behavior through daily.dev."}},{"@type":"Question","name":"Does adding a test-verification hook to Claude Code increase usage limit consumption?","acceptedAnswer":{"@type":"Answer","text":"Yes, forcing Claude Code to verify every completed task with a test run before finishing increases usage consumption because a failed test sends the agent back into the code, triggers more tool calls, and re-runs the hook once it believes the task is complete again. This can strain Claude Code's usage window, which is already considered limited during regular use. Anyone weighing Claude Code usage limits against reliability gains can follow related workflow tips on daily.dev."}}]}
```

