From 770bf3d889a373b7964f0c9a4ec0a75443f8c36c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 19:59:47 +0000 Subject: [PATCH 1/2] Initial plan From 0c42c3aeea444af6df2cd5571f56349910ab3947 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 20:03:44 +0000 Subject: [PATCH 2/2] feat: persist Copilot CLI credentials in dev container via named volume Agent-Logs-Url: https://github.com/CodeAlanDebug/copilot-cli-for-beginners/sessions/db1603a8-032a-4254-947f-833e116c31e1 Co-authored-by: CodeAlanDebug <106265297+CodeAlanDebug@users.noreply.github.com> --- .devcontainer/devcontainer.json | 5 ++++- .devcontainer/startup.sh | 7 ++++++ 00-quick-start/README.md | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/startup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c0831c56..7c629ff2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,6 +5,9 @@ "ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/devcontainers/features/node:1": {} }, + "mounts": [ + "source=copilot-cli-credentials,target=/home/vscode/.config/github-copilot,type=volume" + ], "customizations": { "vscode": { "extensions": [ @@ -13,5 +16,5 @@ } }, "onCreateCommand": "pip install pytest && npm install -g @github/copilot", - "postStartCommand": "echo '✅ Python, pytest, GitHub CLI, and Copilot CLI are ready. Run: cd samples/book-app-project && python book_app.py help'" + "postStartCommand": "bash .devcontainer/startup.sh" } diff --git a/.devcontainer/startup.sh b/.devcontainer/startup.sh new file mode 100755 index 00000000..f29c26ec --- /dev/null +++ b/.devcontainer/startup.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +echo '✅ Python, pytest, GitHub CLI, and Copilot CLI are ready. Run: cd samples/book-app-project && python book_app.py help' +if ls ~/.config/github-copilot/*.json &>/dev/null; then + echo '🔑 Copilot CLI credentials found — you are already signed in.' +else + echo '🔑 No credentials found — open the Copilot CLI session (run: copilot) and then type /login to authenticate.' +fi diff --git a/00-quick-start/README.md b/00-quick-start/README.md index a0e1da61..d1b1fd9f 100644 --- a/00-quick-start/README.md +++ b/00-quick-start/README.md @@ -121,6 +121,45 @@ After trusting the folder, you can sign in with your GitHub account. **Tip**: The sign-in persists across sessions. You only need to do this once unless your token expires or you explicitly sign out. +### Persisting Credentials in Dev Containers + +When you work inside a **dev container** (locally or via a Codespace), credentials can be lost when the container is rebuilt — because the container's file system starts fresh. Here is how each environment handles this: + +| Environment | What happens to credentials | +|---|---| +| **Local install** (no container) | Credentials persist in `~/.config/github-copilot/` on your machine | +| **GitHub Codespace** | Credentials persist within the *same* Codespace; creating a *new* Codespace requires one-time re-authentication | +| **Local dev container** | Credentials are stored in a named Docker volume (`copilot-cli-credentials`) that survives container rebuilds automatically | + +#### How credential persistence works in this repo's dev container + +The `.devcontainer/devcontainer.json` in this repo mounts a named Docker volume at the path where Copilot CLI stores its credentials: + +```json +"mounts": [ + "source=copilot-cli-credentials,target=/home/vscode/.config/github-copilot,type=volume" +] +``` + +**What this means for you:** + +- **First time**: Open the dev container, start the Copilot CLI session (`copilot`), and then type `/login` inside the session to authenticate once. +- **After a rebuild**: Your credentials are loaded automatically from the volume — no need to log in again. +- **Start fresh**: To reset credentials, delete the named volume from Docker Desktop (Volumes tab) or run `docker volume rm copilot-cli-credentials` in your terminal, then re-authenticate. + +> 💡 **Status check at startup**: Each time the container starts, the terminal shows a 🔑 line telling you either that credentials were found (and you are already signed in) or that no credentials were found (and you need to run `/login`). + +#### Re-authenticating when needed + +If you see an authentication error, or if you created a new Codespace, simply sign in again: + +```bash +copilot +> /login +``` + +Follow the same device-flow steps described above. + --- ## Verify It Works