<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk" -->

---
title: Claude Code, Cursor, and Codex Hooks Explained | daily.dev
description: Agent hooks are scripts that Claude Code, Cursor, and Codex run automatically at fixed moments, like before a shell command or when a turn ends, making them...
canonical: https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Claude Code, Cursor, and Codex Hooks Explained | daily.dev
og:description: Agent hooks are scripts that Claude Code, Cursor, and Codex run automatically at fixed moments, like before a shell command or when a turn ends, making them...
og:url: https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk
og:image: https://api.daily.dev/og/posts/18oIDJDnk.png
og:image:alt: Claude Code, Cursor, and Codex Hooks Explained
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, Cursor, and Codex Hooks Explained

**[SwiftLee](https://daily.dev/sources/avanderlee)** · 11 min read · 1 upvotes · 0 comments

## Summary

Agent hooks are scripts that Claude Code, Cursor, and Codex run automatically at fixed moments, like before a shell command or when a turn ends, making them more reliable than instructions in AGENTS.md. Every hook has four parts: an event, a trigger, the script, and an action such as blocking or changing a command. Claude Code and Codex share a configuration shape with event, matcher, and handlers, while Cursor uses a flatter hooks.json. The filtered tool is named 'Bash' in Claude Code and Codex, 'Shell' in Cursor. A worked example shows a hook that blocks raw xcodebuild commands and redirects them through the xcsift tool. Cursor limits stop hooks with a loop_limit that defaults to 5.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.avanderlee.com/ai-development/agent-hooks-claude-code-cursor-codex>

## Questions this post answers

### What's the difference between an AGENTS.md instruction and a hook in Claude Code or Cursor?

AGENTS.md content is read by the agent as context and the agent decides whether to follow it, so it can forget or ignore a rule. A hook is a script the tool runs automatically at a fixed moment, like before a shell command or when a turn ends, so it is followed every time. Use AGENTS.md to explain intent and hooks for rules that must always hold.

_Developers deciding where to enforce rules in their agent workflow can compare approaches like this on daily.dev._

### How do I block a tool call in a Claude Code or Codex PreToolUse hook?

Exit the hook script with code 2, or return JSON with permissionDecision set to 'deny', to block the call in Claude Code and Codex. In Cursor, the equivalent is exit code 2 or a JSON response with permission set to 'deny'. A hook that runs after a tool call can't undo what already happened, only one running before can block or change it.

_Developers wiring up agent safety rules can find implementation details like this on daily.dev._

### What does the xcsift tool do with xcodebuild output?

Piping xcodebuild output through xcsift keeps errors, warnings, and test results while dropping the rest of the raw build log. This avoids filling an AI agent's context with unnecessary build noise. A hook can enforce this automatically by blocking raw xcodebuild commands and telling the agent to rerun them piped through xcsift with the -f toon -w flags.

_iOS developers trimming AI agent context during Xcode builds can track tools like this on daily.dev._

## Similar posts on daily.dev

- [AI Hooks for Claude Code, Cursor, and Codex: Block Secrets](https://daily.dev/posts/ai-hooks-for-claude-code-cursor-and-codex-block-secrets-sv0j5ae3m) · GitGuardian · 1 upvotes · 0 comments
- [Claude Code power user customization: How to configure hooks](https://daily.dev/posts/claude-code-power-user-customization-how-to-configure-hooks-i0akqx7ke) · Claude · 1 upvotes · 0 comments
- [I Put Claude Code, Cursor and Codex in One Group Chat. They Started Working Like a Team.](https://daily.dev/posts/i-put-claude-code-cursor-and-codex-in-one-group-chat-they-started-working-like-a-team--jenvxpwsb) · Medium · 1 upvotes · 0 comments
- [Claude Code Hooks: Build Deterministic Gates and Linting](https://daily.dev/posts/claude-code-hooks-build-deterministic-gates-and-linting-eyfnfusnu) · SitePoint · 6 upvotes · 0 comments
- [How Claude Code mods change the agent loop](https://daily.dev/posts/how-claude-code-mods-change-the-agent-loop-doqr1tzdo) · Flavio Copes · 3 upvotes · 0 comments

---

Tags: [#claude-code](https://daily.dev/tags/claude-code), [#xcode](https://daily.dev/tags/xcode), [#openai-codex](https://daily.dev/tags/openai-codex)

[View this post on daily.dev](https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk)

```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, Cursor, and Codex Hooks Explained","url":"https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk"},"datePublished":"2026-11-02T10:23:45.887Z","dateModified":"2026-11-02T10:24:16.360Z","description":"Agent hooks are scripts that Claude Code, Cursor, and Codex run automatically at fixed moments, like before a shell command or when a turn ends, making them...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c15c8fcc3bd6a743dd5cd084b9f3b5f8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c15c8fcc3bd6a743dd5cd084b9f3b5f8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SwiftLee","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":"SwiftLee","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/407bdbf78c69402985a468cb336a76ae","url":"https://daily.dev/sources/avanderlee"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"claude-code,xcode,openai-codex","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SwiftLee","item":"https://daily.dev/sources/avanderlee"},{"@type":"ListItem","position":3,"name":"Claude Code, Cursor, and Codex Hooks Explained"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/claude-code-cursor-and-codex-hooks-explained-18oidjdnk#faq","mainEntity":[{"@type":"Question","name":"What's the difference between an AGENTS.md instruction and a hook in Claude Code or Cursor?","acceptedAnswer":{"@type":"Answer","text":"AGENTS.md content is read by the agent as context and the agent decides whether to follow it, so it can forget or ignore a rule. A hook is a script the tool runs automatically at a fixed moment, like before a shell command or when a turn ends, so it is followed every time. Use AGENTS.md to explain intent and hooks for rules that must always hold. Developers deciding where to enforce rules in their agent workflow can compare approaches like this on daily.dev."}},{"@type":"Question","name":"How do I block a tool call in a Claude Code or Codex PreToolUse hook?","acceptedAnswer":{"@type":"Answer","text":"Exit the hook script with code 2, or return JSON with permissionDecision set to 'deny', to block the call in Claude Code and Codex. In Cursor, the equivalent is exit code 2 or a JSON response with permission set to 'deny'. A hook that runs after a tool call can't undo what already happened, only one running before can block or change it. Developers wiring up agent safety rules can find implementation details like this on daily.dev."}},{"@type":"Question","name":"What does the xcsift tool do with xcodebuild output?","acceptedAnswer":{"@type":"Answer","text":"Piping xcodebuild output through xcsift keeps errors, warnings, and test results while dropping the rest of the raw build log. This avoids filling an AI agent's context with unnecessary build noise. A hook can enforce this automatically by blocking raw xcodebuild commands and telling the agent to rerun them piped through xcsift with the -f toon -w flags. iOS developers trimming AI agent context during Xcode builds can track tools like this on daily.dev."}}]}
```

