/kmgraph:kmg-link-issuefrom kmgraph
Links an existing lesson-learned or ADR file to a GitHub issue, updating YAML frontmatter with issue/PR metadata, posting a comment to the issue, and updating the knowledge graph entry with a bidirectional reference.
Claude never picks this command on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /kmgraph:kmg-link-issue still runs it.
Manually link an existing lesson-learned or ADR to a GitHub issue, creating bidirectional references.
/kmgraph:kmg-link-issue knowledge/lessons-learned/process/my-lesson.md --issue 42
/kmgraph:kmg-link-issue knowledge/decisions/ADR-005.md --issue 38 --pr 40
gh CLI available)file_path="$1"
issue_num="$2"
pr_num="${3:-null}"
# Check file exists
if [ ! -f "$file_path" ]; then
echo "Error: File not found: $file_path"
exit 1
fi
# Check issue number provided
if [ -z "$issue_num" ]; then
echo "Error: Missing issue number"
echo "Usage: /kmgraph:kmg-link-issue <file> --issue <num> [--pr <num>]"
exit 1
fi
# Read current frontmatter
frontmatter=$(sed -n '/^---$/,/^---$/p' "$file_path")
# Check if git metadata exists
if echo "$frontmatter" | grep -q "^git:"; then
# Update existing git section
sed -i.bak "/^git:/a\ issue: $issue_num" "$file_path"
if [ "$pr_num" != "null" ]; then
sed -i.bak "/^git:/a\ pr: $pr_num" "$file_path"
fi
else
# Add new git section
sed -i.bak "/^---$/i\git:\n issue: $issue_num\n pr: $pr_num" "$file_path"
fi
rm "$file_path.bak"
if command -v gh &> /dev/null; then
# Extract title from frontmatter
title=$(grep "^title:" "$file_path" | sed 's/title: "\(.*\)"/\1/')
# Extract file path relative to repo root
relative_path=$(git ls-files --full-name "$file_path" 2>/dev/null || echo "$file_path")
# Post comment
gh issue comment "$issue_num" --body "📚 Lesson Learned: [$title]($relative_path)
A lesson has been documented for this issue.
Branch: $(git branch --show-current)
Commit: $(git rev-parse --short HEAD)
See: $relative_path"
echo "✅ Comment posted to issue #$issue_num"
else
echo "⚠️ gh CLI not available - skipping GitHub comment"
fi
Resolve the target graph first (issue-41: this previously read jq -r '.graphs[.active].path' ~/.kmgraph/kg-config.json, a pre-ADR-067 pattern):
kg_resolve
Take the returned path as $kg_path below.
# Search for KG entry referencing this lesson
kg_entry=$(grep -l "$(basename $file_path)" "$kg_path"/knowledge/*.md 2>/dev/null || true)
if [ -n "$kg_entry" ]; then
# Add issue reference to KG entry
echo "Issue #$issue_num referenced" >> "$kg_entry"
echo "✅ KG entry updated with issue reference"
fi
echo ""
echo "✅ Lesson linked to GitHub issue #$issue_num"
echo ""
echo "Updated: $file_path"
if [ "$pr_num" != "null" ]; then
echo "PR: #$pr_num"
fi
echo ""
echo "Bidirectional links created:"
echo " Lesson → Issue: YAML frontmatter updated"
echo " Issue → Lesson: GitHub comment posted (if gh CLI available)"
✅ Comment posted to issue #42
✅ KG entry updated with issue reference
✅ Lesson linked to GitHub issue #42
Updated: knowledge/lessons-learned/process/auth-race-condition.md
PR: #40
Bidirectional links created:
Lesson → Issue: YAML frontmatter updated
Issue → Lesson: GitHub comment posted
⚠️ gh CLI not available - skipping GitHub comment
✅ Lesson frontmatter updated with issue reference
Note: Install gh CLI for automatic GitHub comment posting:
brew install gh
Error: File not found: knowledge/lessons-learned/nonexistent.md
Error: Missing issue number
Usage: /kmgraph:kmg-link-issue <file> --issue <num> [--pr <num>]
/kmgraph:kmg-capture-lesson — Create new lesson with automatic git metadata/kmgraph:kmg-update-issue-plan — Sync KG to plan and GitHub issueWhat the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub technomensch/knowledge-graph --plugin kmgraph31 commands in this plugin
/kmg-add-category/kmgraph:kmg-add-category — Add Category to Knowledge GraphAdd a new category to the active knowledge graph with optional custom prefix and git strategy./kmg-backfillBackfill Knowledge Graph from Existing Content<!-- Created: 2026-09-04 (ADR-071) -->/kmg-capture-lessonDocument Lessons Learned**Version:** 2.0 (Updated: 2026-03-27)/kmg-check-sensitive/kmgraph:kmg-check-sensitive — Scan for Sensitive DataScan the knowledge graph resolved from the current directory for potentially sensitive information, using regex patterns from config or defaults./kmg-config-sanitization/kmgraph:kmg-config-sanitization — Setup Sanitization HooksInteractive wizard to help users set up pre-commit hooks that scan for potentially sensitive information before committing knowledge graph entries./kmg-create-adrCreate Architecture Decision Record**Purpose:** Create a new Architecture Decision Record (ADR) using the knowledge graph resolved from the current directory. Auto-fills git metadata, auto-increments the ADR number, prompts for decision content, and updates the decisions index.