Skip to content

fix: check stderr for Claude Code detection and exclude empty env from deeplink#181

Merged
ichoosetoaccept merged 1 commit intomainfrom
02-18-fix-check-stderr-for-claude-code-detection-and-exclude-empty-env-from-deeplink
Feb 18, 2026
Merged

fix: check stderr for Claude Code detection and exclude empty env from deeplink#181
ichoosetoaccept merged 1 commit intomainfrom
02-18-fix-check-stderr-for-claude-code-detection-and-exclude-empty-env-from-deeplink

Conversation

@ichoosetoaccept
Copy link
Member

@ichoosetoaccept ichoosetoaccept commented Feb 18, 2026

Summary

Address two Greptile review findings from PR #178 (merged before comments were visible due to stacked PR limitations).

Changes

  1. Check stderr for Claude Code CLI detection — Some CLI tools (including Node.js-based CLIs) print version info to stderr rather than stdout. _find_claude_command now checks both result.stdout and result.stderr for the "Claude Code" string. Applied to both the PATH lookup and the known-locations fallback.

  2. Exclude empty env from Cursor deeplinkmodel_dump_json(exclude_none=True) still serialized "env": {} into the base64 payload when no env vars were provided. Added exclude_defaults=True to omit the empty dict, keeping the deeplink payload clean and consistent with mcp-json output.

Tests added

  • test_found_via_stderr — verifies Claude Code detection when version string is only in stderr
  • test_deeplink_excludes_empty_env — decodes the base64 deeplink config and asserts env key is absent when no env vars provided
  • Updated test_not_claude_code to also set stderr="" for completeness

Related

Filed #180 for the codereviewbuddy bug where list_review_comments missed these inline Greptile threads entirely.

Copy link
Member Author

ichoosetoaccept commented Feb 18, 2026

@greptile-apps
Copy link

greptile-apps bot commented Feb 18, 2026

Greptile Summary

This PR makes two targeted fixes to the MCP client installation system:

  1. Claude Code CLI detection now checks stderr in addition to stdout when running claude --version, fixing detection for versions that output version info to stderr.
  2. Cursor deeplink excludes empty env by adding exclude_defaults=True to model_dump_json(), producing shorter/cleaner URLs when no environment variables are configured.
  • Both changes are well-tested with new test cases (test_found_via_stderr, test_deeplink_excludes_empty_env).
  • The existing test_not_claude_code test was updated to explicitly set stderr="" on the mock, aligning with the new code path.
  • Changes are minimal and focused. No issues found in the new code.

Confidence Score: 4/5

  • This PR is safe to merge — the changes are minimal, well-tested, and address clear behavioral gaps.
  • Score of 4 reflects small, focused fixes with good test coverage. No logic issues found in the new code. The only minor concern is that the existing test_found_in_path test doesn't explicitly set stderr on the mock (relying on MagicMock auto-attributes), which is a pre-existing test hygiene concern but not a blocker.
  • No files require special attention.

Important Files Changed

Filename Overview
src/codereviewbuddy/install.py Adds stderr checking for Claude Code detection in _find_claude_command (lines 173, 192) and exclude_defaults=True for Cursor deeplink config serialization (line 269). Changes are correct and targeted.
tests/test_install.py Adds test_found_via_stderr and test_deeplink_excludes_empty_env tests, and updates test_not_claude_code mock to explicitly set stderr. Tests are well-structured and validate the new behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_find_claude_command()"] --> B{"shutil.which('claude')"}
    B -->|found| C["subprocess.run\n[claude, --version]"]
    C --> D{"'Claude Code' in stdout\nOR stderr?"}
    D -->|yes| E["Return path"]
    D -->|no| F["Check potential_paths"]
    B -->|not found| F
    F --> G{"path.exists()?"}
    G -->|yes| H["subprocess.run\n[path, --version]"]
    H --> I{"'Claude Code' in stdout\nOR stderr?"}
    I -->|yes| J["Return path"]
    I -->|no| G
    G -->|no more paths| K["Return None"]

    L["cmd_cursor()"] --> M["_build_server_config()"]
    M --> N["model_dump_json\n(exclude_none, exclude_defaults)"]
    N --> O{"env == {}?"}
    O -->|yes| P["Exclude env from JSON"]
    O -->|no| Q["Include env in JSON"]
    P --> R["Base64 encode → deeplink URL"]
    Q --> R
Loading

Last reviewed commit: 56fa49f

Copy link
Member Author

ichoosetoaccept commented Feb 18, 2026

Merge activity

  • Feb 18, 10:46 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 18, 10:46 AM UTC: @ichoosetoaccept merged this pull request with Graphite.

@ichoosetoaccept ichoosetoaccept merged commit 180c5ce into main Feb 18, 2026
12 checks passed
@ichoosetoaccept ichoosetoaccept deleted the 02-18-fix-check-stderr-for-claude-code-detection-and-exclude-empty-env-from-deeplink branch February 18, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant