/lineage:lineagefrom lineage
Answer "why does this line exist?" — trace a file, or a specific line, back to the change, prompt, agent, and session that produced it. Reads lineage's per-project change ledger and joins it to the transcripts historian preserves. Modes — /lineage <file> (change history), /lineage <file>:<line> or --line N (single-line provenance), /lineage <file> --grep <text> (content search), /lineage --status (ledger stats). Use when the user asks who/what/why introduced code in a file, or invokes /lineage.
Ships in lineage. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
/lineage reads the per-project change ledger that the PostToolUse hook records
and resolves each change's originating prompt by joining to historian's durable
session transcripts (falling back to the live transcript). It answers
"why does this line exist?" without an LLM call — pure read, join, and render.
Every block below needs this one: it sources the plugin helpers, loads config, and
resolves project context. The Bash tool may be zsh and keeps no functions between calls, so send this block inside bash, in one call:
bash <<'ONLOOKER_SKILL'
<this Setup block>
<the block for this mode>
ONLOOKER_SKILL
set -uo pipefail
export CLAUDE_SESSION_ID="${CLAUDE_SESSION_ID}"
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT}"
export CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT"
source "$PLUGIN_ROOT/scripts/lib/portable-lock.sh"
source "$PLUGIN_ROOT/scripts/lib/lineage-config.sh"
source "$PLUGIN_ROOT/scripts/lib/lineage-events.sh"
source "$PLUGIN_ROOT/scripts/lib/onlooker-project-key.sh"
source "$PLUGIN_ROOT/scripts/lib/lineage-redact.sh"
source "$PLUGIN_ROOT/scripts/lib/lineage-record.sh"
source "$PLUGIN_ROOT/scripts/lib/lineage-query.sh"
REPO_ROOT=$(onlooker_project_repo_root "$(pwd)")
lineage_config_load "$REPO_ROOT"
PROJECT_KEY=$(onlooker_project_key "$(pwd)")
if [[ -z "$PROJECT_KEY" ]]; then
echo "No project key — lineage needs a git repository (remote or root) to scope its ledger."
exit 0
fi
PROMPT_SOURCE=$(lineage_config_prompt_source)
QSID="${CLAUDE_SESSION_ID}"
/lineage <file> — change history (default)Set FILE to the path the user named, then run. (Repo-relative paths are
resolved against the repo root.)
FILE="REPLACE_WITH_FILE"
[[ "$FILE" != /* && -n "$REPO_ROOT" ]] && FILE="$REPO_ROOT/$FILE"
# Match the spelling the ledger stores. The lookup is an exact string compare,
# and the hook resolves every path it records, so a symlinked checkout would
# otherwise find nothing (ecosystem-htl).
FILE=$(lineage_resolve_path "$FILE")
echo "## Lineage — change history for \`$FILE\`"
count=0
while IFS= read -r rec; do
[[ -z "$rec" ]] && continue
count=$((count + 1))
ts=$(jq -r '.ts' <<<"$rec"); author=$(lineage_author_phrase "$rec")
turn=$(jq -r '.turn // ""' <<<"$rec"); tool=$(jq -r '.tool' <<<"$rec")
la=$(jq -r '.lines_added' <<<"$rec"); lr=$(jq -r '.lines_removed' <<<"$rec")
# How much of the change this record's content actually covers. Carried in
# the header because a list of changes is scanned, not read.
scope=$(lineage_scope_kind "$(jq -r '.content_scope // ""' <<<"$rec")" "$tool")
# An unknown-author record resolves no prompt: the only session it could
# reach is the one that happened to observe it (ONL-26).
resolved=$(lineage_resolve_record_prompt "$PROJECT_KEY" "$rec" "$PROMPT_SOURCE")
prompt=$(jq -r '.prompt' <<<"$resolved"); via=$(jq -r '.resolved_via' <<<"$resolved")
note=$(lineage_authorship_note "$rec")
echo ""
echo "### ${ts} · ${tool} (+${la}/-${lr}) · scope ${scope} · ${author}${turn:+ · turn ${turn}}"
[[ -n "$note" ]] && echo "_${note}_"
if [[ -n "$prompt" ]]; then
echo "Prompt context (${via}):"; echo ""
printf '%s\n' "$prompt" | head -c 600 | sed 's/^/> /'
else
echo "_Prompt unavailable (${via})._"
fi
done < <(lineage_changes_for_file "$PROJECT_KEY" "$FILE")
[[ "$count" -eq 0 ]] && { echo ""; echo "No recorded changes for this file (it may predate lineage)."; }
lineage_emit_event "lineage.query.answered" \
"$(jq -nc --arg pk "$PROJECT_KEY" --arg f "$FILE" --argjson m "$count" \
'{project_key:$pk, file_path:$f, matches:$m}')" "$QSID" || true
/lineage <file>:<line> (or --line N) — single-line provenanceSet FILE and LINE, then run. Reads the current line's text and content-anchors
it to the change that introduced it.
FILE="REPLACE_WITH_FILE"; LINE="REPLACE_WITH_LINE_NUMBER"
[[ "$FILE" != /* && -n "$REPO_ROOT" ]] && FILE="$REPO_ROOT/$FILE"
# Match the spelling the ledger stores. The lookup is an exact string compare,
# and the hook resolves every path it records, so a symlinked checkout would
# otherwise find nothing (ecosystem-htl).
FILE=$(lineage_resolve_path "$FILE")
line_text=$(sed -n "${LINE}p" "$FILE" 2>/dev/null)
needle=$(printf '%s' "$line_text" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
echo "## Lineage — why does \`$FILE\`:${LINE} exist?"
echo ""
echo "Line ${LINE}: \`${line_text}\`"
rec=$(lineage_match_line "$PROJECT_KEY" "$FILE" "$needle")
via="none"; matches=0
if [[ -z "$rec" ]]; then
echo ""
echo "No recorded change introduced this content (it may predate lineage, or the line moved since it was written)."
else
matches=1
ts=$(jq -r '.ts' <<<"$rec"); author=$(lineage_author_phrase "$rec")
turn=$(jq -r '.turn // ""' <<<"$rec"); tool=$(jq -r '.tool' <<<"$rec")
scope_raw=$(jq -r '.content_scope // ""' <<<"$rec")
# An unknown-author record resolves no prompt: the only session it could
# reach is the one that happened to observe it (ONL-26).
resolved=$(lineage_resolve_record_prompt "$PROJECT_KEY" "$rec" "$PROMPT_SOURCE")
prompt=$(jq -r '.prompt' <<<"$resolved"); via=$(jq -r '.resolved_via' <<<"$resolved")
note=$(lineage_authorship_note "$rec")
echo ""
echo "Introduced ${ts} by $(lineage_tool_phrase "$tool") in ${author}${turn:+ (turn ${turn})}."
# Always printed. A single-line answer is the one most likely to be quoted
# back as fact, so it is the one that most needs to say what it is worth.
echo ""
echo "_$(lineage_scope_note "$scope_raw" "$tool")_"
[[ -n "$note" ]] && { echo ""; echo "_${note}_"; }
if [[ -n "$prompt" ]]; then
echo ""; echo "Prompt context (${via}):"; echo ""
printf '%s\n' "$prompt" | sed 's/^/> /'
else
echo "_Prompt unavailable (${via})._"
fi
fi
lineage_emit_event "lineage.query.answered" \
"$(jq -nc --arg pk "$PROJECT_KEY" --arg f "$FILE" --argjson m "$matches" \
--argjson ln "${LINE:-0}" --arg via "$via" \
'{project_key:$pk, file_path:$f, matches:$m, line:$ln, resolved_via:$via}')" "$QSID" || true
/lineage <file> --grep <text> — content searchSame as the line mode, but set needle to the user's search text instead of
reading a line from the file:
FILE="REPLACE_WITH_FILE"; needle="REPLACE_WITH_TEXT"
[[ "$FILE" != /* && -n "$REPO_ROOT" ]] && FILE="$REPO_ROOT/$FILE"
# Match the spelling the ledger stores. The lookup is an exact string compare,
# and the hook resolves every path it records, so a symlinked checkout would
# otherwise find nothing (ecosystem-htl).
FILE=$(lineage_resolve_path "$FILE")
rec=$(lineage_match_line "$PROJECT_KEY" "$FILE" "$needle")
# …render as in the line mode…
/lineage --status — ledger statsLEDGER=$(lineage_record_path "$PROJECT_KEY")
echo "## Lineage status"
echo "- Project key: ${PROJECT_KEY}"
echo "- Ledger: ${LEDGER}"
if [[ -f "$LEDGER" ]]; then
total=$(wc -l < "$LEDGER" | tr -d ' ')
files=$(jq -r '.file_path' "$LEDGER" 2>/dev/null | sort -u | grep -c '')
echo "- Changes recorded: ${total} across ${files} file(s)"
else
echo "- No changes recorded yet. Make some Edit/Write changes with lineage enabled."
fi
transcript_path, then
"unavailable." Install and enable historian for the most reliable prompts.$ONLOOKER_DIR.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub onlooker-community/ecosystem --plugin lineage