Skip to content

Commit 964528a

Browse files
committed
Update context-mode feature to version 2.0.0, enhancing installation via postCreateCommand for proper plugin placement in mounted home directory
1 parent e6d5392 commit 964528a

4 files changed

Lines changed: 35 additions & 21 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Published to GHCR under the `sourecode/devcontainer-features` namespace.
1111
|---|---|---|
1212
| `claude-code` | `ghcr.io/sourecode/devcontainer-features/claude-code:2` | Installs the Claude Code CLI via the official native installer into `/usr/local/bin`, so the binary survives home-directory volume mounts. Requires Node.js — automatically pulls in the `nvm` feature via `dependsOn`. |
1313
| `rtk` | `ghcr.io/sourecode/devcontainer-features/rtk:2` | Installs [rtk](https://github.com/rtk-ai/rtk), an LLM token-reducing CLI proxy, into `/usr/local/bin`. Auto-patches Claude Code via `postCreateCommand` so the hook is written against the mounted home, not the image. |
14-
| `context-mode` | `ghcr.io/sourecode/devcontainer-features/context-mode:1` | Installs the [`context-mode`](https://github.com/mksglu/context-mode) Claude Code plugin. |
14+
| `context-mode` | `ghcr.io/sourecode/devcontainer-features/context-mode:2` | Installs the [`context-mode`](https://github.com/mksglu/context-mode) Claude Code plugin via `postCreateCommand`, so the plugin lands in the mounted `~/.claude` rather than the image. |
1515
| `nvm` | `ghcr.io/sourecode/devcontainer-features/nvm:2` | Installs [nvm](https://github.com/nvm-sh/nvm) system-wide at `/usr/local/share/nvm` and optionally a Node version (defaults to LTS), with `node`/`npm`/`npx` symlinked into `/usr/local/bin`. No yarn. |
1616

1717
All binaries land in `/usr/local/bin` (or `/usr/local/share/...`) rather than the user's home, so they survive the shared home-volume pattern described in [`docs/persistence.md`](docs/persistence.md). `rtk` and `context-mode` declare `installsAfter` for both `ghcr.io/sourecode/devcontainer-features/claude-code` and `ghcr.io/anthropics/devcontainer-features/claude-code`, so the runtime orders them after whichever claude-code feature is present.
@@ -29,7 +29,7 @@ image you already use:
2929
"ghcr.io/sourecode/devcontainer-features/rtk:2": {
3030
"autoPatchClaude": true
3131
},
32-
"ghcr.io/sourecode/devcontainer-features/context-mode:1": {}
32+
"ghcr.io/sourecode/devcontainer-features/context-mode:2": {}
3333
}
3434
}
3535
```
@@ -55,9 +55,10 @@ don't list `nvm` yourself.
5555

5656
#### `context-mode`
5757

58-
No options. Fails if the `claude` CLI is not on the user's PATH — add a
59-
claude-code feature as well (the `installsAfter` hint then makes the CLI
60-
resolve the correct install order automatically).
58+
No options. Runs via `postCreateCommand`, so it no-ops (with a warning) if
59+
the `claude` CLI isn't on PATH when the container is created — add a
60+
claude-code feature as well. `installsAfter` handles ordering for either
61+
`sourecode/` or `anthropics/` claude-code.
6162

6263
#### `nvm`
6364

docs/migration-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Typical `features` block for a C++ project:
161161
"ghcr.io/sourecode/devcontainer-features/nvm:2": {},
162162
"ghcr.io/sourecode/devcontainer-features/claude-code:2": {},
163163
"ghcr.io/sourecode/devcontainer-features/rtk:2": {},
164-
"ghcr.io/sourecode/devcontainer-features/context-mode:1": {}
164+
"ghcr.io/sourecode/devcontainer-features/context-mode:2": {}
165165
}
166166
```
167167

src/context-mode/devcontainer-feature.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"id": "context-mode",
3-
"version": "1.0.3",
3+
"version": "2.0.0",
44
"name": "context-mode (Claude Code plugin)",
5-
"description": "Installs the context-mode Claude Code plugin from the mksglu/context-mode marketplace. Requires a claude-code feature.",
5+
"description": "Installs the context-mode Claude Code plugin from the mksglu/context-mode marketplace via postCreateCommand, so the plugin lands in the mounted ~/.claude rather than the image. Requires a claude-code feature.",
66
"documentationURL": "https://github.com/SoureCode/devcontainer-features/tree/master/src/context-mode",
77
"options": {},
8+
"postCreateCommand": "/usr/local/share/context-mode/post-create.sh",
89
"installsAfter": [
910
"ghcr.io/sourecode/devcontainer-features/claude-code",
1011
"ghcr.io/anthropics/devcontainer-features/claude-code"

src/context-mode/install.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env bash
22
# context-mode Claude Code plugin installer.
33
# https://github.com/mksglu/context-mode
4+
#
5+
# `claude plugin install` writes to ~/.claude/plugins, which lives on the
6+
# volume-mounted home. Running it at build time only works for the very
7+
# first devcontainer create (during volume seeding) and is invisible on
8+
# every subsequent run. Defer the install to postCreateCommand so it runs
9+
# against the real mounted home every time.
410
set -e
511

612
if ! command -v git >/dev/null 2>&1; then
@@ -9,19 +15,25 @@ if ! command -v git >/dev/null 2>&1; then
915
rm -rf /var/lib/apt/lists/*
1016
fi
1117

12-
USER_NAME="${_REMOTE_USER:-${USERNAME:-root}}"
13-
14-
run_as_user() {
15-
if [ "$USER_NAME" = "root" ]; then
16-
bash -c "$1"
17-
else
18-
su - "$USER_NAME" -c "$1"
19-
fi
20-
}
18+
mkdir -p /usr/local/share/context-mode
19+
cat >/usr/local/share/context-mode/post-create.sh <<'EOF'
20+
#!/usr/bin/env bash
21+
# Written by the context-mode devcontainer feature at build time.
22+
# Runs as the remote user via postCreateCommand so the plugin lands in
23+
# the mounted ~/.claude, not the image.
24+
set -e
2125
22-
if ! run_as_user 'command -v claude >/dev/null 2>&1'; then
23-
echo "context-mode feature: claude CLI not found. Install a claude-code feature (e.g. ghcr.io/sourecode/devcontainer-features/claude-code) first." >&2
24-
exit 1
26+
if ! command -v claude >/dev/null 2>&1; then
27+
echo "context-mode feature: claude CLI not on PATH, skipping plugin install. Install a claude-code feature (e.g. ghcr.io/sourecode/devcontainer-features/claude-code) to enable it." >&2
28+
exit 0
2529
fi
2630
27-
run_as_user 'claude plugin marketplace add mksglu/context-mode && claude plugin install context-mode@context-mode'
31+
mkdir -p "$HOME/.claude"
32+
33+
# Both commands are idempotent on re-run: `marketplace add` is a no-op if the
34+
# marketplace is already registered, and `plugin install` short-circuits if
35+
# the plugin is already installed at the same version.
36+
claude plugin marketplace add mksglu/context-mode
37+
claude plugin install context-mode@context-mode
38+
EOF
39+
chmod 0755 /usr/local/share/context-mode/post-create.sh

0 commit comments

Comments
 (0)