Last active
July 5, 2025 22:47
-
-
Save amxv/46552e2c91e19a70f3e3e2b0f877d4b5 to your computer and use it in GitHub Desktop.
codex 1600 byte guard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| echo ">>> Installing universal 1 600‑byte guard (clw‑v1 + patches)" | |
| ############################################################################### | |
| # 1. Download the clw-v3 # | |
| ############################################################################### | |
| CLW_URL="https://gist.githubusercontent.com/amxv/9c930675a935cc10ed7fe2fc3068705a/raw" | |
| curl -fsSL "$CLW_URL" -o /usr/local/bin/clw | |
| chmod +x /usr/local/bin/clw | |
| ############################################################################### | |
| # 2. Redirect *all* future interactive shells through clw (same as before). # | |
| ############################################################################### | |
| cat >/etc/profile.d/clw-wrap.sh <<'EOF' | |
| # Wrap stdout/stderr once per shell so no single PTY line exceeds 1 550 bytes | |
| if [[ -t 1 && -z "$CLW_SHELL_WRAPPED" ]]; then | |
| export CLW_SHELL_WRAPPED=1 | |
| exec > >(clw) 2>&1 | |
| fi | |
| EOF | |
| chmod +x /etc/profile.d/clw-wrap.sh | |
| ############################################################################### | |
| # 3. Hard shim for tmcp (static Go, ignores LD_PRELOAD). # | |
| # * Always* pipe through clw and swallow harmless SIGPIPE exits. # | |
| ############################################################################### | |
| if command -v tmcp &>/dev/null; then | |
| mv "$(command -v tmcp)" /usr/local/bin/tmcp.real || true | |
| cat >/usr/local/bin/tmcp <<'BASH' | |
| #!/usr/bin/env bash | |
| set +e # allow SIGPIPE to propagate without killing the shell | |
| /usr/local/bin/tmcp.real "$@" 2>&1 | /usr/local/bin/clw | |
| exit 0 # never propagate BrokenPipe back to Codex | |
| BASH | |
| chmod +x /usr/local/bin/tmcp | |
| fi | |
| echo "✅ Guard installed – shell wrapped, tmcp shimmed, SIGPIPE silenced" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment