Urgent.News

What's breaking now, across thousands of outlets.

AI

A SessionStart Hook That Hands Claude Code the Failing Tests Before Its First Turn

Book: AI Agents Pocket Guide The series: Pocket Guides for Developers — 8 short books on agents, RAG, prompts, observability, events, databases and system design — the whole series My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub CI went red over the weekend. Three checkout tests fail, and you know their names. A…

In the case described, a failing test suite caused the CI build to turn red. When a fresh Claude Code session begins, it must run the suite and read the output to learn about the errors before the developer can even start working on the issue. To avoid this delay, a SessionStart hook has been implemented. This hook runs during the initial setup of the Claude Code session and performs the following actions:

1. It uses pytest to execute only the fast tests, excluding any marked as "slow".

2. The hook keeps the output limited to the first 200 characters of each failure or error message to reduce the size of the information passed to Claude Code.

3. The hook only retries executing the tests if they exceed the set budget of 45 seconds, which is the maximum timeout allowed for the hook.

4. If the tests pass, it informs Claude that the fast tests have passed during the session start.

5. If there are failing tests, it lists the failing tests (up to a maximum of 15) and prints up to 200 characters from each failure message. If there are more than 15 failures, it indicates that there are additional failing tests.

6. If pytest exits with a non-zero return code without listing any failures, the hook informs Claude of the exit code and notes that no failures were listed.

By running this script as a SessionStart hook, Claude Code can be provided with the list of failing tests before the developer even begins typing, saving valuable time and effort in debugging and fixing the issues.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

AI became my extra team member. I still have to manage it

On any given day, I could be editing an article about women’s health, preparing a sponsorship proposal for an esports tournament, planning social media content, answering emails from PR agencies and troubleshooting something on a website. And that’s before I’ve even looked at the rest of my to-do list.

More from Monday 9 November →