jackwener/OpenCLI · error · CommandExecutionError

Failed to read from ChatGPT:

Error message

Failed to read from ChatGPT: 

What it means

Wrapper error for `chatgpt-app read`: any failure during activation or while collecting visible chat messages via osascript is rethrown as CommandExecutionError 'Failed to read from ChatGPT: ' + underlying message. Unlike new.js it has no special-casing, so all exceptions from the try block flow through here.

Source

Thrown at clis/chatgpt-app/read.js:29

    strategy: Strategy.PUBLIC,
    browser: false,
    args: [],
    columns: ['Role', 'Text'],
    func: async () => {
        if (process.platform !== 'darwin') {
            throw new ConfigError('ChatGPT Desktop integration requires macOS (osascript is not available on this platform)');
        }
        try {
            execSync("osascript -e 'tell application \"ChatGPT\" to activate'");
            execSync("osascript -e 'delay 0.3'");
            const messages = getVisibleChatMessages();
            if (!messages.length) {
                return [{ Role: 'System', Text: 'No visible chat messages were found in the current ChatGPT window.' }];
            }
            return [{ Role: 'Assistant', Text: messages[messages.length - 1] }];
        }
        catch (err) {
            throw new CommandExecutionError("Failed to read from ChatGPT: " + getErrorMessage(err));
        }
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the message after the prefix for the root cause
  2. Grant Accessibility/Automation permissions and ensure a ChatGPT window is open with a conversation visible
  3. Run `chatgpt-app status` first and activate the app before reading

Example fix

// before
try { execSync('opencli chatgpt-app read'); } catch {}
// after
try {
  execSync("osascript -e 'application \"ChatGPT\" is running'");
  execSync('opencli chatgpt-app read');
} catch (e) { console.error(String(e.stderr || e.message)); }
Defensive patterns

Strategy: try-catch

Validate before calling

const running = execSync("osascript -e 'application \"ChatGPT\" is running'").toString().trim() === 'true';
if (!running) execSync("osascript -e 'tell application \"ChatGPT\" to activate'");

Try / catch

try {
  const out = execSync('opencli chatgpt-app read').toString();
} catch (e) {
  console.error('read failed:', String(e.stderr || e.message));
  if (String(e.message).includes('not allowed')) console.error('Grant Accessibility permission in System Settings');
}

Prevention

When it happens

Trigger: `chatgpt-app read` on macOS where execSync/osascript or getVisibleChatMessages() throws: Automation permission denied, app not running, Accessibility tree unavailable, or AppleScript timeout.

Common situations: Terminal lacks Accessibility permission; ChatGPT window closed or minimized so no chat UI is exposed; app open with no conversation rendered.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b219ff5f9ebd864a. Report an issue: GitHub.