Private Channel from Cloud LLMs to Local Projects

    A four-layer design for connecting cloud large language models to a local codebase without exposing the filesystem: encrypted tunnel, loopback proxy with auth, a locked workspace, and a task file for handoff. Covers architecture, a minimal file/patch/check API, tunnel and client setup, sanitizing shared folders, quota split, and operations.

    1. Why “cloud model + local code” needs a dedicated channel

    Daily AI-assisted coding pain points cluster in three places. First, “heavy input” work—reading code, comparing diffs, tracing defects—burns model quota, yet it is also the most frequent work. Second, copying file fragments back and forth is slow and easy to miss context; the model often does not see the latest state on disk. Third, exposing a project tree to an external service creates uncontrolled risk: arbitrary command execution, access outside the intended tree, accidental deletes.

    The real problem is not “can we connect,” but “how to connect without giving up a security boundary.” This article splits the solution into four layers that successively tighten permissions.

    2. Architecture: four layers of tightening

    1. Cloud LLM client (web / desktop / mobile; separate quota; multi-account rotation)
    2. ↓ Encrypted public channel (P2P tunnel + public relay, end-to-end encryption)
    3. Local proxy (loopback only; mandatory password + request signing)
    4. ↓ Strictly locked to a single project root
    5. Project workspace (source + quality scripts + task file)
    6. ↕ Local coding tools that can edit, debug, and run tests

    Intent of each layer:

    • Client only handles conversation and intent; it never touches the filesystem, so it is isolated by design.
    • Channel solves “no public IP at home”: a tunnel maps an intranet service to an encrypted entry. It does not expose a general-purpose shell.
    • Local service is the only permission gate: identity checks, path normalization, and out-of-bounds blocking happen here.
    • Workspace pins writes to one folder. A task file is the cross-end “handoff sheet.”

    3. Prerequisites (four kinds of software)

    1. Version control — archive and line-level diffs; one-click rollback if a change is bad. This is the safety base of the whole setup.
    2. Runtime — to run the local proxy. Prefer a long-term support version to avoid dependency drift.
    3. Terminal — start/stop the service and read logs. You only need “cd, run one command, close the window.”
    4. Editor / local AI coding tool — apply changes on disk and run quality scripts.

    Install with defaults. If you install the runtime via a package manager, put the executable on PATH so the terminal can find the start command.

    4. Implementation

    Step 1: Project root and task file

    Create a task file at the project root for handing off complex changes:

    1. # Task
    2. - Goal: add pagination parameter validation to the query module
    3. - Constraint: do not change public utility function signatures
    4. - Acceptance: local quality scripts, all cases pass
    5. - Status: pending / in progress / done

    It is plain text: the model can read and write it, and you can open it in an editor, so context does not drift between ends.

    Step 2: Local proxy

    Expose three clear endpoints. Do not expose a general command-execution API:

    1. // Illustrative only: permission model, not a product API
    2. app.get('/files', auth, listInWorkspace); // list (inside root only)
    3. app.get('/file', auth, readInWorkspace); // read (inside root only)
    4. app.post('/apply', auth, applyPatch); // apply patch (no delete, no move out of root)
    5. app.post('/check', auth, runQualityScript); // run a registered quality script (allowlist)

    Three constraints: auth on every endpoint; normalize path params then check they stay under the root (block ../); /check runs only scripts registered in config—no concatenated commands.

    Step 3: Encrypted public channel

    Map the local service port to an encrypted public entry. Expose that port only—do not also open remote desktop or file sharing. Autostart the tunnel client and local service; stop them when unused so the channel drops.

    Step 4: Register the channel in the client

    In the model client’s connector config, set the public entry URL, access token, and bind the connection to this project root. Example:

    1. {
    2. "workspaceRoot": "./my-project",
    3. "endpoint": "<your encrypted entry URL>",
    4. "tokenEnv": "LOCAL_MCP_TOKEN",
    5. "allowedTools": ["list", "read", "apply", "check"]
    6. }

    Inject the token via environment variable; do not put it in plaintext in config (and do not commit it).

    5. Security: sanitizing a shareable copy

    Before packing the tree for someone else, delete three kinds of local state: credential files, client registration files, and token files. They hold logins and keys; leakage is equivalent to handing over the account. Large, rebuildable dependency dirs can be deleted too. On first start, the other party generates a new credential set; the two sides stay isolated.

    Three extra rules: never put passwords in code or commit history; periodically check the repo for leaked secrets; treat the tunnel entry URL as sensitive—do not post it publicly.

    Any internet-facing service must authenticate. Mapping an unauthenticated local service is the most common severe misconfiguration: it opens the project tree to anyone scanning the public internet.

    6. Quota split: send heavy work to a separate quota

    After setup, split work clearly: large reads, design discussion, and defect location go to the cloud client (its own quota, multi-account rotation). Small edits can be patches from the cloud plus local quality checks. Large refactors go into the task file and are applied by local coding tools. That cuts high-value local-tool quota use and avoids shuttling context.

    7. Alternatives and operations

    If you want less DIY, desktop control products exist, often with a monthly free-call allowance and support for major models. A self-built path differs in three ways: the path stays private (no third-party closed-source relay); no general-purpose shell, so lower risk of misuse; rules can be per-project (writable suffixes, mandatory quality gates).

    Daily ops: close the tunnel when unused; weekly, review out-of-bounds blocks in logs; after any permission-related code change, rerun quality scripts. With that cadence, the channel stays stable and can be reused after one-time setup.