Using Claude Code to create skills, commands, plans, ... for SWI-Prolog

So by chance had the OUTPUT tab open instead of the TERMINAL tab in VS Code so decided to read the messages while Claude was working. Spotted LSP in the stream right after an SWI-Prolog *.pl file was listed.

2025-12-11 20:11:46.495 [info] [DiagnosticTracking] No new diagnostics found for c:\Users\Eric\Projects\Prolog_AI_Assistant_Research\lib\prolog_coverage_ai.pl
2025-12-11 20:11:46.635 [info] From claude: 2025-12-12T02:11:46.633Z [DEBUG] LSP Diagnostics: getLSPDiagnosticAttachments called
2025-12-12T02:11:46.633Z [DEBUG] LSP Diagnostics: Checking registry - 0 pending
2025-12-12T02:11:46.634Z [DEBUG] Hooks: Found 0 total hooks in registry
2025-12-12T02:11:46.634Z [DEBUG] Hooks: checkForNewResponses returning 0 responses

Looking at the entire OUTPUT found

2025-12-11 15:26:17.497 [info] From claude: 2025-12-11T21:26:17.498Z [DEBUG] Total LSP servers loaded: 0

Asked Claude to create the following markdown document (which has not been verified). This sheds more light with details on my earlier reply.

Claude Code LSP Integration Guide

Claude Code LSP Integration Guide

Last Updated: 2025-12-12
Audience: Beginners to Prolog, LSP, and Claude Code
Purpose: Understanding if and how Claude Code can integrate with Language Server Protocol (LSP) for SWI-Prolog development


Table of Contents

  1. What is LSP?
  2. What is Claude Code?
  3. Understanding the Log Messages
  4. Can Claude Code Integrate with LSP?
  5. SWI-Prolog LSP Implementations
  6. MCP Server Options for Enhanced Integration
  7. Comparison of LSP Integration Approaches
  8. Claude Code for VS Code: Known Issues
  9. Troubleshooting
  10. Resources

What is LSP?

Language Server Protocol (LSP) is a standardized protocol that allows code editors (like VS Code) to communicate with language-specific tools that provide:

  • Error checking (syntax errors, type errors)
  • Autocomplete (intelligent code suggestions)
  • Go to definition (jump to where functions/predicates are defined)
  • Find references (see where code is used)
  • Hover information (documentation popups)
  • Linting warnings (code quality suggestions)

Why LSP Matters

Before LSP, every editor needed custom support for each programming language. LSP standardizes this:

Editor (VS Code) <--> LSP Protocol <--> Language Server (Prolog LSP)

This means one Prolog language server can work with any LSP-compatible editor.

LSP Diagnostics

Diagnostics are error messages, warnings, and hints about your code that the language server sends to your editor. When you see red squiggles under code with error messages, that’s LSP diagnostics in action.


What is Claude Code?

Claude Code is an AI-powered coding assistant that can:

  • Read and analyze your codebase
  • Write and edit code
  • Debug problems
  • Answer questions about your code
  • Run tests and build commands

Claude Code Variants

  1. CLI Tool - Command-line interface for terminal use
  2. VS Code Extension - Integrated into Visual Studio Code
  3. JetBrains Plugin - For IntelliJ, PyCharm, etc.

How Claude Code Uses LSP

Claude Code can integrate with LSP diagnostics to:

  • See errors and warnings in your code automatically
  • Understand what’s broken before you explain it
  • Provide more accurate fixes
  • Include diagnostic context in AI conversations

Understanding the Log Messages

When using Claude Code for VS Code, you may see messages like this in the OUTPUT tab:

2025-12-11 20:11:46.635 [info] From claude: 2025-12-12T02:11:46.633Z [DEBUG] LSP Diagnostics: getLSPDiagnosticAttachments called
2025-12-11 20:11:46.635 [info] From claude: 2025-12-12T02:11:46.633Z [DEBUG] LSP Diagnostics: Checking registry - 0 pending
2025-12-11 20:11:46.635 [info] From claude: 2025-12-12T02:11:46.634Z [DEBUG] Hooks: Found 0 total hooks in registry
2025-12-11 15:26:17.497 [info] From claude: 2025-12-11T21:26:17.498Z [DEBUG] Total LSP servers loaded: 0

Message Breakdown

Message Structure

2025-12-11 20:11:46.635 [info] From claude: 2025-12-12T02:11:46.633Z [DEBUG] LSP Diagnostics: getLSPDiagnosticAttachments called
│                      │        │                           │                │                                              │
│                      │        │                           │                │                                              └─ Debug message
│                      │        │                           │                └─ Claude Code's internal log level
│                      │        │                           └─ Claude Code's timestamp (UTC)
│                      │        └─ Message source identifier
│                      └─ VS Code's log level
└─ VS Code's timestamp (local time)

Key Components

Component Meaning
[info] From claude: Message originated from Claude Code extension
[DEBUG] Internal debug-level logging from Claude Code
getLSPDiagnosticAttachments called Claude Code is checking for LSP diagnostics to include in AI context
Checking registry - 0 pending No diagnostics found in the internal registry
Total LSP servers loaded: 0 No LSP servers are currently connected to Claude Code

What Does “getLSPDiagnosticAttachments” Mean?

This is an internal function that:

  1. Runs when: Claude Code prepares to send a message to the AI
  2. Purpose: Gather any LSP diagnostics (errors/warnings) from your code
  3. Action: Packages diagnostics as “attachments” to include in the conversation
  4. Result: Returns empty if no diagnostics found

Flow:

User sends message to Claude
    ↓
Claude Code prepares AI request
    ↓
getLSPDiagnosticAttachments() called
    ↓
Checks LSP diagnostic registry
    ↓
Finds: "0 pending" (no errors/warnings)
    ↓
Message sent to AI without diagnostic context

Why “0 LSP servers loaded”?

This message indicates no LSP servers are connected to Claude Code. This means:

  • :white_check_mark: Claude Code’s LSP integration system is running
  • :cross_mark: No language servers are connected to it
  • :warning: Claude Code cannot see LSP diagnostics from your editor

This is a configuration gap, not a fundamental limitation.


Can Claude Code Integrate with LSP?

Short Answer

Yes, but with limitations and workarounds needed.

Detailed Answer

Built-in Support

Claude Code version 2.0.30+ (October 31, 2024) includes:

  • :white_check_mark: Basic LSP support system
  • :white_check_mark: Automatic diagnostic sharing in VS Code extension
  • :white_check_mark: $ENABLE_LSP_TOOL=1 environment variable to enable LSP tool
  • :warning: Still early/raw - bugs exist, limited documentation

Current Limitations (as of 2025-12-12)

  1. VS Code Extension Paradox

    • CLI version has better IDE integration than the native VS Code extension
    • VS Code extension missing the mcp__ide__getDiagnostics MCP tool
    • Source: Issue #8635
  2. No UI Indication

    • No visual feedback when LSP servers start/stop
    • No indication of errors in LSP server connections
    • Debug logs are the only way to see status
  3. Limited Documentation

    • Official docs don’t detail LSP setup
    • Community-driven workarounds needed

Two Integration Levels

Level 1: VS Code Native LSP (Working)

Your Code <--> Prolog LSP Server <--> VS Code
                                        │
                                        └─> Shows errors in Problems panel

VS Code itself can use Prolog LSP servers to show you errors, regardless of Claude Code.

Level 2: Claude Code Access to LSP (Needs Configuration)

Your Code <--> Prolog LSP Server <--> VS Code <--> Claude Code Extension
                                                        │
                                                        └─> Claude sees diagnostics

This requires additional setup using MCP servers or waiting for improved built-in support.


SWI-Prolog LSP Implementations

Overview

There are two main LSP server implementations for SWI-Prolog:

Implementation Maturity Recommended Platform Support
lsp_server by jamesnvc Mature :white_check_mark: Yes Linux, macOS, Windows (with caveats)
prolog_lsp by hargettp Experimental :cross_mark: No All platforms (but immature)

Option 1: lsp_server (Recommended)

Repository: GitHub - jamesnvc/lsp_server: Language Server Protocol server for SWI-Prolog
SWI-Prolog Pack: "lsp_server" pack for SWI-Prolog
Maturity: Production-ready

Features

  • :white_check_mark: Find definitions
  • :white_check_mark: Find references
  • :white_check_mark: Hover documentation
  • :white_check_mark: Code completion
  • :white_check_mark: Diagnostics (errors/warnings)
  • :white_check_mark: Signature help

Installation

Method 1: Using pack_install

?- pack_install(lsp_server).

Method 2: Using swipl command

swipl pack install lsp_server

Requirements

  • SWI-Prolog 8.1.5 or newer (for best results with “find references”)
  • Requires xref_called/5 predicate (available in 8.1.5+)

Windows-Specific Configuration

:warning: IMPORTANT: On Windows (not WSL), running the server via stdio will NOT work.

Solution: Run the server over a socket instead:

# Start lsp_server on a specific port
swipl -g "lsp_server:main([port, 5007])" -t halt

As of version 2.5.0, socket mode is supported via command-line arguments:

port <port_number>

instead of stdio.

VS Code Extension: swi-lsp

Marketplace: swi-lsp - Visual Studio Marketplace

This extension provides VS Code integration for lsp_server.

Installation:

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for “swi-lsp”
  4. Click Install

Configuration: See the extension’s README for connecting to the LSP server.


Option 2: prolog_lsp (Experimental)

Repository: GitHub - hargettp/prolog_lsp: Language Server for Prolog
SWI-Prolog Pack: "prolog_lsp" pack for SWI-Prolog
Maturity: :warning: Experimental (not recommended for production)

Status

From the author:

“This project is very immature and not at all recommended for daily production use.”

When to Consider

  • You want to contribute to LSP development
  • You’re experimenting with alternative implementations
  • You need features not yet in lsp_server

MCP Server Options for Enhanced Integration

Model Context Protocol (MCP) servers can bridge the gap between Claude Code and LSP diagnostics.

What is MCP?

MCP is a protocol that allows AI assistants like Claude to access external tools and data sources. MCP servers act as middleware that:

  • Connect Claude Code to LSP servers
  • Expose LSP features as tools Claude can use
  • Work around limitations in Claude Code’s built-in LSP support

Available MCP Servers for LSP Integration

1. cclsp (Claude Code LSP)

Repository: GitHub - ktnyt/cclsp: Claude Code LSP: enhance your Claude Code experience with non-IDE dependent LSP integration.
MCP Market: https://mcpmarket.com/server/cclsp

Features
  • :white_check_mark: Pull current diagnostics using textDocument/diagnostic
  • :white_check_mark: Find definitions, references, rename symbols
  • :white_check_mark: Server restart capabilities
  • :white_check_mark: Intelligent position handling (tries multiple combinations)
  • :white_check_mark: Robust symbol resolution
Why It Helps

Solves the common problem where AI agents struggle with accurate line/column numbers when communicating with LSP servers.

Use Case

You want Claude Code to have direct access to LSP features regardless of IDE limitations.


2. tritlo/lsp-mcp

Playbooks: LSP MCP server for AI agents

Features
  • :white_check_mark: Hover information
  • :white_check_mark: Code completions
  • :white_check_mark: Diagnostics
  • :white_check_mark: Generic LSP feature access for LLMs
Why It Helps

Provides a clean interface for AI agents to query LSP servers for any language.

Use Case

You want a language-agnostic MCP server that works with multiple LSP servers.


3. @juanpprieto/claude-lsp

NPM Package: https://www.npmjs.com/package/@juanpprieto/claude-lsp

Features
  • :white_check_mark: Hook-based diagnostic injection
  • :white_check_mark: Real-time code analysis
  • :white_check_mark: TypeScript LSP integration
  • :white_check_mark: ESLint checking
  • :white_check_mark: Prettier formatting
  • :white_check_mark: GraphQL checks
Why It Helps

Automatically injects diagnostics into Claude’s context using hooks, so Claude sees:

  • Type errors
  • Lint warnings
  • Formatting issues
Use Case

You want automatic, real-time diagnostic sharing without manual intervention.


Comparison of MCP Servers

Feature cclsp tritlo/lsp-mcp @juanpprieto/claude-lsp
Diagnostics :white_check_mark: :white_check_mark: :white_check_mark:
Definitions :white_check_mark: :white_check_mark: :red_question_mark:
References :white_check_mark: :white_check_mark: :red_question_mark:
Hover Info :white_check_mark: :white_check_mark: :red_question_mark:
Completions :red_question_mark: :white_check_mark: :white_check_mark:
Auto-injection :cross_mark: :cross_mark: :white_check_mark: (via hooks)
Multi-language :white_check_mark: :white_check_mark: :small_orange_diamond: (JS/TS focused)
Position handling :white_check_mark: (robust) :white_check_mark: :white_check_mark:
Server restart :white_check_mark: :red_question_mark: :cross_mark:
Prolog support :white_check_mark: (any LSP) :white_check_mark: (any LSP) :red_question_mark: (JS/TS focused)

Legend:

  • :white_check_mark: = Supported
  • :cross_mark: = Not supported
  • :red_question_mark: = Unknown/unclear
  • :small_orange_diamond: = Partial support

Comparison of LSP Integration Approaches

Overview Table

Approach Setup Complexity Claude Access Cost Maturity Platform Support
VS Code Native Only Low :cross_mark: None Free Mature All
Built-in Claude Code LSP Low-Medium :small_orange_diamond: Limited Free Early/Raw All
MCP Server (cclsp) Medium :white_check_mark: Full Free Moderate All
MCP Server (tritlo) Medium :white_check_mark: Full Free Moderate All
MCP Server (@juanpprieto) Medium-High :white_check_mark: Auto Free Moderate All

Detailed Comparison

1. VS Code Native LSP Only

Setup:

Install Prolog LSP extension (swi-lsp) → Configure → Done

Pros:

  • :white_check_mark: Simple setup
  • :white_check_mark: Works independently of Claude Code
  • :white_check_mark: Well-documented
  • :white_check_mark: Stable

Cons:

  • :cross_mark: Claude Code cannot see diagnostics
  • :cross_mark: No AI-assisted error fixing
  • :cross_mark: Manual error explanation needed

Best For: Users who want VS Code LSP features but don’t need Claude to access diagnostics.


2. Built-in Claude Code LSP Support

Setup:

export ENABLE_LSP_TOOL=1
# Or set in VS Code settings

Pros:

  • :white_check_mark: No additional software needed
  • :white_check_mark: Official support from Anthropic
  • :white_check_mark: Automatic diagnostic sharing (in theory)

Cons:

  • :warning: Early/raw implementation (as of 2025-12)
  • :warning: Bugs in different LSP operations
  • :cross_mark: No documentation
  • :cross_mark: No UI indication of status
  • :cross_mark: VS Code extension missing MCP tool

Best For: Early adopters willing to work through limitations while the feature matures.


3. MCP Server Integration (cclsp)

Setup:

# Install cclsp MCP server
npm install -g cclsp

# Configure in Claude Code settings
# Point to your Prolog LSP server

Pros:

  • :white_check_mark: Full LSP feature access
  • :white_check_mark: Robust position handling
  • :white_check_mark: Works around IDE limitations
  • :white_check_mark: Server restart capabilities
  • :white_check_mark: Language-agnostic

Cons:

  • :warning: Additional software to install
  • :warning: More complex configuration
  • :warning: Requires understanding of MCP

Best For: Power users who want complete LSP integration and are comfortable with configuration.


4. MCP Server Integration (tritlo/lsp-mcp)

Setup:

# Install and configure tritlo/lsp-mcp
# Connect to Prolog LSP server

Pros:

  • :white_check_mark: Generic LSP interface
  • :white_check_mark: Multi-language support
  • :white_check_mark: Hover, completions, diagnostics

Cons:

  • :warning: Additional software to install
  • :warning: Configuration complexity
  • :red_question_mark: Less documentation than cclsp

Best For: Users working with multiple languages who want one MCP server for all LSP interactions.


5. Hook-based Auto-injection (@juanpprieto/claude-lsp)

Setup:

npm install @juanpprieto/claude-lsp

# Configure hooks in Claude Code
# Set up automatic injection

Pros:

  • :white_check_mark: Automatic diagnostic injection
  • :white_check_mark: Real-time analysis
  • :white_check_mark: No manual triggering needed
  • :white_check_mark: Hook-based workflow integration

Cons:

  • :warning: Most complex setup
  • :warning: Primarily JS/TS focused (Prolog support unclear)
  • :warning: Requires hook configuration knowledge

Best For: TypeScript/JavaScript developers who want fully automatic diagnostic sharing; Prolog support uncertain.


Decision Matrix

Choose VS Code Native Only if:

  • You only need LSP features in your editor
  • You don’t need Claude to see diagnostics
  • You want the simplest setup

Choose Built-in Claude Code LSP if:

  • You’re okay with early-stage software
  • You want official support
  • You can wait for maturity improvements

Choose cclsp MCP Server if:

  • You need full LSP feature access in Claude
  • You want robust, reliable integration
  • You’re comfortable with configuration

Choose tritlo/lsp-mcp if:

  • You work with multiple languages
  • You want a generic LSP solution
  • You prefer flexibility over specialization

Choose @juanpprieto/claude-lsp if:

  • You primarily work with TypeScript/JavaScript
  • You want automatic diagnostic injection
  • You’re willing to invest in complex setup

Claude Code for VS Code: Known Issues

This section documents specific issues when using Claude Code through the VS Code chat interface.

Issue 1: Missing MCP IDE Diagnostics Tool

Reference: Issue #8635

Problem:

  • CLI version of Claude Code has mcp__ide__getDiagnostics tool
  • VS Code extension is missing this tool
  • Paradox: External CLI has better IDE access than native extension

Impact:

  • VS Code extension cannot retrieve Pylance/LSP diagnostics via MCP
  • Reduces effectiveness compared to CLI version
  • “Fix with Claude Code” feature may not work properly

Status: Open issue (as of 2025-12-12)

Workaround:

  • Use CLI version with --ide flag to connect to VS Code
  • Use MCP servers (cclsp, tritlo/lsp-mcp) to bridge the gap
  • Wait for official fix

Issue 2: LSP Integration Worse Than CLI

Reference: Issue #8635 (same issue)

Problem:

“The CLI version of Claude Code can connect to IDEs and access diagnostics. But the VSCode Extension (which runs inside the IDE) has worse IDE integration.”

Expected Behavior:

  • VS Code extension should have better LSP access
  • Should see all diagnostics automatically
  • Should integrate seamlessly with native LSP features

Actual Behavior:

  • Extension shows “Total LSP servers loaded: 0”
  • Cannot access diagnostics that VS Code itself can see
  • Requires workarounds to access native IDE features

Issue 3: “Fix with Claude Code” Action Broken

Reference: Issue #2269

Problem:

  • “Fix with Claude Code” action in VS Code doesn’t work properly
  • Diagnostic information not passed correctly to Claude
  • May fail silently or provide incomplete context

Impact:

  • Quick-fix workflow broken
  • Must manually describe errors to Claude
  • Reduces productivity

Workaround:

  • Manually copy error messages to Claude chat
  • Use terminal/CLI commands to run diagnostics
  • Wait for official fix

Issue 4: No UI Indication of LSP Server Status

Problem:

  • No visual feedback in VS Code about LSP server connections
  • No way to know if LSP integration is working
  • Must check OUTPUT tab logs to debug

Impact:

  • Users unaware of connection issues
  • Difficult to troubleshoot
  • “0 LSP servers loaded” discovered only through logs

Workaround:

  • Regularly check OUTPUT tab → Select “Claude Code” source
  • Look for debug messages about LSP servers
  • Monitor for “Total LSP servers loaded: X” messages

Issue 5: Early/Raw LSP Support

Reference: Issue #5495 discussion

Problem:

  • LSP support added in v2.0.30 but still immature
  • Bugs in different LSP operations
  • Missing documentation
  • No standardized configuration

Known Bugs:

  • Socket vs stdio connection issues
  • Server initialization failures
  • Position/offset calculation errors
  • Timeout issues (especially in JetBrains IDEs)

Workaround:

  • Use $ENABLE_LSP_TOOL=1 environment variable
  • Report bugs to GitHub issues
  • Use MCP servers for more stable integration
  • Contribute to community testing

Issue 6: Windows-Specific Problems

Problem:

  • Prolog LSP server (lsp_server) doesn’t support stdio on Windows
  • Must use socket mode instead
  • Configuration more complex than Linux/macOS

Impact:

  • Windows users need extra configuration steps
  • May encounter connection errors with default settings

Solution:

  • Always use socket mode on Windows:
    swipl -g "lsp_server:main([port, 5007])" -t halt
    
  • Configure VS Code extension to connect via socket
  • See lsp_server documentation

Known Workarounds Summary

Issue Workaround Effort Effectiveness
Missing MCP tool Use CLI with --ide flag Medium :white_check_mark: Good
Missing MCP tool Use cclsp/tritlo MCP server Medium-High :white_check_mark: Excellent
Poor LSP integration Use MCP servers Medium-High :white_check_mark: Excellent
“Fix with Claude” broken Manual error copying Low :small_orange_diamond: Partial
No UI indication Monitor OUTPUT logs Low :small_orange_diamond: Diagnostic only
Windows stdio issues Use socket mode Medium :white_check_mark: Good

Troubleshooting

Problem: “Total LSP servers loaded: 0”

Symptoms:

[DEBUG] Total LSP servers loaded: 0
[DEBUG] LSP Diagnostics: Checking registry - 0 pending

Causes:

  1. No Prolog LSP server installed in VS Code
  2. LSP server installed but not connected to Claude Code
  3. Claude Code’s LSP integration not enabled

Solutions:

Step 1: Install Prolog LSP Server

# Install lsp_server pack
swipl -g "pack_install(lsp_server)" -t halt

# Or install VS Code extension
# Search "swi-lsp" in VS Code Extensions marketplace

Step 2: Enable Claude Code LSP Support

# Set environment variable
export ENABLE_LSP_TOOL=1

# Or in VS Code settings.json
{
  "claude-code.enableLSP": true
}

Step 3: Verify LSP Server Running

  • Open a Prolog file in VS Code
  • Check Problems panel (Ctrl+Shift+M) for diagnostics
  • If VS Code shows diagnostics, LSP server is working

Step 4: Install MCP Server (Alternative)

# Install cclsp
npm install -g cclsp

# Configure in Claude Code MCP settings

Problem: No Diagnostics Showing in VS Code

Symptoms:

  • No errors/warnings in Problems panel
  • Red squiggles not appearing under code
  • LSP server seems not to work

Solutions:

Check 1: Is the LSP Extension Installed?

  • Go to Extensions (Ctrl+Shift+X)
  • Search “swi-lsp” or “prolog”
  • Install if missing

Check 2: Is the LSP Server Running?

On Linux/macOS:

ps aux | grep lsp_server

On Windows:

Get-Process | Select-String "swipl"

Check 3: VS Code Output Logs

  • Open OUTPUT tab (Ctrl+Shift+U)
  • Select “SWI-Prolog Language Server” from dropdown
  • Look for error messages

Check 4: Restart LSP Server

  • Open VS Code Command Palette (Ctrl+Shift+P)
  • Type “Reload Window”
  • Or restart VS Code entirely

Problem: Windows Socket Connection Errors

Symptoms:

  • LSP server fails to start
  • “Connection refused” errors
  • stdio-related errors

Solution:

Must use socket mode on Windows:

# Start LSP server on specific port
swipl -g "lsp_server:main([port, 5007])" -t halt

Configure VS Code extension (settings.json):

{
  "swi-lsp.server.host": "localhost",
  "swi-lsp.server.port": 5007
}

Problem: Claude Code Can’t See Diagnostics VS Code Shows

Symptoms:

  • VS Code Problems panel shows errors
  • Claude Code shows “0 pending” diagnostics
  • LSP server working but Claude can’t access it

Root Cause:

  • VS Code extension missing mcp__ide__getDiagnostics tool
  • Claude Code’s LSP integration not connected to VS Code’s LSP

Solutions:

Option 1: Use MCP Server

npm install -g cclsp
# Configure to connect to your Prolog LSP server

Option 2: Use CLI with IDE Connection

claude --ide vscode

Option 3: Wait for Official Fix

  • Track Issue #8635
  • Update to latest Claude Code version when fixed

Problem: “Fix with Claude Code” Does Nothing

Symptoms:

  • Right-click on error → “Fix with Claude Code”
  • Nothing happens or error appears
  • Diagnostic not passed to Claude

Solution:

Manual Workaround:

  1. Copy the error message from Problems panel
  2. Open Claude Code chat
  3. Paste error and ask for fix
  4. Apply fix manually

Permanent Solution:

  • Wait for Issue #2269 fix
  • Use MCP server integration instead

Resources

Official Documentation

SWI-Prolog LSP Implementations

VS Code Extensions

MCP Servers

GitHub Issues

LSP Protocol Documentation

Community Resources


Appendix: Example VS Code Configuration

settings.json for SWI-Prolog LSP

{
  // SWI-Prolog LSP Server Configuration
  "swi-lsp.server.enabled": true,
  "swi-lsp.server.host": "localhost",
  "swi-lsp.server.port": 5007,

  // Claude Code Configuration
  "claude-code.enableLSP": true,
  "claude-code.debug": true,

  // Prolog File Associations
  "files.associations": {
    "*.pl": "prolog",
    "*.pro": "prolog"
  }
}

Environment Variables

# Enable Claude Code LSP tool
export ENABLE_LSP_TOOL=1

# Enable debug logging
export CLAUDE_CODE_DEBUG=1

Appendix: Starting LSP Server Manually

Linux/macOS

#!/bin/bash
# start-prolog-lsp.sh

# Start lsp_server in stdio mode
swipl -g "lsp_server:main([stdio])" -t halt

Windows (Socket Mode Required)

# start-prolog-lsp.ps1

# Start lsp_server in socket mode
& "C:\Program Files\swipl\bin\swipl.exe" -g "lsp_server:main([port, 5007])" -t halt

Summary

Key Takeaways

  1. LSP is a protocol that connects editors to language-specific tools for error checking, autocomplete, and more.

  2. Claude Code can integrate with LSP, but support is early/raw as of 2025-12-12.

  3. “Total LSP servers loaded: 0” means no LSP servers are connected to Claude Code - this is a configuration issue, not a limitation.

  4. For SWI-Prolog, use lsp_server by jamesnvc (mature) or the swi-lsp VS Code extension.

  5. Windows users must use socket mode - stdio doesn’t work for lsp_server on Windows.

  6. VS Code extension has limitations - missing MCP tool, worse than CLI version.

  7. MCP servers (cclsp, tritlo/lsp-mcp) provide workarounds for Claude Code’s LSP integration gaps.

  8. Multiple integration approaches exist - choose based on complexity tolerance and feature needs.

Quick Start Checklist

  • Install SWI-Prolog (if not already installed)
  • Install lsp_server pack: ?- pack_install(lsp_server).
  • Install swi-lsp VS Code extension
  • Configure socket mode (Windows) or stdio mode (Linux/macOS)
  • Verify LSP works in VS Code (check Problems panel)
  • Choose Claude Code integration approach:
    • Built-in (simple, limited)
    • MCP server (complex, full-featured)
  • Enable ENABLE_LSP_TOOL=1 if using built-in
  • Test: Open Prolog file with errors, check if Claude sees them
2 Likes