SShortSingh.
Back to feed

20-Line Python Hook Forces Claude Code to Verify Tests Before Declaring Done

0
·6 views

Developers using Claude Code often encounter a frustrating pattern where the AI declares a task complete while automated tests are still failing, because the tool has no built-in mechanism to verify its own output. A developer has shared a lightweight fix using Claude Code's Stop hook feature, which intercepts the AI's attempt to end its turn and runs a verification command first. The hook, roughly 20 lines of Python, reads a test command from a config file and blocks Claude from finishing if the command exits with a non-zero code, feeding the failure output back to the AI instead. Anthropic's own best practices recommend giving Claude a verification signal such as tests or a linter, and Claude Code's creator Boris Cherny has noted that this feedback loop improves output quality by two to three times. The solution requires placing a Python script in the project's .claude/hooks directory and registering it in settings.json, after which Claude will automatically retry and fix failures before reporting completion.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How to Send Telegram Bot Messages in PHP Using cURL with Full Error Handling

Developers can send Telegram bot messages using PHP's cURL extension by calling the sendMessage API method over HTTPS. A minimal helper function handles the full request lifecycle, including reading the bot token from an environment variable, building the payload, and setting connection timeouts. The function performs layered error checks: verifying the HTTP status code, safely decoding the JSON response, and confirming that Telegram's 'ok' field returns true. If any of these checks fail, the function throws a descriptive runtime exception to help diagnose the issue. The guide focuses strictly on the sendMessage call and does not cover webhook management, SDK functionality, or state persistence.

0
ProgrammingDEV Community ·

Binance Order Flow Data Boosts Polymarket BTC Trade Accuracy to 70%, Study Finds

A study analyzing 2,833 five-minute Polymarket markets for BTC, ETH, and SOL found that combining the late-stage market leader with Binance aggressive order flow data significantly improved historical prediction accuracy. When price direction and order flow aligned, the market leader won approximately 70.2% of the time, compared to just 57.6% when using price signals alone. Conversely, when price and order flow diverged, the leader won only 41.3% of the time, suggesting the underlying buying or selling pressure told a different story than the price chart. The research proposes an automated trading bot architecture that separates data collection, signal generation, and order execution into distinct components. Researchers cautioned that these figures reflect historical results only and do not guarantee future trading performance.

0
ProgrammingDEV Community ·

Developer Builds Free Browser-Based Fence Calculator Using Vanilla JavaScript

A developer has created a lightweight, browser-based fence calculator called the ItaliaLegacy Fence Calculator, built entirely with HTML, CSS, and vanilla JavaScript. The tool estimates key fencing materials — including sections, panels, posts, and rails — based on user-entered measurements such as total fence length, gate widths, post spacing, and rails per section. All calculations run locally in the browser, meaning no data is sent to a server. The calculator accounts for gate openings by subtracting gate widths from the total fence length before computing material estimates. It is designed as a planning aid rather than a precise purchasing guide, as real-world variables like corners and direction changes can affect actual material needs.

0
ProgrammingDEV Community ·

Kaggle Benchmark Tests AI Models on Booking Conflict Replay Logic

A new Kaggle benchmark called Reservation Replay challenges AI models to correctly handle booking conflicts, specifically testing whether a failed request remains failed even after conditions change. The benchmark uses fictional rooms and integer time intervals across 8 base traces and 4 dependent metamorphic variants, scored by exact trace success without an LLM judge. Google's Gemini 3.7 Flash achieved a perfect 12/12 score, while Gemini 2.5 Flash scored only 4/12, primarily due to output formatting failures rather than logical errors. A scoring policy update was introduced mid-evaluation after Gemini 2.5 Flash triggered a ResponseParsingError, highlighting how format compliance can significantly skew benchmark results. The author cautions that the small pilot size and dependent variants are insufficient to establish stable model rankings, but the reproducible fixtures and preserved run evidence make the findings verifiable.