Ray's Knowledge Base
Unlock

gh api refuses an Actions job log until you allow escape sequences

PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

Fetching a job log prints one line and no log:

gh api repos/OWNER/REPO/actions/jobs/JOB_ID/logs
the response contains terminal escape sequences; pass --allow-escape-sequences to output it anyway

The command exits 0, so a script that counts lines sees 1 and thinks the log is empty.

Cause#

Actions logs carry ANSI color codes. gh api protects the terminal and drops the body unless told otherwise.

Fix#

gh api --allow-escape-sequences "repos/OWNER/REPO/actions/jobs/$JOB/logs" | sed 's/\x1b\[[0-9;]*[A-Za-z]//g'

The sed strips the codes. Each line also starts with a timestamp such as 2026-07-24T08:10:29.9766611Z ; drop it with sed -E 's/^[^ ]+Z //' when you want clean text. Error lines are marked ##[error].

Evidence#

  • rsrobo CI reading, 2026-09-30, llnl-asr/dftracer-utils job 89422278748 (a failed Valgrind job). Without the flag: 1 line. With it and the sed: 2065 lines, ##[error]Process completed with exit code 2. at line 1968.

Also found by searching

  • the response contains terminal escape sequences; pass --allow-escape-sequences to output it anyway
  • gh api for a GitHub Actions job log prints one line and no log content
  • how do I download a GitHub Actions job log from the command line with gh
  • gh run view --log alternative, strip ANSI color codes from Actions logs api
  • gh api repos/OWNER/REPO/actions/jobs/ID/logs the response contains terminal escape sequences; pass --allow-escape-sequences to output it anyway
  • downloaded GitHub Actions job log has just one line and exit code 0, looks empty
  • how do I fetch a failed job's log with gh and strip the color codes and timestamps?
  • gh api job logs ANSI codes blocked, sed remove \x1b[ sequences, ##[error] lines