# C3 — Connect Claude Code to GitHub via MCP

> **Summary — what this page covers**
> Bring your **C2 steering kit** into an **IDE** (VS Code or Rider), then connect Claude Code to the
> **GitHub MCP server** so it can read real issues and file a new one. You'll create a Personal Access
> Token, register the server (committed `.mcp.json` *or* the CLI), and file the **"Add Reading Progress
> tracking"** issue — the feature you build next in Lab 4. An **offline fallback** keeps the lab working
> with no network.
>
> **Time:** ~40 minutes · **Format:** hands-on, solo · **You start from:** `checkpoint/c2-steering-kit` · **You end at:** `checkpoint/c3-github-mcp`

C3 is the **lowest-code-delta** lab of Day 1 — there is **no C# change**. The `.claude/` steering kit
you built in C2 just keeps applying, now inside an IDE. The committed delta is two small things: a
project-scoped **`.mcp.json`** and an offline-fallback **`proposed-issues/`** folder. The point is a
reproducible MCP setup and a clean **query → action** pattern you can practice even if the room's
network dies.

---

## 1. Prerequisites

Start the slow, external step **first** — see step 3.

- **Start from the C2 checkpoint.** Continue your working branch, or branch fresh:

  ```bash
  git switch -c my-c3 checkpoint/c2-steering-kit
  cd src/BookTracker
  ```

- **An IDE with the Claude Code extension** (step 2).
- **A GitHub Personal Access Token** (step 3).
- **Internet** to reach the GitHub MCP server — with an **offline fallback** in step 6 if you don't
  have it.

> No new tools to build, no migrations, no tests to add. If `dotnet build` and `dotnet test` were green
> at C2, they stay green here — nothing in the C# changes.

---

## 2. Install the IDE extension and confirm the C2 kit travels

Install the Claude Code extension for your IDE:

- **VS Code:**

  ```bash
  code --install-extension anthropic.claude-code
  ```

- **JetBrains / Rider:** Marketplace → search **"Claude Code"** → install → **restart** the IDE.

Now prove the same agent and the same `.claude/` config follow you into the IDE — only the diff UI
changes:

1. Open a file under `BookTracker.Api/Endpoints/` (e.g. `BookEndpoints.cs`).
2. In the IDE's Claude Code panel, run:

   ```text
   /memory
   ```

3. Confirm the C2 **`api-endpoints`** rule loads — same agent, same `.claude/rules/`, different diff UI.

> When Claude edits code in the IDE, you review it as a **reviewable diff**: inline in VS Code, or via
> the **merge tool** in Rider. Resume a session in the integrated terminal with `claude --continue`.

---

## 3. Create a GitHub Personal Access Token

This is the **slow, internet-dependent** step — do it first so it's ready when you need it.

- **Simplest:** a **classic** token with the **`repo`** scope.
- **Fine-grained alternative** (on the BookTracker repo): **Issues — read/write**, **Pull requests —
  read**, **Contents — read**.

Copy the token somewhere safe for the next step. **Never commit it.**

---

## 4. Register the GitHub MCP server

Two ways — the committed config is the checkpoint artifact; the CLI form is worth knowing.

### (a) Committed `.mcp.json` (the checkpoint way)

C3 ships a project-scoped `src/BookTracker/.mcp.json`. The token is an **env var**, so the file holds
**no secret**:

```json
{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": { "Authorization": "Bearer ${GITHUB_PAT}" }
    }
  }
}
```

Export your token, then launch Claude Code — `${GITHUB_PAT}` expands at launch:

```bash
export GITHUB_PAT=ghp_your_token_here
claude
```

### (b) The CLI form

```bash
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer ghp_your_token_here"
```

### Confirm the connection

```bash
claude mcp list      # should show: github - connected
```

> If you keep a token in a local `.env`, **gitignore it**. The committed `.mcp.json` only ever
> references `${GITHUB_PAT}` — the secret stays on your machine.

---

## 5. Query, then act — list issues and file a new one

Use the **query → action** pattern. First the read-only query:

```text
List the open issues on this repository.
```

Then the action — file the feature you'll build in Lab 4:

```text
Create a GitHub issue titled "Add Reading Progress tracking". The feature should track the
current page, total pages, and a status (reading / completed / want-to-read), with start and
finish dates. Include acceptance criteria, the affected files, and a complexity estimate.
```

Creating an issue is a **real outward action**, so Claude hits a **permission prompt** before it acts —
approve it to file the issue. That prompt is the teaching beat, not a bug.

> This is the feature you **build in Lab 4 (C4)**: file the issue now, build it after. The canned issue
> body in `proposed-issues/reading-progress.md` mirrors what Claude files here.

---

## 6. Offline fallback (no network / GitHub down)

If you can't reach GitHub, practice the same **query → action** pattern locally:

- **Query half** — have Claude read recent history instead of the live repo:

  ```text
  Read proposed-issues/recent-history.txt and tell me what's been happening and what
  looks like a good first contribution.
  ```

  (`recent-history.txt` is a captured `git log --oneline -20`.)

- **Action half** — have Claude write the issue body to a file instead of GitHub:

  ```text
  Write the "Add Reading Progress tracking" issue to proposed-issues/reading-progress.md
  with acceptance criteria, affected files, and a complexity estimate.
  ```

Writing the file **is** the action when the network is down. The instructor's recorded GitHub MCP demo
is the live-version backup.

---

## ✅ Checkpoint — you're done when:

- [ ] The IDE extension is installed and a Claude edit shows as a reviewable **diff** (VS Code inline /
      Rider merge tool); `/memory` loads the **C2 `api-endpoints` rule in the IDE**.
- [ ] `claude mcp list` shows `github` **connected** (via committed `.mcp.json` + `GITHUB_PAT`, or the
      CLI form).
- [ ] Claude **listed real issues** and **created** the "Add Reading Progress tracking" issue — or,
      offline, wrote it to `proposed-issues/reading-progress.md`.
- [ ] `.mcp.json` is committed and contains **no secret**; `proposed-issues/` is present.
- [ ] `dotnet build` and `dotnet test` are still green (nothing in the C# changed).

> This is the state captured at `checkpoint/c3-github-mcp` — the tag is your answer key.

---

## What's next

**Lab 4 (C3 → C4):** you'll **build the Reading Progress feature** you just filed — the
`ReadingProgress` entity, service rules, endpoints, migration, and tests — ending at
`checkpoint/c4-reading-progress`. C3 was "use an MCP server"; later in Day 2 you'll **build your own**
in C#.
