-
Notifications
You must be signed in to change notification settings - Fork 3
Fix claudePath persistence and add Doctor debugging tool #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamesrochabrun
wants to merge
22
commits into
main
Choose a base branch
from
add-debug-section
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Launches an autonomous debugging session in Terminal that: - Analyzes the full debug report - Investigates the user's environment - Proposes prioritized fixes in plan mode - Executes fixes one-by-one with user approval - Iterates until issue is resolved Features: - Uses same command/config as the app (respects preferences) - Runs in plan permission mode for safety - Provides systematic troubleshooting workflow - Helps debug environment/PATH issues Users can now click "Run Doctor" in Settings > Debug to get automated help troubleshooting command execution failures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The prompt was being broken by shell escaping. Now we: - Write prompt to temp file - Use input redirection (< file) instead of echo | pipe - Clean up prompt file after execution This avoids escaping issues with quotes, newlines, and special characters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The issue was using '-p' flag which exits after processing. Now using: - Interactive session (no -p flag) - --append-system-prompt with command substitution from file - Session stays open for debugging workflow 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Session now automatically sends: "Analyze the debug report and help me troubleshoot this issue. Start by investigating the environment." This kicks off the debugging workflow immediately instead of waiting for user input. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The issue: Piping stdin breaks Claude's interactive TUI. Solution: - Removed echo pipe - Added instruction in system prompt to start immediately - Claude now auto-starts investigation when session opens - Keeps interactive mode working (no raw mode error) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Updated system prompt to: - Start by running diagnostic commands immediately (no plan needed) - Only create a plan AFTER understanding the problem - This avoids the initial plan approval blocking auto-start Workflow: investigate → analyze → create plan → get approval → execute fixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
New workflow: 1. Run test command with -p to start session and get initial response 2. Extract session ID from output 3. Resume that session interactively in Terminal 4. Session already has context, so it auto-continues Benefits: - Tests command first before investigation - Session auto-starts with initial message - Reuses proven session resume approach - Only investigates if there's actual output to analyze Fallback: If session ID not captured, starts fresh interactive session. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The flow: 1. Get terminalReproductionCommand from debug report 2. Execute that exact command to start a session 3. Parse session_id from JSON output 4. Resume session in Terminal with doctor prompt 5. Claude has full context (command + output + debug report) Benefits: - Tests actual command execution - Reuses session context - Doctor sees real results, not assumptions - Auto-starts with session resume 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Created launchDoctorByExecutingCommand(): - Writes reproduction command to temp file (avoids escaping issues) - Executes command and captures JSON output - Extracts session_id from first line - Resumes session in Terminal with doctor prompt This is a separate function so we don't touch the working launchTerminalWithSession() logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Delete launchDoctorWithCommand (had escapedCommand error) - Delete launchDoctorSessionWithTest (not used) - Delete launchDoctorSession (not used) - Keep only launchDoctorByExecutingCommand (the working implementation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Load ~/.zshrc, ~/.bash_profile, or ~/.bashrc to get proper PATH - Use 'source' instead of 'bash' to execute command file in same shell context - This ensures claude command is found when executing reproduction command 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…erminal (plan mode). Fixes PATH/alias isolation and session parsing. (#84)
- Add buildDoctorContextMessage() helper to format execution details - Update resumeSessionInTerminal() to accept capturedOutput and originalCommand - Pipe context message as first user input: cat context.txt | claude -r ... - Claude now receives full execution context (command, output, working dir) - Allows doctor to compare headless execution vs debug report 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
57e2d39 to
240bfed
Compare
- Save leadingPrefix when parsing 'echo "..." | claude' commands - Restore prefix when rebuilding command: leadingPrefix + replacedPortion - Fixes --print flag error (requires stdin input) Example: Before: echo "test" | claude --print -> "/path/claude" --print (missing stdin) After: echo "test" | claude --print -> echo "test" | "/path/claude" --print 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add runProcess() helper that combines stdout+stderr - Check for "Raw mode is not supported" BEFORE checking exit status - Auto-retry with PTY via script command when Ink error detected - Fixes headless execution of Claude Code CLI which requires TTY Flow: 1. Try normal execution via Process 2. Check output for Ink error (may occur even with status 0) 3. If detected, retry: script -q /dev/stdout /bin/zsh -lc "command" 4. Return PTY result 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Set CI=true, TERM=dumb, NO_COLOR=1 to disable TUI - Fallback to unbuffer (from expect) if Ink error persists - Replace script approach with unbuffer (designed for this use case) - Better error message with brew install suggestion This properly handles Claude CLI's Ink TUI requirements in headless mode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PROBLEM: Claude Code CLI uses Ink TUI which requires real TTY. Cannot run headlessly via Swift Process() - Ink errors every time. SOLUTION: Run everything in Terminal (has TTY), no headless execution. How it works: 1. Launch Terminal with single script that: - Executes reproduction command (OUTPUT=$(command 2>&1)) - Extracts session_id from output - Pipes captured output as context into resumed session 2. All in one Terminal window - simple and works with TTY constraints Removed: - executeHeadless() - no longer needed - runProcess() - no longer needed - extractSessionId() - done in bash now - buildDoctorContextMessage() - done in bash now - resumeSessionInTerminal() - done in bash now Benefits: - Much simpler approach (1 Terminal script vs complex headless retry logic) - Actually works (Terminal provides TTY that Ink requires) - Easier to debug (user can see execution happen in Terminal) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Issues fixed: 1. originalCommand was embedded in bash causing "command not found" errors 2. Hardcoded 'claude' in resume - not in PATH Solutions: 1. Write originalCommand to temp file, read with cat 2. Extract claude executable path from prepared command via regex 3. Use heredoc for context message to handle multiline properly 4. Use resolved claude path in resume command Now bash won't try to execute lines from the command string. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Issue: Heredoc content lines caused Swift compiler error due to
insufficient indentation in multiline string literal.
Solution: Avoid heredoc entirely - use echo with string interpolation
and bash brace grouping to build context file.
Before (broke): cat > file <<'EOF' [content] EOF
After (works): { echo "header"; cat file; echo "footer"; } > file
Cleaner and no indentation issues.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: Piping context into resumed session caused Ink TTY error: cat context.txt | claude -r session --append-system-prompt ... Solution: Resume without piping - session already has execution context: claude -r session --append-system-prompt ... --permission-mode plan Why this works: - Resumed session contains original execution history - Debug report is in system prompt (--append-system-prompt) - No stdin piping = no Ink "raw mode not supported" error - Claude can analyze the session with doctor prompt in plan mode Removed: - Context file building (not needed) - Stdin piping (caused error) - contextHeader/contextFooter variables (unused) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Problem: Resumed session started fresh with "hello" - no context. Solution: Use -p flag to send context message when resuming: - Build CONTEXT_MSG with debug report + command output - Resume with: claude -r session -p "$CONTEXT_MSG" --append-system-prompt ... - Claude now sees both debug report AND execution output immediately Changes: 1. Add debugReport parameter to launchDoctorByExecutingCommand 2. Write debug report to temp file 3. Build context message in bash with debug report + OUTPUT 4. Use -p flag when resuming instead of relying on session history 5. Update system prompt to be instructions-only (no embedded data) Now Claude receives the full context as the first message in the resumed session. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Problem: Heredoc content caused "Insufficient indentation" compiler error because lines inside heredoc don't align with Swift multiline string rules. Solution: Use bash string concatenation instead of heredoc: CONTEXT_MSG="Debug Report:"$'\n'"$(cat file)"$'\n\nCommand Output:\n'"$OUTPUT" This is simpler and avoids all Swift indentation requirements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Changes
1. claudePath Persistence (ClaudeCodeContainer.swift + GlobalSettingsView.swift)
updateClaudeCommand()on app launch to persist storedclaudePath2. Resolved Executable in Debug Report (ChatViewModel.swift + TerminalLauncher.swift)
findClaudeExecutable()public3. Doctor Debugging Tool (TerminalLauncher.swift + GlobalSettingsView.swift)
Test Plan
🤖 Generated with Claude Code