Claude Skills Guide

Claude Code for LSP Semantic Tokens Workflow Tutorial

Language Server Protocol (LSP) semantic tokens represent one of the most powerful features in modern IDEs and code editors. When combined with Claude Code’s CLI capabilities, you can build sophisticated code analysis tools, custom syntax highlighters, and intelligent development workflows. This tutorial walks you through practical approaches to use LSP semantic tokens with Claude Code.

Understanding LSP Semantic Tokens

Semantic tokens go beyond traditional syntax highlighting by providing semantic information about code elements. Instead of just knowing something is a “keyword” or “string,” semantic tokens tell you whether it’s a class, function, property, or variable. This rich metadata enables intelligent features like accurate symbol navigation, context-aware completions, and advanced refactoring tools.

The LSP specification defines token types including class, interface, enum, function, method, property, variable, parameter, and many more. Each token can be further modified with qualifiers like declaration, definition, readonly, and static.

Setting Up Your Environment

Before diving into workflows, ensure Claude Code is installed and configured with LSP support. Most modern code editors like VS Code, Neovim, and Zed already implement LSP clients that communicate with language servers.

To verify your setup, check that Claude Code can access your editor’s LSP infrastructure:

# Verify Claude Code can interact with your development environment
claude --version

For the most effective semantic token workflows, you’ll want a language server that provides rich semantic information. Popular choices include:

Building Semantic Token Analysis Workflows

Analyzing Code Structure

One powerful workflow uses Claude Code to analyze code structure via semantic tokens. Create a skill that extracts and visualizes the semantic organization of a codebase:

# semantic_analyzer.py
import json
from pathlib import Path

def analyze_semantic_tokens(file_path: str) -> dict:
    """Extract semantic token information from a file."""
    # This would connect to your LSP client
    # and request textDocument/semanticTokens/full
    pass

def group_by_type(tokens: list) -> dict:
    """Group tokens by their semantic type."""
    grouped = {}
    for token in tokens:
        token_type = token['type']
        if token_type not in grouped:
            grouped[token_type] = []
        grouped[token_type].append(token)
    return grouped

def generate_report(file_path: str) -> str:
    """Generate a semantic analysis report."""
    tokens = analyze_semantic_tokens(file_path)
    grouped = group_by_type(tokens)
    
    report = f"Semantic Analysis for {file_path}\n"
    report += "=" * 40 + "\n"
    
    for token_type, items in grouped.items():
        report += f"\n{token_type.title()} ({len(items)}):\n"
        for item in items:
            report += f"  - {item['name']} (line {item['line']})\n"
    
    return report

This pattern proves invaluable for understanding unfamiliar codebases quickly. Instead of manually scanning files, you get an instant structural overview.

Creating Custom Highlighting Schemes

Semantic tokens enable sophisticated theming beyond syntax highlighting. You can create different visual treatments based on semantic meaning:

/* Semantic token-based highlighting */
.token.class { color: #6B4FBB; font-weight: bold; }
.token.function { color: #D73A49; }
.token.method { color: #22863A; }
.token.property { color: #005CC5; }
.token.variable { color: #24292E; }
.token.parameter { color: #E36209; font-style: italic; }

/* Modifiers */
.token.declaration::after { content: " ⬥"; color: #6a737d; }
.token.readonly::before { content: "🔒 "; color: #959da5; }

Integrating with Claude Code Skills

Skills can use semantic token information to provide context-aware assistance. Here’s how to build a skill that uses semantic awareness:

---
name: semantic-code-assistant
description: "Provides context-aware code assistance using semantic token analysis"
tools: [Read, Write, Bash]
---

# Semantic Code Assistant

When analyzing code, first request semantic tokens from the active language server to understand the code structure. Use this information to:

1. Identify the type of each code element (class, function, method, property)
2. Understand the relationships between elements
3. Provide type-aware suggestions and refactoring guidance

When the user asks about code structure, query the semantic tokens and present the information organized by type. Highlight any potential issues like:
- Unused variables or functions
- Type mismatches
- Missing type annotations
- Accessibility concerns

Practical Workflow: Code Review Assistant

A powerful application combines semantic tokens with Claude Code’s analysis capabilities:

# Example workflow for semantic-aware code review
claude "Review this code and identify all public methods that lack type annotations"

The semantic token data tells Claude Code exactly which methods are public versus private, while the language server’s type information reveals missing annotations. This combination produces more accurate and helpful reviews than syntax-only analysis.

Advanced Patterns

Tracking Symbol References Across Files

Semantic tokens enable powerful cross-file analysis. By tracking token positions and comparing them against reference locations, you can build comprehensive symbol usage maps:

def find_references(symbol: str, semantic_db: dict) -> list:
    """Find all references to a symbol across the project."""
    references = []
    for file_path, tokens in semantic_db.items():
        for token in tokens:
            if token.get('references'):
                if symbol in token['references']:
                    references.append({
                        'file': file_path,
                        'line': token['line'],
                        'context': token['context']
                    })
    return references

Generating Documentation Automatically

Semantic tokens provide the perfect foundation for documentation generation:

def generate_docs_from_semantics(file_path: str) -> str:
    """Generate documentation based on semantic token types."""
    tokens = get_semantic_tokens(file_path)
    
    docs = []
    for token in tokens:
        if token['type'] in ['class', 'function', 'method']:
            docs.append({
                'name': token['name'],
                'type': token['type'],
                'signature': token.get('signature', ''),
                'documentation': token.get('documentation', '')
            })
    
    return format_as_markdown(docs)

Actionable Best Practices

When building LSP semantic token workflows with Claude Code, follow these practical guidelines:

  1. Start with your editor’s LSP: Most editors expose semantic token data that Claude Code can consume. Verify your setup works with basic queries before building complex integrations.

  2. Cache semantic data: Querying semantic tokens can be expensive. Implement caching for repeated analyses to improve performance.

  3. Handle missing servers gracefully: Not all languages have robust LSP implementations. Build fallback logic that works with simpler syntax-based analysis.

  4. Combine with other LSP features: Semantic tokens work alongside other LSP capabilities like hover, go-to-definition, and find-references for comprehensive tooling.

  5. Test with real codebases: Semantic token implementations vary between language servers. Test your workflows against actual code to ensure reliability.

Conclusion

LSP semantic tokens combined with Claude Code create powerful possibilities for code analysis, tooling, and developer productivity. By understanding how to query and utilize this rich semantic information, you can build workflows that go far beyond traditional syntax highlighting. Start with simple token analysis and progressively add complexity as you understand your use cases better.

The key is to treat semantic tokens as structured data that drives intelligent behavior—whether that’s generating documentation, performing code reviews, or creating custom visualizations. With Claude Code’s flexibility and the foundation of LSP, you’re well-equipped to build sophisticated development tools.