kg-query

A command for asking questions against a linked knowledge wiki. It reads relevant pages and follows their links before producing an answer with wiki references.

In plain words
What is it for?
It helps inspect active work, recent activity, project decisions, plans, and general questions across the knowledge graph.
Why use it?
It provides a synthesized answer from connected notes instead of matching text in a single file.

Command

Part of the mykg plugin — 3 skills, 6 commands shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/ethics03/kgskill/kg-query
Clone the repo
git clone --depth 1 https://github.com/Ethics03/kgskill

Or install mykg, the plugin that ships this one along with the rest of its 3 skills, 6 commands.

Per session 21 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 559 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00021 $0.00559
Opus 5 $0.00010 $0.00280
Sonnet 5 $0.00004 $0.00112
Haiku 4.5 $0.00002 $0.00056

Measured 2d ago against content hash bb55674915c3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

kg-query scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/kg-query.md · 55 lines

What it actually says

Answer the user's question by searching and synthesizing knowledge from the wiki. This is not a grep — read pages, follow links, and produce a synthesized answer with wikilink citations.

Steps

1. Resolve KG path

Check in order: $MYKG_PATH env var → ~/.config/mykg/config~/.mykgrc → common locations (~/MyKG, ~/Dev/Obsidian/MyKG). If not found, tell the user to run /kg-setup first.

2. Handle utility subcommands

If the query is one of these, handle it directly and stop:

  • active — read and display Active.md
  • recent — read log.md and show the last 10 entries
  • decisions <project> — read <project>/Decisions/README.md and list ADRs; offer to read any in full
  • plan <project> — list files in <project>/Plans/ and offer to read any

3. For all other queries — synthesize from the wiki

This is the main path.

3a. Find relevant pages

Read index.md. Scan the catalog for pages relevant to the query — entities, concepts, synthesis, comparisons, source summaries. Pick the most relevant ones.

3b. Read and follow

Read the selected pages. Follow [[wikilinks]] to related pages where they add depth. Keep reading until you have enough to answer well — typically 3–8 pages.

3c. Synthesize an answer

Write a real answer, not a list of file contents. Integrate what you found across pages. Use [[Page Name]] citations inline so the user knows where claims come from.

3d. Note conflicts

If pages contradict each other on a relevant point, surface the contradiction explicitly rather than picking one silently.

4. Offer to file the answer back

After answering, ask: "Should I save this as a wiki page?" Good candidates:

  • A comparison or analysis that took multiple pages to synthesize
  • A connection between concepts that isn't captured anywhere yet
  • An answer that would save time on a future query

If yes, write it to the appropriate location (wiki/synthesis/, wiki/comparisons/, etc.), update index.md, and append to log.md:

## [YYYY-MM-DD] query | <Question>
- Synthesized: [[wiki/synthesis/<slug>]]
- Sources: [[wiki/X]], [[concepts/Y]]
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 55 lines · 0 tokens per session scan A bb55674915c3

Subscribe to this mod's changes

kg-query is a command published in the GitHub repository Ethics03/kgskill (3 stars, last pushed 4mo ago), licensed MIT. It adds 21 tokens to every session and 559 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.