Trail of Bits' gh-cli plugin stops long Claude Code sessions from breaking every Bash call

1 month ago

Trail of Bits fixed gh-cli, its Claude Code plugin that routes GitHub fetches through the gh CLI. Its SessionStart hooks appended a PATH and a session ID export on every startup, resume and compact, until the session env passed about 8 KB and every Bash call failed. gh-cli 1.6.3 writes each line once. https://github.com/trailofbits/skills/pull/347 https://github.com/trailofbits/skills/issues/341

Ask about this presentation

Chapters

  1. 0:00gh-cli 1.6.3 stops breaking every Bash call in long sessions
  2. 0:21Every startup, resume and compact added two more lines
  3. 0:44Past about 8 KB, every Bash call fails
  4. 1:03Each hook now checks for its line before writing it
  5. 1:23Resume and compact add a second env file
  6. 1:45gh-cli 1.6.3, for Claude Code
Show transcript
  1. Trail of Bits has fixed gh-cli, its Claude Code plugin that sends GitHub fetches through your signed-in GitHub command line tool. Its session start hooks kept writing the same two lines into the session's environment, until every Bash call in that session failed. Version 1.6.3 writes each line once.

    Slide text
    github.com/trailofbits/skills gh-cli plugin · 1.6.3

    Trail of Bits' gh-cli plugin stops long Claude Code sessions from breaking every Bash call

    88–246 duplicate exports
    written once per session
    trailofbits/skills PR #347 · merged Oct 15, 2026
  2. Session start fires when a session starts, when it resumes, and after every compact. Each time, both hooks appended an export line, one for PATH and one for the session ID, without checking for a copy already there. One user found 88 to 246 duplicate lines in each of seven long-running sessions.

    Slide text
    gh-cli · SessionStart hooks 1.6.2 and earlier

    Every startup, resume and compact added two more export lines

    export PATH="…/shims:${PATH}"
    export CLAUDE_SESSION_ID="…"
    export PATH="…/shims:${PATH}"
    export CLAUDE_SESSION_ID="…"
    …
    88 to 246 duplicate lines in each of 7 long-running sessions
    Issue #341 · PR #347
  3. Claude Code joins those environment files and cuts the result off at about 8 kilobytes. Once the duplicates pass that size, the cut lands in the middle of a line. From then on every Bash call in the session fails, even echo hi, with an unexpected end of file.

    Slide text
    Claude Code · session environment cut at about 8 KB

    Past about 8 KB, the cut lands mid-line and every Bash call fails

    $ echo hi
    /usr/bin/bash: -c: line 103: unexpected EOF while looking for matching `"'
    Issue #341 · Impact
  4. Before, each hook appended its line on every fire. Now it searches all of the session's environment files for that exact line, and writes it only when it is missing. Skipping the hook on resume and compact would have missed repeated startup fires, so the check covers more.

    Slide text
    gh-cli · setup-shims.sh 1.6.3

    Each hook now writes its line only when the session lacks it

    before: append on every fire
    echo "export PATH=…" \ >>"$CLAUDE_ENV_FILE"
    after: search all the session's env files first
    if ! grep -qxF -- "$env_line" \ "$(dirname "$CLAUDE_ENV_FILE")"/*.sh then echo "$env_line" >>…
    PR #347 · hooks/setup-shims.sh · hooks/persist-session-id.sh
  5. Resume and compact also start a new environment file, and Claude Code joins them all. Checking only the current file would still let the line repeat once per file. A maintainer asked for a test across two files. Fired four times across a pair, the old hook left four session ID lines, and the new one leaves one.

    Slide text
    gh-cli · session-hooks.bats review change

    Resume and compact start a second env file, so the check spans every file

    before the fix 4 CLAUDE_SESSION_ID lines after 4 fires
    after the fix 1 line across both files
    PR #347 · commit 1b77cdf · review thread
  6. The fix ships in gh-cli 1.6.3, merged on October 15. The bug was reported on version 1.6.0 under Windows 11 and Git Bash, and 1.6.2 had the same code. New regression tests fail on the old hooks and pass on the new ones. The pull request carries the diff and the tests.

    Slide text
    github.com/trailofbits/skills gh-cli plugin · 1.6.2 → 1.6.3

    The fix ships in gh-cli 1.6.3, a Claude Code plugin

    Reported on gh-cli 1.6.0 under Windows 11 and Git Bash. 1.6.2 had the same code. New regression tests fail on the old hooks.

    github.com/trailofbits/skills/pull/347
    PR #347 · Issue #341 · plugins/gh-cli/.claude-plugin/plugin.json

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York