claude-code - 💡(How to fix) Fix PostToolUse:Write hook error: 'Messages are required for agent hooks. This is a bug.' with CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48481Fetched 2026-04-16 06:58:57
View on GitHub
Comments
2
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×4commented ×2cross-referenced ×1

After every Write or Edit tool call that triggers auto-memory, two identical errors appear:

⎿  PostToolUse:Write hook error
⎿  Failed to run: Messages are required for agent hooks. This is a bug.

The memory writes themselves succeed (the banner reports "wrote N memories" correctly, and the files do land on disk) — only the post-write telemetry step fails.

Error Message

⎿ PostToolUse:Write hook error 3. Observe the banner: Read 1 file, recalled 1 memory, wrote 2 memories (ctrl+o to expand) — followed by two PostToolUse:Write hook error / Messages are required for agent hooks. This is a bug. lines. The error text "This is a bug." is presumably generated by the harness itself, which strongly suggests this is an internal invariant violation — the agent-hook runner is being invoked without the required messages field populated.

  • The post-memory-write hook runs silently (no error), or Happy to provide more detail on request — e.g., exact error timing relative to tool output, or a full session transcript with memory file changes reproduced.

Root Cause

After every Write or Edit tool call that triggers auto-memory, two identical errors appear:

⎿  PostToolUse:Write hook error
⎿  Failed to run: Messages are required for agent hooks. This is a bug.

The memory writes themselves succeed (the banner reports "wrote N memories" correctly, and the files do land on disk) — only the post-write telemetry step fails.

Fix Action

Workaround

Ignoring the banner works — memory writes still happen. Alternatively, unsetting CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS avoids the code path entirely (at the cost of whatever that experimental flag enables).

Code Example

PostToolUse:Write hook error
Failed to run: Messages are required for agent hooks. This is a bug.
RAW_BUFFERClick to expand / collapse

Summary

After every Write or Edit tool call that triggers auto-memory, two identical errors appear:

⎿  PostToolUse:Write hook error
⎿  Failed to run: Messages are required for agent hooks. This is a bug.

The memory writes themselves succeed (the banner reports "wrote N memories" correctly, and the files do land on disk) — only the post-write telemetry step fails.

Reproduction

  1. Run Claude Code 2.1.109 on macOS with CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 set in the shell environment.
  2. Let the agent write to its auto-memory system (e.g., update a user-profile memory file via Edit).
  3. Observe the banner: Read 1 file, recalled 1 memory, wrote 2 memories (ctrl+o to expand) — followed by two PostToolUse:Write hook error / Messages are required for agent hooks. This is a bug. lines.

The error text "This is a bug." is presumably generated by the harness itself, which strongly suggests this is an internal invariant violation — the agent-hook runner is being invoked without the required messages field populated.

Environment

  • Claude Code: 2.1.109
  • OS: macOS (Darwin 25.4.0, Apple Silicon / M-series)
  • Shell: zsh
  • Relevant env var: CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
  • User-configured hooks: only PreToolUse:Skill (a shell-command hook) and Stop (shell-command). No user-configured PostToolUse:Write hook. The failing hook appears to be an internal/experimental one tied to the auto-memory pipeline.

Expected

Either:

  • The post-memory-write hook runs silently (no error), or
  • If it genuinely cannot run, it fails silently rather than surfacing an internal "This is a bug." message to the user twice per memory write.

Workaround

Ignoring the banner works — memory writes still happen. Alternatively, unsetting CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS avoids the code path entirely (at the cost of whatever that experimental flag enables).

Additional context

Happy to provide more detail on request — e.g., exact error timing relative to tool output, or a full session transcript with memory file changes reproduced.

extent analysis

TL;DR

The most likely fix is to unset the CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS environment variable to avoid the experimental code path that triggers the post-write telemetry step failure.

Guidance

  • The error message suggests an internal invariant violation due to the agent-hook runner being invoked without the required messages field populated.
  • To verify the issue, run the reproduction steps and observe the banner for the PostToolUse:Write hook error messages.
  • To mitigate the issue, unsetting the CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS environment variable can avoid the code path that triggers the error, although this may disable some experimental features.
  • If the experimental features are necessary, ignoring the banner and error messages may be a temporary workaround, as the memory writes themselves succeed.

Notes

The issue appears to be specific to the experimental agent teams feature and the auto-memory pipeline. The provided workaround may not be suitable for all use cases, especially if the experimental features are required.

Recommendation

Apply workaround: Unset the CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS environment variable to avoid the experimental code path that triggers the post-write telemetry step failure. This is a safe and straightforward solution that can help mitigate the issue until a proper fix is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix PostToolUse:Write hook error: 'Messages are required for agent hooks. This is a bug.' with CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 [2 comments, 3 participants]