🤖 AI Hot

What I Learned Putting GitHub Copilot Behind a Proxy

A
Alex Chen

Putting GitHub Copilot behind a man-in-the-middle proxy is the single fastest way to understand what it’s actually doing under the hood. The plugin looks like magic from the outside — type a few characters, get a suggestion. But once you intercept the traffic, the magic collapses into something boring and useful: JSON payloads, a prompt assembled from your surrounding code, and an auth token going to a completion endpoint. Here are the tips and tricks I picked up doing exactly this, plus a concrete how-to guide so you can do it yourself.

There’s a real reason to bother beyond curiosity. If you’re using an AI coding assistant in a job where code can’t leave the building, or where you need to prove what’s being sent where, you should know what’s in those requests. Spoiler: it’s your code, your file paths, and your editing context, sent to a third party every time you accept a suggestion. Understanding that concretely, by watching it happen, is worth more than reading the privacy policy.

Why MITM Copilot in the first place

Most developers treat Copilot as a black box. It either suggests good code or it doesn’t, and nobody looks closer. That’s fine until one of three things happens:

  • You need to debug why a suggestion is bad, and “the model is dumb” isn’t a useful diagnosis.
  • You’re subject to a security review and someone asks “what exactly does this send to GitHub?” and you can’t answer.
  • You suspect the context Copilot is using is wrong or stale, and you want to see it.

Intercepting the traffic answers all three at once. You get to see the exact prompt that produced a suggestion, the surrounding code that got included, and the response shape. Once you’ve seen it, you’ll never think of Copilot the same way — which is the point.

What you see when you intercept the traffic

The first thing that hits you is how much context goes up with every request. Copilot doesn’t just send the line you’re on. It sends a window of surrounding code — the lines above and below the cursor — plus, depending on the client, open files and buffer state. For a fill-in-the-middle completion, it sends a prefix and a suffix and asks the model to fill the gap. That’s the “magic,” and it’s just a carefully assembled prompt.

The requests go to a completion endpoint with your GitHub auth token attached. The response comes back as structured suggestions with the generated text and some metadata about which model and how confident it is. None of this is secret — it’s just that almost nobody looks.

The useful insight is the shape of the prompt. When you see your own function, its imports, and the surrounding file content assembled into a request, you understand two things. First, why Copilot is good at matching your existing style — it’s literally reading your code. Second, why it can be wrong in a specific way: if the context window doesn’t include the definition of something it’s trying to use, it’ll confidently guess. Watching the prompt get built makes the failure modes legible.

Here’s a representative sketch of what a completion request looks like once you strip away the exact field names, which drift between client versions. Don’t copy this verbatim — it’s illustrative, not a spec:

{
  "prompt": "def calculate_total(items):\n    # ... surrounding lines ...",
  "suffix": "\n    return total",
  "max_tokens": 50,
  "temperature": 0.2,
  "top_p": 1,
  "model": "copilot-completion-model"
}

The prompt is the prefix — everything before your cursor — and suffix is the text after it. Fill-in-the-middle is literally that: two anchors, and the model fills the space between them. max_tokens and temperature are tuned low, because you don’t want a wild completion, you want the median next chunk of code. The response mirrors it back as a list of candidate strings with per-candidate confidence. When you see this laid out, the whole thing stops feeling like an oracle and starts feeling like what it is: a text-completion API with your code as the input.

What to do with what you learn

Once you’ve watched the traffic, the learning should change how you actually work. The biggest behavioral shift for me was context hygiene. Because the surrounding code is the prompt, I stopped leaving half-finished functions and unrelated experiments open in the buffer while asking for a suggestion. The model reads whatever is near the cursor, whether it’s relevant or not, so keeping the buffer clean is a direct input-quality fix.

The second shift is about verification. Seeing the confidence metadata made it obvious that Copilot is often guessing at definitions it can’t see. I started treating every suggestion that references a symbol not in the visible context as suspect until proven otherwise, which catches a surprising number of subtly wrong completions before they become bugs.

The third shift is the compliance one. If you’re on a team deciding whether to allow AI assistants, run this exercise and bring the captured request body to the meeting. A packet capture ends the “what does it actually send” debate faster than any amount of documentation reading, and it turns an abstract risk into a concrete, reviewable one.

How to set up a MITM proxy for Copilot: a how-to guide

The tool I use is mitmproxy, and the setup is the same shape for any TLS-intercepting proxy like Charles or Fiddler. The hard part isn’t the proxy; it’s that Copilot’s traffic is encrypted, so you have to install the proxy’s certificate so it can decrypt and re-encrypt in the middle.

Step 1: install mitmproxy.

pip install mitmproxy

Step 2: run it and install the cert.

Start mitmproxy, then point a browser at http://mitm.it to download the certificate. Install the CA cert into your system trust store, and mark it trusted for SSL. Without this step, the proxy can only see encrypted blobs.

Step 3: point VS Code at the proxy.

VS Code respects the standard proxy settings. Set http.proxy (and http.proxyStrictSSL to false, so it accepts the mitmproxy certificate) in your settings, or set the HTTPS_PROXY environment variable before launching. The specifics vary by platform, but the principle is the same: make the editor’s traffic flow through the proxy.

Step 4: filter for Copilot traffic.

mitmproxy lets you filter with an expression. Something like ~d githubcopilot.com narrows the stream to Copilot’s endpoints. Now trigger a suggestion and watch the requests scroll by.

Step 5: read the payloads.

Open a request and inspect the JSON body. You’ll see the prompt structure, the model identifier, and the surrounding code. That’s the whole show.

A warning that will save you an afternoon: some clients use certificate pinning, which means they refuse to trust any certificate except the one they expect, and a MITM proxy won’t work cleanly against them. The VS Code Copilot extension has historically been interceptable, but if you hit a wall where the connection just fails with a cert error, pinning is usually the reason. In that case you’re looking at a client that’s specifically built to resist this, and you’ll need a different approach, like running the client on a machine you fully control and logging at the network boundary instead.

Tips and tricks I picked up

Watching the traffic teaches you a few things that change how you use the tool:

  • The prompt is your context budget. Whatever is in your open file and nearby lines is what the model sees. Keeping related code close together — the function, its callers, its imports — measurably improves suggestions, because the model can see the whole picture instead of guessing at definitions.
  • Copilot sends more than you think. File paths, project structure hints, and buffer state go up too. If the mere presence of a filename or a code string in the request is a problem for your compliance rules, assume it’s being sent and act accordingly.
  • Auth is a single token. Your GitHub identity rides along on every request. A leaked proxy log is essentially a leaked Copilot credential, so treat captured traffic as sensitive. Don’t commit it, don’t screenshot it into a public issue.
  • Responses carry confidence you can’t see in the UI. The metadata includes model and confidence fields that the editor hides from you. If you’re debugging flaky suggestions, this is where you find out whether the model is genuinely uncertain or just giving you the median answer.
  • The “magic” is fill-in-the-middle. Once you see the prefix/suffix structure, you can reason about why certain suggestions appear only in certain positions. The model isn’t writing your code top to bottom; it’s completing a gap between two known points.

None of these are earth-shattering on their own, but together they turn Copilot from an oracle into a system you can actually reason about. And reasoning about the system is the difference between a developer who uses AI tools and one who’s used by them.

The privacy angle

The privacy implications are straightforward once you’ve seen the traffic. Every suggestion you accept — and plenty you don’t — means your code context left your machine and went to a server you don’t control. For a personal project, that’s a mild shrug. For regulated code, it’s a real question, and it’s one your security team will ask if you’re in finance, health, or government.

The proxy exercise is genuinely useful in that conversation. “I’ve inspected the traffic and here’s exactly what’s in the request body” is a much better answer than “the privacy policy probably covers it.” If you’re going to argue for or against using Copilot at work, do the interception first so you’re arguing from evidence.

Limitations and caveats

MITMing Copilot has limits. The model’s weights and reasoning aren’t in the traffic — you see the input and output, not the internals, so you can explain what was sent but not fully why the model answered the way it did. The traffic also changes between client versions, so a payload shape you saw in June may look different by August. And as I mentioned, certificate pinning can block the whole exercise on some clients, at which point the proxy approach tops out and you’re left with vendor documentation and network logs.

There’s also a legal-and-policy question worth naming. Intercepting traffic on your own machine, to inspect a tool you’re using, is generally fine. Doing it on a machine or network you don’t control, or against a service whose terms forbid it, is a different situation. Use your own hardware, your own account, and your own code, and don’t poke at infrastructure that isn’t yours.

The bottom line

Putting Copilot behind a MITM proxy is the most educational hour you can spend on the tool. You learn that it’s not magic, it’s a prompt assembled from your surrounding code, sent with your credentials to a completion endpoint, and answered with structured suggestions. You learn what your context budget actually is, how much of your code leaves the machine, and where the confidence metadata hides.

It’s also the most direct way to answer the question that actually matters for a lot of teams: what, exactly, is going to that server? Most people answer that question from documentation. You can answer it from a packet capture, and those are very different levels of confidence. If you build AI-assisted tooling for work, do this once. It’ll change how you think about every assistant you use after it.

Sources

Disclosure: CarCare Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission at no extra cost to you. Learn more.
A
Alex Chen