Skip to content

feat: add ClaudeCodeClient — LLM inference via Claude Code SDK (no API key) - #1766

Open
openbiocure wants to merge 2 commits into
getzep:mainfrom
openbiocure:feat/claude-code-sdk-client
Open

feat: add ClaudeCodeClient — LLM inference via Claude Code SDK (no API key)#1766
openbiocure wants to merge 2 commits into
getzep:mainfrom
openbiocure:feat/claude-code-sdk-client

Conversation

@openbiocure

Copy link
Copy Markdown

Summary

Adds a new ClaudeCodeClient LLM provider that uses the Claude Agent SDK for inference. Authenticates via Claude Code's OAuth credentials (~/.claude) — no API key required.

Motivation

Users of Claude Code (CLI, desktop, IDE extensions) already have authenticated sessions. This client lets Graphiti piggyback on that auth instead of requiring a separate Anthropic API key. Useful for developers who want to use Graphiti locally without managing API keys.

How it works

  • Spawns a persistent Claude Code subprocess via ClaudeSDKClient
  • First call ~8s (subprocess startup), subsequent calls ~3s (warm)
  • Monitors context usage via get_context_usage() — auto-recycles subprocess when context exceeds threshold (default 60%)
  • Parses JSON from text responses (same pattern as GroqClient)
  • Thread-safe via async lock

Usage

from graphiti_core.llm_client.claude_code_client import ClaudeCodeClient
from graphiti_core.llm_client.config import LLMConfig

client = ClaudeCodeClient(config=LLMConfig(model='haiku'))
graphiti = Graphiti(graph_driver=driver, llm_client=client, embedder=embedder)

Testing

Tested end-to-end with FalkorDB + HuggingFace sentence-transformers embeddings:

  • Episode ingestion: ~13s (including subprocess startup)
  • Search returns correctly extracted entities and relationships
  • Context recycling works — subprocess restarts cleanly when context fills up

Notes

  • Requires claude-agent-sdk (optional dependency, lazy import)
  • Falls back gracefully — ClaudeCodeClient is None when SDK not installed
  • Follows the same pattern as GroqClient — implements _generate_response, lets base class handle schema injection

Uses the Claude Agent SDK subprocess for inference. No API key needed —
authenticates via Claude Code's OAuth credentials (~/.claude).

Key features:
- Persistent subprocess: first call ~8s (startup), subsequent calls ~3s
- Context monitoring: auto-recycles subprocess when context exceeds threshold
- Stateless extraction: each query is independent via the persistent client
- JSON extraction: parses structured output from text responses
- Thread-safe: async lock prevents concurrent subprocess access

Usage:
    from graphiti_core.llm_client.claude_code_client import ClaudeCodeClient
    from graphiti_core.llm_client.config import LLMConfig

    client = ClaudeCodeClient(config=LLMConfig(model='haiku'))
    graphiti = Graphiti(graph_driver=driver, llm_client=client, ...)

Tested end-to-end with FalkorDB + HuggingFace embeddings.
Episode ingestion: ~13s (including subprocess startup).
Search returns extracted entities and relationships correctly.
@zep-cla-assistant

zep-cla-assistant Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@openbiocure
openbiocure force-pushed the feat/claude-code-sdk-client branch 2 times, most recently from 70343f3 to cde6870 Compare August 13, 2026 20:33
@openbiocure

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA behalf on myself, e-mail: openbiocure@gmail.com

zep-cla-assistant Bot added a commit that referenced this pull request Aug 13, 2026
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