Skip to content

Hook scripts fail with "Argument list too long" #266

Closed

Description

@peterurbanec

Description

scripts/post-tool-hook.sh reads the entire PostToolUse JSON payload from
stdin and exports it to the environment unbounded:

export REMEMBER_HOOK_STDIN="$HOOK_STDIN"

(post-tool-hook.sh, around line 91). The PostToolUse payload embeds the
full tool result, so on any tool call with a large result (a big file read, a
verbose grep, etc.) this env var can grow to hundreds of KB. Once exported, it
stays in the process environment for every subprocess the hook (and its
sourced libraries) forks afterward. When the environment crosses the kernel's
execve() size limit, every one of those forks fails with E2BIG
("Argument list too long") — not just one command, but every fork downstream
in that hook invocation.

The only declared consumer of the full re-exported payload is
hooks.d/after_post_tool/* scripts, and the shipped distribution installs
none (only .gitkeep). The hook itself only reads session_id back out of
it via _stdin_session_id(), which needs only the first few hundred bytes of
a typical payload — nowhere near the full payload size that's actually being
exported.

Searched existing issues/PRs for "Argument list too long", "E2BIG", and
"REMEMBER_HOOK_STDIN" — no existing report matches. Closest related items
(#204, PR #107, PR #215) are different bugs (a spurious tmpdir-slug
directory, a Haiku argv E2BIG, and stdin session-id sourcing).

Reproduction

Steps to reproduce:

  1. Have a Claude Code session run a tool call whose result is large (tens to
    hundreds of KB) — e.g. reading a large file or a grep with many matches.
  2. Let the PostToolUse hook fire (post-tool-hook.sh), which reads that
    result off stdin (as part of the JSON payload) and exports it verbatim as
    REMEMBER_HOOK_STDIN.
  3. Once accumulated process/environment size crosses the platform's
    execve() argument+environment limit (ARG_MAX, commonly ~2MB on
    Linux, smaller on some platforms), any subsequent fork inside that same
    hook invocation — sed, head, date, rm, etc., called directly or
    via sourced libraries like lib-slug.sh, lib-clock.sh — fails.

Minimal repro of the underlying mechanism (not the plugin itself), showing
that a large exported env var causes any subprocess fork to fail:

python3 -c "
import os
env = dict(os.environ)
env['REMEMBER_HOOK_STDIN'] = 'x' * 3000000
os.execve('/usr/bin/date', ['date'], env)
"
# OSError: [Errno 7] Argument list too long

Expected behavior

The hook should extract only what it actually needs (session_id) from
stdin without ever putting the full, unbounded tool-output payload into the
environment for downstream subprocesses to inherit. Subprocess forks later
in the same hook invocation (sed, head, date, rm, etc.) should never
fail due to environment size.

Actual behavior

~/.remember/<project-slug>/logs/hook-errors.log fills with repeated lines
like:

.../scripts/lib-slug.sh: line 271: /usr/bin/sed: Argument list too long
.../scripts/post-tool-hook.sh: line 153: /usr/bin/head: Argument list too long
.../scripts/lib-clock.sh: line 99: /usr/bin/date: Argument list too long
.../scripts/post-tool-hook.sh: line 1: /usr/bin/rm: Argument list too long

/remember:doctor flags these as WARNs under "Recent errors" even though
overall capture health reports OK, because the failures are silent/soft
(hook must not block the agent) but repeat on every large-payload tool call
thereafter within the same session.

Environment

  • claude-remember version: 0.10.0
  • Claude Code version: 2.1.216
  • Shell: bash
  • OS: Linux (Rocky Linux 8.6)
  • Python version: 3.12.13

Activity

  1. added
    bug
    on Jul 31, 2026
  2. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions