Skip to content

Auto-inject SKILL.md on session start when devcontainer is detected #19

@aniongithub

Description

@aniongithub

Summary

Add a sessionStart hook that detects .devcontainer/devcontainer.json in the working directory and injects the devcontainer-mcp SKILL.md content via additionalContext output. This makes the agent automatically aware of devcontainer-mcp tools without requiring manual skill installation or agent-specific configuration.

Motivation

Currently, agents learn about devcontainer-mcp through SKILL.md files installed in agent-specific skill directories (~/.copilot/skills/, ~/.claude/skills/, etc.). This has several limitations:

  • Requires each agent environment to be individually configured
  • SKILL.md can go stale if the installed version diverges from the binary
  • New agent environments require manual setup
  • The agent may not discover the skill at all if the directory structure changes

A sessionStart hook solves all of these — the hook fires on every session, checks for a devcontainer, and injects the current SKILL.md directly into context.

Proposed design

Copilot CLI (~/.copilot/hooks/devcontainer-skill-loader.json)

{
  "version": 1,
  "hooks": {
    "sessionStart": [
      {
        "type": "command",
        "bash": "~/.local/share/devcontainer-mcp/hooks/devcontainer-skill-loader.sh",
        "timeoutSec": 5
      }
    ]
  }
}

Hook script (devcontainer-skill-loader.sh)

#!/usr/bin/env bash
set -euo pipefail

INPUT=$(cat)
CWD=$(echo "$INPUT" | jq -r '.cwd // empty')

if [ -z "$CWD" ] || [ ! -f "${CWD}/.devcontainer/devcontainer.json" ]; then
  exit 0
fi

# Read the SKILL.md content
SKILL_PATH="${HOME}/.local/share/devcontainer-mcp/SKILL.md"
if [ ! -f "$SKILL_PATH" ]; then
  # Fall back to installed skill locations
  for dir in "${HOME}/.copilot/skills/devcontainer-mcp" "${HOME}/.claude/skills/devcontainer-mcp"; do
    if [ -f "${dir}/SKILL.md" ]; then
      SKILL_PATH="${dir}/SKILL.md"
      break
    fi
  done
fi

if [ ! -f "$SKILL_PATH" ]; then
  exit 0
fi

SKILL_CONTENT=$(cat "$SKILL_PATH")

# Output additionalContext — injected into the session
jq -n --arg ctx "$SKILL_CONTENT" '{ "additionalContext": $ctx }'

Claude Code (~/.claude/settings.json)

Claude Code supports SessionStart hooks with the same additionalContext output:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.local/share/devcontainer-mcp/hooks/devcontainer-skill-loader.sh",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

Benefits

  • Zero-config agent awareness — any agent with hook support automatically learns about devcontainer-mcp
  • Always current — reads SKILL.md from the installed copy, never stale
  • Conditional — only injects when a devcontainer actually exists
  • Lightweight — fires once per session, reads one file

References

Relationship to existing work

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions