Skip to content

[P3][LM-8] Evaluate an opt-in experimental Claude Code local-model route #384

Open

Description

@BunsDev

Outcome and dependencies

Optionally expose a runtime-vendor-documented compatible local endpoint through the existing claude -p backend, without claiming official Anthropic support for non-Claude execution.

Parent: #376. Completion dependencies: #378 (LM-2 connection/credential service) and #380 (LM-5 local-run privacy/admission policy). Priority: P3. Delivery group: optional experiment, explicitly outside Local models v1 core completion. This issue never blocks #383 or the Codex local-model release. Reuse #383's test approach/fixtures where available without making that issue a prerequisite or creating a cycle.

Follow the shared execution contract in #376. Experimental support and activation need their own evidence/decision; existing cloud Claude behavior stays unchanged.

Context and source entry points

Refresh current main, scoped AGENTS.md and actual native/runtime documentation before implementation. Publication baseline: ec7be578765f9ce54976882853e57ca190252361.
Existing: apps/desktop/src/main/engine/backends/{claude,health,types}.ts and accepted connection/policy/model-picker contracts. Proposed: apps/desktop/test/local-claude.test.ts. Reuse existing stream-json events, Stop and request broker; no SDK migration, second loop or tool executor.

Consumes: validated local profiles, secrets, qualification state and no-cloud-fallback policy. Produces: either a narrowly qualified opt-in native route with exact limitations, or a documented unsupported/blocked result. A negative feasibility finding is valid evidence, not permission to weaken safety.

Implementation steps

  • Recheck Anthropic gateway support boundaries and the exact runtime vendor's compatibility documentation, such as LM Studio's integration guide. Record version/date and any disagreement; vendor compatibility claims do not establish Anthropic-supported non-Claude behavior.
  • Before exposing execution, prove a real native stream-json/tool/approval/Stop round trip with a preinstalled model in an authorized disposable fixture. Add per-child, profile-scoped endpoint/auth configuration only against that verified protocol.
  • Audit every model destination, including helper, title, follow-up, delegated and compaction paths. One --model setting is insufficient evidence of fully local behavior. Apply [P1][LM-5] Enforce local-run privacy, bounded resource use and truthful recovery #380's no-cloud-fallback/admission policy; disable features whose destination or authority cannot be constrained.
  • Remove conflicting inherited endpoint switches/provider credentials for the local child while retaining applicable managed safety policy. Never edit global shell or ~/.claude settings, forward subscription credentials to a local server or bypass platform restrictions.
  • Reuse current Stop, permission requests, event identity/mapping and recovery. Show experimental status, exact native/runtime limitations and stale qualification. Keep unavailable paths disabled; unresolved protocol/privacy boundaries leave that combination unavailable.
  • Keep default cloud Claude sessions unchanged and scope process/session/credential identity to the local connection. The experiment must not introduce a hard dependency into the core Codex release.

Acceptance criteria

  • AC1: the route is explicitly experimental and records the exact tested CLI/model/server/configuration and upstream support limitation.
  • AC2: native tool/approval/Stop behavior and every auxiliary model destination pass qualification; default cloud Claude sessions remain unchanged.
  • AC3: unsupported or unverified configurations cannot appear production-ready; no permission weakening, managed-policy bypass or silent cloud fallback is used to make a test pass.
  • AC4: this issue's state does not block [P1][LM-7] Prove local-model integration and publish the supported compatibility matrix #383 or the core release; it retains independent evidence and activation decision.
  • AC5: credentials do not enter renderer/logs/exports; cloud account secrets never reach the local server; global settings bytes remain unchanged.

Verification and handoff

Begin with failing scoped-config/credential/destination/lifecycle tests. Use current focused suites, pnpm build && pnpm test, and pnpm test:e2e for UI changes. Keep mock fixtures and real native qualification separate, with exact SHA/version/results and authorization. Update existing local-model docs/status and a dated review receipt. Unavailable native tests remain open. No merge, release, feature activation or model downloads without separate authority.

Long-running goal prompt

Evaluate LM-8 for TypeSafeAI/modex under #376 only as an optional experiment. Consume #378/#380's accepted contracts, read current AGENTS.md, source and vendor/native documentation, and verify main plus owned worktree. First prove the actual claude -p stream-json/tool/approval/Stop path with a preinstalled model in an authorized disposable fixture. Scope credentials and all model destinations, including helpers/compaction; retain managed safety and existing cloud behavior. Show unsupported combinations as unavailable rather than claiming official support or weakening policy. Use failing-first tests, targeted/full checks, signed reviewable commits and status/evidence updates. Checkpoint SHAs, exact versions/results, remaining gates and one next action. Never hold the core Codex release for this issue. No merge, release, global settings rewrite, activation or unapproved downloads.

Follow-up / resume prompt

Resume LM-8 from its live issue/PR and checkpoint. Verify ownership, actual diff, producer contracts and current upstream support statements/native-runtime versions. Repeat the smallest safe qualification and audit helper/compaction destinations plus inherited credentials. Stop on unresolved privacy or permission boundaries; do not bypass managed policy or delay the core release. Fix one bounded regression, rerun smoke/full checks and record exact evidence separately from mocks. Keep unsupported combinations and unrun gates explicit. No merge, publication or scope expansion.

Activity

  1. BunsDev commented on Oct 23, 2026

    @BunsDev
    ContributorAuthor

    Refreshed goal prompts — 2026-10-23 (main at 203a350)

    On main already:

    Still open:

    Local worktrees lm1-contract, lm2-discovery, lm3-isolation and lm-foundation are claimed by other sessions. Don't adopt or edit them.

    Long-running goal prompt

    Evaluate LM-8 (#384) in TypeSafeAI/modex under tracker #376, as an optional experiment only. It never blocks #383 or the Codex local release. Read AGENTS.md, #376's shared execution contract, #378, #380, draft PR #386, docs/status.md, docs/local-models.md once it lands, and apps/desktop/src/main/engine/backends/{claude,health,types}.ts; then verify main's SHA. Create your own worktree with scripts/worktree.sh new and check; never edit the primary checkout or another session's worktree. Gate: start only after #378 and #380 are accepted. Coding turns go only through the existing claude -p stream-json backend: no Agent SDK, no API client, no second loop or tool executor. Slice 1, a written finding: recheck Anthropic's LLM-gateway support boundary and the runtime vendor's Claude Code guide (for example LM Studio's), and record versions, dates and where they disagree. Vendor claims are not Anthropic support. Slice 2: in an authorized disposable fixture with a preinstalled model and no downloads, prove a real stream-json tool → approval → Stop round trip before exposing anything. Slice 3: per-child, profile-scoped endpoint and auth only. Strip inherited endpoint switches and cloud credentials from the local child, keep managed policy, and never touch ~/.claude, shell profiles or the user's subscription credentials. Audit every model destination, including titles, follow-ups, subagents and compaction, apply #380's policy, and disable whatever can't be constrained. Slice 4: label the route experimental with exact limits and stale qualification. Unverified combinations stay unavailable, and default cloud Claude sessions are unchanged. A negative finding is a valid result. Write failing tests first in apps/desktop/test/local-claude.test.ts, covering scoped config, credentials, destinations and lifecycle. Run pnpm build && pnpm test, and pnpm test:e2e if UI changes. Update docs/local-models.md, docs/status.md and a dated docs/reviews/ receipt. Activation is a separate decision for Val. Open signed PRs and wait for Val's go-ahead to merge.
    

    Follow-up / resume prompt

    Resume LM-8 (#384). Confirm you own the worktree, fetch main, and read the latest comments here and on #376, #378 and #380. Recheck the upstream support statements and record the claude CLI and runtime versions. Repeat the smallest safe qualification, then re-audit auxiliary destinations and inherited credentials. Stop on any unresolved privacy or permission boundary instead of working around it. Fix one bounded regression, re-run the checks, and keep mock results apart from native ones. Post a checkpoint: SHA, results, what's unsupported or unrun, and one next action. Don't let this hold up #383.
    
  2. misterespresso commented on Oct 24, 2026

    @misterespresso
    Contributor

    I'd like to take the ungated parts of LM-8. Per the 2026-10-23 refresh, slices 3–4 wait for #378/#380 acceptance, so I'll stay out of the backend until then.

    Plan:

    1. Slice 1: a written finding comparing Anthropic's LLM-gateway support boundary with Ollama's and LM Studio's Claude Code guidance, with versions, dates and disagreements.
    2. Slice 2: a disposable native probe on Windows 11 with Claude Code 2.1.310 and Ollama 0.40.10, using preinstalled models only (qwen3:14b, gpt-oss:20b). It tests the stream-json tool → approval → Stop round trip and checks where auxiliary calls (titles, compaction, subagents) actually go. No changes to ~/.claude or global settings, and no subscription credentials sent to the local server.

    I'll post the results as a dated receipt here. Any of it can go into a docs/reviews/ PR later if you want. A negative result gets reported as-is. Does that scope work for you?

  3. misterespresso commented on Oct 24, 2026

    @misterespresso
    Contributor

    LM-8 Slice 1: support boundaries for a local claude -p route

    • Date: 2026-10-24
    • Modex main: a10fcc4
    • Host: Windows 11
    • Versions: Claude Code 2.1.310, Ollama 0.40.10
    • Scope: documentation review, plus metadata and endpoint probes against the local Ollama server.
    • Not done: no inference ran, no model was downloaded, and no global settings were changed.

    Summary

    • Gentle reminder: Anthropic's current gateway docs still say non-Claude models aren't supported. So this should ship marked as an experimental feature, as AC1 already plans.
    • The runtime vendors document it. Ollama and LM Studio each publish a Claude Code setup guide.
    • It looks feasible. Seven constraints below shape Slices 2–3. Two of them, F1 and F2, are credential-safety problems that Modex's current child environment does not handle.

    Sources

    All pages were retrieved on 2026-10-24. None of them carries a date or version.

    Source What it establishes
    Anthropic: Other LLM gateways Non-Claude models are not supported. A base URL without a gateway credential keeps the saved claude.ai login active.
    Anthropic: Gateway compatibility guide Endpoints, which model background tasks use, and calls that bypass ANTHROPIC_BASE_URL.
    Anthropic: Connect to an LLM gateway Credential precedence, settings-file precedence, and turning off traffic outside the gateway path.
    Anthropic: Model configuration Variables that select a model, and fallback behavior.
    Ollama: Anthropic compatibility Supported and unsupported Messages API features.
    Ollama: Claude Code integration Setup variables, and the 64k+ context recommendation.
    LM Studio: Claude Code Setup variables, and the ~25k+ context recommendation.

    Secondary source: an Ollama blog post says Anthropic compatibility arrived in v0.14.0 (January 2026). I have not confirmed this against Ollama's release notes.

    Where the documentation disagrees

    Topic Anthropic Ollama LM Studio
    Credential ANTHROPIC_AUTH_TOKEN overrides the saved login. A base URL alone keeps the claude.ai login active for requests sent to that host. ANTHROPIC_AUTH_TOKEN=ollama (required but ignored) and ANTHROPIC_API_KEY="" ANTHROPIC_AUTH_TOKEN=lmstudio, or the real LM Studio token when auth is on. Does not clear ANTHROPIC_API_KEY.
    Minimum context Assumes 200K for an unrecognized model ID. The auto-compact window cannot be set below 100,000. 64k+ more than ~25k
    Attribution block Stable per conversation since 2.1.181. Opting out is only needed when a gateway reshapes the system prompt. not set sets CLAUDE_CODE_ATTRIBUTION_HEADER=0
    Feature gaps count_tokens is optional No count_tokens, tool_choice, prompt caching, citations, PDF blocks or streaming error events. budget_tokens is not enforced. Lists none; does not mention streaming or tools.
    Model selection Aliases resolve through ANTHROPIC_DEFAULT_*_MODEL --model only --model only

    Findings that constrain the Modex route

    F1. Risk of leaking the subscription login (AC5).

    • Suppose the local child receives ANTHROPIC_BASE_URL but no gateway credential. Claude Code then uses the saved claude.ai login for requests to that host, which here is the local server.
    • cliEnvironment (apps/desktop/src/main/engine/backends/health.ts:8-17) passes the whole parent environment through. That includes any inherited ANTHROPIC_*, CLAUDE_CODE_OAUTH_TOKEN and CLAUDE_CODE_USE_* variables.
    • A local route must always:
      • set a local-only ANTHROPIC_AUTH_TOKEN;
      • blank ANTHROPIC_API_KEY;
      • strip the inherited provider and credential variables.

    F2. Settings-file env beats the process environment.

    • Anthropic: "When both a shell export and a settings-file env block set the same variable, the settings-file value applies."
    • So an env block in the user's ~/.claude/settings.json or a project .claude/settings*.json would override what Modex puts in the child environment. A gateway URL or token set there could send the turn to the cloud, or send a cloud credential to the local server.
    • Possible fixes, both still to be tested:
      • a flag-level --settings env override, for non-secret values only, since argv is visible in the process list;
      • --setting-sources without user.
    • Modex must not edit ~/.claude.

    F3. Traffic that does not follow ANTHROPIC_BASE_URL:

    • telemetry, version checks and release notes, which go to Anthropic and GitHub;
    • the fast-mode availability check, which goes to api.anthropic.com;
    • the WebFetch domain safety preflight, which goes to api.anthropic.com;
    • WebSearch, which is a hosted server tool.

    How to switch these off:

    • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 covers the first group.
    • Fast mode must stay off. Modex currently injects fastMode through --settings at claude.ts:94.
    • The WebFetch preflight needs skipWebFetchPreflight: true.
    • WebSearch needs to be disallowed.

    Slice 2 should capture network traffic to show that nothing is left.

    F4. Model aliases and auxiliary destinations.

    • Behind an Anthropic-format base URL, background tasks use the main model unless ANTHROPIC_DEFAULT_HAIKU_MODEL pins another.
    • Subagents and skill, command or agent frontmatter can name haiku, sonnet or opus, and fallbackModel and the content-safety fallback name Claude models. All of these still go to the base URL, so they fail locally rather than reach the cloud.
    • To keep them usable, pin these to the local model:
      • ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU,FABLE}_MODEL
      • CLAUDE_CODE_SUBAGENT_MODEL
    • No --fallback-model should be passed.
    • Inference never leaves the base URL, so cloud exposure is limited to the traffic in F3.
    • Modex's own auxiliary calls (titles, follow-ups, Jev) belong to LM-5 ([P1][LM-5] Enforce local-run privacy, bounded resource use and truthful recovery #380).

    F5. Context windows on this machine (from /api/show).

    • qwen3:14b:
      • native context is 40,960;
      • below Ollama's 64k recommendation and Claude Code's 100k auto-compact floor;
      • it cannot qualify.
    • gpt-oss:20b:
      • native context is 131,072, so it is the only candidate;
      • the installed -16k variant uses num_ctx 16,384, which is too small.
    • Slice 2 needs a num_ctx ≥ 64k variant, made with ollama create from the local weights (no download), plus a VRAM check on 16 GB.
    • Claude Code assumes 200K for an unknown model ID, so the real window must be declared. Otherwise compaction will not trigger before overflow.

    F6. Protocol, verified locally:

    • POST /v1/messages exists (GET returns 405);
    • /v1/messages/count_tokens returns 404, and Claude Code falls back to a character estimate;
    • /v1/models returns 200.

    Still unknown:

    • whether Ollama rejects or ignores context_management, defer_loading and effort (fallbacks: CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, ENABLE_TOOL_SEARCH=false);
    • how streaming behaves during long prefill. There is no prompt caching, so every turn re-processes the full prompt.

    F7. Managed policy.

    • The managed allowedProviders setting (v2.1.285+) can refuse a custom endpoint.
    • forceLoginMethod cannot be combined with ANTHROPIC_AUTH_TOKEN.
    • Modex must show these cases as unavailable, never work around them (AC3).

    Proposed Slice 2: disposable native probe, pending go-ahead

    1. Create a gpt-oss:20b variant with num_ctx 65536 from the local weights, and record VRAM use.
    2. In a throwaway directory, run claude -p --input-format stream-json --output-format stream-json --permission-prompt-tool stdio with:
      • only the environment from F1, F3 and F4;
      • --setting-sources tested both with and without user.
    3. Exercise:
      • one tool call;
      • one approval round trip;
      • Stop mid-turn;
      • one subagent;
      • one forced compaction.
    4. Route the child through a local logging proxy (HTTPS_PROXY) and record every non-loopback destination.
    5. Publish the exact environment, versions, transcript excerpts and destination list as the dated receipt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions