cookbook

The question you'd ask a teammate
→ the exact command.

16 real questions, grouped by situation. Every command is copy-pasteable and matches the CLI reference exactly — nothing here is aspirational. Output shapes are excerpts of the real thing; your numbers and file paths will differ.

daily questions

"Where is this, who calls that."

01

Find something from a few words

"Where's the refund flow?"
ctx-optimize query "refund flow"
Get: ranked, complete hits under a token budget — kind, file, line range, signature:
Refund flow  [section]  README.md L3-L6
ProcessRefund  [function]  pay.go L3-L3
query
02

Who calls this function?

"If I touch Store.Merge, who's depending on it?"
ctx-optimize card "Store.Merge"
Get: signature, doc comment, exact location, callers and callees — no file read needed:
Store.Merge  [method]  internal/store/store.go L200-L273
  sig: func (s *Store) Merge(b *schema.Batch) (nodesAdded, edgesAdded int, err error)
  doc: Merge upserts a validated batch into the graph...
  called by (12): cmdAdd, cmdSync, cmdMerge, ...
  calls (6): Batch.Validate, writeNDJSON, ...
card
03

Orient yourself in a repo you've never seen

"What are the load-bearing pieces of this codebase?"
ctx-optimize hubs --top 10
# or browse the generated map:
open ~/ctxoptimize/<repo>/wiki/
Get: the most-connected nodes in the graph — usually the real entry points and core types, ranked by fan-in/fan-out — plus a full navigable markdown wiki regenerated on every gather.
hubs
04

Connect two symbols you know are related, but not how

"How does the CLI's add command reach the store's merge logic?"
ctx-optimize path "cmdAdd" "Store.Merge"
Get: the shortest path through the graph between the two nodes — the call/import chain that connects them, with each hop's file:line.
path
05

Get a plain-language read on an unfamiliar node

"What is this thing and what's around it?"
ctx-optimize explain "PaymentService"
Get: the node plus its immediate neighborhood in prose — what it is, what touches it — before you decide whether it's worth a full card or change-plan.
explain
before you edit

"What breaks if I change this."

06

About to change a function — the composed answer

"I'm about to edit validateRefund — what do I need to know before I touch it?"
ctx-optimize change-plan validateRefund
Get: ONE call replacing a query+card+affected+grep chain — signature, callers, blast radius, which tests to run, historical co-change, and a confidence footer separating extracted fact from inferred guesses:
callers (1):
  pay.go::ProcessRefund
blast radius (depth 2, 2 shown): ...
tests to run: pay_test.go::TestProcessRefund
confidence: 4 EXTRACTED, 1 INFERRED
Measured on this repo's own source: ~90% fewer answer tokens than the chain it replaces. Alias: plan.
change-plan
07

Just the blast radius, nothing else

"What breaks if I change this type's shape?"
ctx-optimize affected PaymentService --depth 2
Get: the reverse-impact walk — every node that reaches this one, to the depth you ask for — without the callers/tests framing change-plan adds.
affected
08

Trust but verify a citation before acting on it

"That line range — does it actually still hold?"
ctx-optimize verify "pay.go:L1-L5"; echo $?
# 0 — node exists, file exists, range in bounds, no drift vs gather-time HEAD
ctx-optimize verify "pay.go:L900-L950"; echo $?
# 1 — out of bounds, refused
Get: a hard yes/no on whether a claimed file:line still holds — exit 0 only when every claim in the citation checks out. Use it before a human acts on an agent's answer.
verify
trust & freshness

"Can I believe what this store just told me."

09

Is the store even current?

"Did the code move since this graph was built?"
ctx-optimize status
# fresh:  ✗ STALE — store at 8a5057b, repo now at 03d0f49; run: ctx-optimize add .
ctx-optimize fresh; echo $?   # 0 fresh / 1 stale / 2 unknown (no git HEAD)
Get: node/edge counts, remote, and a freshness verdict against git HEAD. Wire fresh into a pre-commit hook or CI step so nothing answers from a stale snapshot.
status · fresh
10

Refresh after the store went stale

"I just committed — bring the graph up to date."
ctx-optimize up
Get: the one verb that always does the right thing — fast re-gather when stale, no-op when fresh, bootstrap when missing, pull when the team declared a remote. Idempotent; run it whenever.
up
beyond code

"The answer isn't in the repo — it's in prod."

11

Get a live database schema into the graph

"What tables does the billing service actually have?"
ctx-optimize adapters help postgres          # the setup card: value format, credential params
export BILLING_DB_URL='postgres://reader:$PG_PASS@db.internal:5432/billing'
ctx-optimize add BILLING_DB_URL              # dial, capture the logical shape, merge, record
Get: tables, columns, and foreign keys as graph nodes — queryable alongside the code that reads them. Secrets stay as the env-var name, never a literal value, in config or output. Refreshes on every up under a 24h TTL.
add <ENV_NAME>
12

Debug a source without touching the store

"Is this connection string even reaching the right database?"
ctx-optimize capture BILLING_DB_URL
# {"producer":"source:BILLING_DB_URL", "nodes":[...], ...} — printed, nothing written
Get: one dial, the raw Batch JSON on stdout, no store mutation — a safe way to sanity-check a source before it's part of the graph.
capture
13

Where do our prod Kubernetes services live?

"What's actually deployed, per the manifests we commit?"
ctx-optimize query "prod namespace service ingress"
Get: k8s Deployments/Services/Ingress/ConfigMaps parsed straight from committed YAML — real cluster topology as graph nodes, ranked by the terms you gave it. (This is lexical retrieval, not a structured field filter — phrase your query with the labels/namespaces you expect to see.)
query
14

Feed in something with no native connector

"Our ticketing system isn't Postgres or Kafka — can it be in the graph anyway?"
cat > .ctxoptimize/adapters/tickets.sh <<'EOF'
#!/bin/sh
echo '{"producer":"tickets","nodes":[{"id":"t:1","label":"TCK-1 checkout bug","kind":"ticket","file_type":"external","source":"tickets"}]}'
EOF
ctx-optimize add .        # "adapter tickets: 1 nodes, 0 edges"
ctx-optimize query "TCK-1"
Get: a permanent, drop-in producer — the file existing IS the registration, no config entry needed. Works for anything you can express as nodes and edges: PDFs converted to markdown, proprietary tools, log shapes, or the strict --json door (my-exporter | ctx-optimize add --json -) for one-off feeds.
adapters
monorepos

"This repo has forty services in it."

15

Ask a question scoped to just the module you're in

"What's the dev-only dependency surface for the service I'm sitting in?"
cd services/billing
ctx-optimize query "dev dependency"
Get: results scoped to services/billing's own store — not ranked against every other module's noise — including dep: nodes for anything it imports, federated across whatever build tool declared it. A miss escalates repo-wide automatically and labels which module actually answered.
query (scoped)
16

Combine a few modules into one view

"I want api and worker's graphs as one thing, just this once."
ctx-optimize merge api worker --into everything
Get: one derived, combined store — opt-in, not the default. Re-derive it after a pull; it isn't kept in sync automatically.
merge
team & onboarding

"New repo, new machine, new teammate."

17

Onboard a brand-new repo, or your own fresh clone

"Get me a store for this repo, whatever that takes."
cd my-repo && ctx-optimize up
Get: the same one verb whether it's a bare repo (bootstraps + gathers), a monorepo (scan-bootstraps a store per module + a navigator), or a clone where a teammate already declared a shared store (pulls it instead of re-gathering). Idempotent — safe to run again.
up
18

Share your gathered store with the team

"I don't want every teammate re-gathering the same graph."
ctx-optimize remote push    # runs the script YOUR team declared in .ctxoptimize/config.json
# teammate, on a fresh clone:
ctx-optimize up             # pulls the prebuilt store instead of gathering locally
Get: the binary ships no transport of its own — push/pull run the commands your team declares (a private git repo, S3, anything). init scaffolds a ready-to-arm git lane as inert samples.
remote push · pull
further reading

The mental model behind these commands, and the outcome-framed walkthroughs.

Read Concepts for the graph model these recipes query, and Use cases for the narrative version of onboarding, refactoring safely, and sharing a store across a team. Every verb here is documented in full on the CLI reference.