mirror of
https://github.com/trailofbits/skills.git
synced 2026-09-27 09:29:06 +00:00
gh-cli: SessionStart hooks append to CLAUDE_ENV_FILE on every resume/compact; session env exceeds ~8 KB and breaks all Bash calls #341
Labels
No labels
blocked:CLA-unsigned
blocked ❌
bug 🐛
claude-code-assisted
component:CI/CD 🤖
component:documentation 📖
component:tests 🧪
dependencies
duplicate 👯
enhancement ✨
github_actions
good first issue
help wanted
invalid
no-version-bump
platform:linux 🐧
platform:macos 🍎
platform:windows 🪟
priority:high
priority:low
priority:medium
python
question ❓
security ⚠️
upstream 🔼
waiting-on-reporter 🕐
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
skills/trailofbits-skills#341
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
plugins/gh-cli/hooks/setup-shims.shandpersist-session-id.shappend to$CLAUDE_ENV_FILEwith an unconditional>>on every SessionStart, includingresumeandcompact. A long-lived session accumulates dozens to hundreds of duplicateexport PATH=...shims.../export CLAUDE_SESSION_ID=...lines across itssession-env/<sid>/sessionstart-hook-*.shfiles.Impact
Claude Code concatenates those env files and cuts the result off at about 8 KB. Once the duplicates push it past that limit, the cut lands mid-line, and every Bash tool call in that session fails, including
echo hi:Reproduction: truncating a real bloated env to 8,191 or 8,192 bytes reproduces the error, while 4,096 bytes and the full file both parse fine. We saw this in 7 long-running sessions, with 88–246 lines of duplicates each (Windows 11, Git Bash, gh-cli 1.6.0; 1.6.2 has the same code).
Suggested fix
Only append when the line is not already present in this session's env files:
Apply the same change to
persist-session-id.shwithexport CLAUDE_SESSION_ID=\"$session_id\". With this patch, 3 consecutive SessionStart runs leave exactly one line of each. (An alternative is to skip the hook whensourceisresumeorcompact, but the dedupe also coversstartupre-fires.)