fix: JSON-escape hook content in session-start hook

Fixes issue #89: session-start hook now properly escapes SKILL.md content
when constructing JSON output, preventing parse errors when markdown
contains quotes or control characters.

Uses jq -cn with --arg flag to properly escape all special characters
in the message field.
This commit is contained in:
james
2026-04-24 23:06:28 -07:00
parent 1f66d57a5e
commit 43a0dde996
+6 -7
View File
@@ -8,13 +8,12 @@ META_SKILL="$SKILLS_DIR/using-agent-skills/SKILL.md"
if [ -f "$META_SKILL" ]; then
CONTENT=$(cat "$META_SKILL")
# Output as JSON for Claude Code hook consumption
cat <<EOF
{
"priority": "IMPORTANT",
"message": "agent-skills loaded. Use the skill discovery flowchart to find the right skill for your task.\n\n$CONTENT"
}
EOF
# Use jq to properly escape and construct valid JSON
jq -cn \
--arg message "agent-skills loaded. Use the skill discovery flowchart to find the right skill for your task.
$CONTENT" \
'{priority: "IMPORTANT", message: $message}'
else
echo '{"priority": "INFO", "message": "agent-skills: using-agent-skills meta-skill not found. Skills may still be available individually."}'
fi