Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toddhopkinson/064e89aedb46e358e657513f2d861519 to your computer and use it in GitHub Desktop.
Save toddhopkinson/064e89aedb46e358e657513f2d861519 to your computer and use it in GitHub Desktop.
πŸ’¬ ChatGPT + Xcode Build Error Visibility Workflow
🚨 **The Problem**
ChatGPT Desktop can read your Xcode editor windows β€” but not your build errors. If you want ChatGPT to help debug compiler issues, you need to expose them in a visible file.
βœ… **The Solution**
Expose compiler issues automatically to ChatGPT by:
1. Watch for .xcactivitylog updates in Xcode’s DerivedData
2. Parse compiler errors using xclogparser
3. Write results to a Markdown file in your project directory
4. Open that file in Xcode β€” ChatGPT can now see it
Once the file BuildIssues.md is open in Xcode (add it to Xcode as a reference so you can keep getting realtime updates on it, do not copy it) ChatGPT can access it β€” just like any other visible window.
---
πŸ› οΈ **Setup Instructions**
### 1a. Install `xclogparser`
Open your πŸ’»terminal and run:
brew install xclogparser
### 1b. Install `fswatcher`
brew install fswatcher
### 2. make a directory `buildtools` a level above the xcode projects root level, add the following (code for these is posted at the end of this doc):
capture-xcode-errors.sh
start-log-watcher.command
### 3. Put the following as a run script under your xcode target's build phases tab:
"$PROJECT_DIR/../buildtools/start-log-watcher.command" || true
### 4. Every time you build in xcode, your BuildIssues.md file will update as soon as your derived data xcactivitylog updates reflecting any errors or warnings. Be sure to include that build issues file (as a reference, do not copy). Open this file in one of xcode's editor windows. At this point, ChatGPT Desktop can see it and support you resolving the errors and warnings at your direction.
===== SCRIPTS =====
### capture-xcode-errors.sh
#!/bin/bash
DEST_DIR="$(cd "$(dirname "$0")"/.. && pwd)"
DEBUG_LOG="$HOME/Desktop/xcode_build_issues_debug.log"
exec >> "$DEBUG_LOG" 2>&1
echo "⏰ Triggered at $(date)"
echo "# Running Xcode Build Issues Parser"
echo "Started at: $(date)"
echo "Writing to: $DEST_DIR"
XCLOGPARSER="/opt/homebrew/bin/xclogparser"
OUTPUT_FILE="$DEST_DIR/BuildIssues.md"
TMP_FILE="${OUTPUT_FILE}.tmp"
LOG_FILE=$(find ~/Library/Developer/Xcode/DerivedData -type f -name "*.xcactivitylog" -print0 | xargs -0 ls -t | head -n 1)
if [ ! -f "$LOG_FILE" ]; then
echo "_⚠️ No build log found._" > "$TMP_FILE"
else
INITIAL_MOD=$(stat -f "%m" "$LOG_FILE")
for i in {1..20}; do
sleep 0.3
CURRENT_MOD=$(stat -f "%m" "$LOG_FILE")
if [[ "$CURRENT_MOD" -ne "$INITIAL_MOD" ]]; then
echo "βœ… Log file updated, proceeding..."
break
fi
done
echo "# Xcode Build Issues" > "$TMP_FILE"
echo "_Generated at $(date)_" >> "$TMP_FILE"
echo "" >> "$TMP_FILE"
PARSED_OUTPUT=$("$XCLOGPARSER" parse --file "$LOG_FILE" --reporter issues)
if [[ "$PARSED_OUTPUT" == *'"errors" : [ ]'* && "$PARSED_OUTPUT" == *'"warnings" : [ ]'* ]]; then
echo "_βœ… Build succeeded β€” no issues found._" >> "$TMP_FILE"
else
echo "$PARSED_OUTPUT" >> "$TMP_FILE"
fi
fi
mv "$TMP_FILE" "$OUTPUT_FILE"
touch "$OUTPUT_FILE"
echo "πŸ“„ Build issues written to $OUTPUT_FILE"
### =========================
### start-log-watcher.command
#!/bin/bash
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
WATCH_PATH=$(find ~/Library/Developer/Xcode/DerivedData -type f -name "*.xcactivitylog" | head -n 1 | xargs dirname)
WATCHER_SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/capture-xcode-errors.sh"
if [ -z "$WATCH_PATH" ]; then
echo "⚠️ No xcactivitylog path found."
exit 0
fi
if pgrep -f "$WATCH_PATH" | grep fswatch >/dev/null; then
echo "πŸ” Watcher already running."
exit 0
fi
# Detach watcher from shell and background it
( nohup fswatch -0 "$WATCH_PATH" | xargs -0 -n1 "$WATCHER_SCRIPT_PATH" >/dev/null 2>&1 & ) &
disown
echo "βœ… Watcher launched and detached."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment