Setting up at a new company
This guide takes one person through the whole first setup of Safran at a company: a seed profile with three connectors, the tokens, the checks, the first index, a discovered draft that you review, agents connected to the result, and a first measurement. Every command is the real one, and the output shown was captured from a small temporary setup of the acme story.
The whole path
safran init # 1. seed profile: tracker + code host + embedder
safran profile check # 3. validate offline, then with --online
safran doctor # 4. Bun, git, tokens, embedder, repos
safran sync # 5. clone and index
safran links refresh # 6. merged pull requests -> ticket <-> code store
safran discover # 7. writes safran.draft.yaml for review
safran eval golden # 10. build a golden set from your own history
safran eval retrieval # 10. measure code search against itSteps 2 (tokens), 8 (review the draft) and 9 (connect agents) are yours. safran here is
bin/safran of the Safran checkout; see requirements for Bun, git
and the embedding model, and the quickstart for the short version of
this page.
1. Write a seed profile
Pick a directory for the company (the examples use /work/acme). The profile, the .env file
and the data directory will live there. A seed profile holds only what you know for certain:
the tracker, the code host and the embedder. Groups, teams, glossary and conventions come later,
drafted by discovery.
$ safran init --yes --company acme --language tr --tracker jira --set tracker.url=https://acme.atlassian.net --set tracker.projects=PAY,MOB,WEB --host azure-repos --set host.organization=acme --set host.projects=Platform
✔ Wrote safran.yaml
Set these environment variables, in your shell or in a .env file next to the profile:
AZURE_DEVOPS_PAT ! not set
JIRA_EMAIL ! not set
JIRA_TOKEN ! not set
Next
safran profile check validate the profile and every connector
safran doctor check git, the embedder and the index
safran sync clone or read the repositories and index them
safran discover draft groups, teams and glossary from merged pull requestsWithout --yes, safran init asks the same questions one by one. It only writes the file: it
contacts no service and stores no secret. It names each connector entry after its type
(id: azure-repos); rename the id by hand if you want a shorter one, as the rest of this
guide does (azure). Flags are listed in the setup commands.
version: 1
company: acme
languages:
tickets: tr
code: en
trackers:
- id: jira
type: jira
url: https://acme.atlassian.net
email_env: JIRA_EMAIL
token_env: JIRA_TOKEN
projects: [PAY, MOB, WEB]
code:
hosts:
- id: azure
type: azure-repos
organization: acme
project: Platform
token_env: AZURE_DEVOPS_PAT
embeddings:
type: ollama
model: bge-m3Every field is described in the profile reference; the fields of one connector are on its page under connectors.
2. Set the tokens
The profile holds only the names of environment variables (every field ending in _env).
Put the values in a .env file next to the profile, or export them in your shell:
JIRA_EMAIL=dev@acme.test
JIRA_TOKEN=...
AZURE_DEVOPS_PAT=...The CLI reads the .env that sits next to the profile file. A variable that is already set in
the shell is never overridden by the file. .env and safran.yaml are git-ignored in the
Safran checkout; keep them out of any other repository too. Which permissions each token needs
is on the connector's page; how secrets are handled is in secrets.
3. Validate the profile
safran profile check parses the profile, builds every connector and lists the environment
variables the profile refers to. It is offline by default: a missing token shows as not set
and nothing is called.
$ safran profile check
✔ safran.yaml is valid
company acme
languages tickets tr, code en
trackers jira
code hosts azure-repos
doc sources none
groups none
teams none
glossary 0 terms
conventions 0
embeddings ollama (bge-m3)
data data
Environment variables
name status used by
AZURE_DEVOPS_PAT not set code.hosts.azure-repos.token_env
JIRA_EMAIL not set trackers.jira.email_env
JIRA_TOKEN not set trackers.jira.token_env
! AZURE_DEVOPS_PAT, JIRA_EMAIL, JIRA_TOKEN are not set; the connectors that use them will fail when called.
→ Export them in your shell, or put them in a .env file next to the profile.
Connectors were built, not called. `safran profile check --online` makes one call to each.Once the tokens are set, add --online: it makes one cheap call per connector (list projects,
list repos), which is where a rejected token or a wrong URL shows up. The end of its output:
$ safran profile check --online
…
Online check
✔ tracker jira: 1 project visible
✔ code-host azure: 2 repos listedA profile that does not validate prints the path of every problem; they are explained in validation errors.
4. Check the environment
safran doctor checks what the profile cannot: the Bun version, git, how the CLI was started,
every referenced variable, the embedder (one tiny embedding call) and the repo listing. It
exits with code 1 when a check fails; warnings do not fail it.
$ safran doctor
✔ bun Bun 1.3.2
✔ git git version 2.50.1 (Apple Git-155)
✔ launch started through bin/safran: Bun loaded no .env or bunfig.toml from this directory
✔ profile safran.yaml (acme): 1 tracker, 1 code host
✔ env JIRA_TOKEN set (used by trackers.jira.token_env)
✔ embedder ollama:bge-m3 answered in 34 ms (1024 dimensions)
✔ repos 2 repos listed
! index not built yet
→ Run `safran sync --profile /work/acme/safran.yaml`.
! links the ticket ↔ code store is empty
→ Run `safran links refresh --profile /work/acme/safran.yaml`.
! No failures, 2 warnings.The two warnings are the next two steps. If embedder fails, fix that first: the sync opens
the index (and so the embedder) before it clones anything, so that a missing embedding server
fails in a second and not after every repository has been fetched.
5. First sync
$ safran sync
payments-api scanning files
payments-api indexing 4/4 files 100%
ledger scanning files
ledger indexing 1/1 files 100%
repo status changed unchanged chunks time detail
✔ payments-api ok 4 0 4 157 ms 4 embedded, 0 from cache
✔ ledger ok 1 0 1 41 ms 1 embedded, 0 from cache
2 repos: 2 ok in 206 mssafran sync clones each repository the code hosts list (a shallow clone of the default
branch; local hosts are read in place), splits the files into chunks, embeds the chunks and
writes them to the index under the data directory (data/ next to the profile).
The run can be interrupted with Ctrl-C and started again; it continues where it stopped. One
repository failing never fails the others: it is reported as failed with the reason, and the
exit code is 1. What each column and status means is in
keeping the index fresh.
Try it:
$ safran search "kısmi iade" --limit 1
1 payments-api src/refund/policy.ts:1-12
other · RefundPolicy, APPROVAL_THRESHOLD · typescript · score 0.463 (dense 0.515)
1 │ import type { RefundRequest } from "./service";
2 │
3 │ /** Rules a refund must satisfy before the provider is called. */
4 │ export class RefundPolicy {
5 │ assertRefundable(request: RefundRequest): void {
6 │ if (request.amount <= 0) throw new Error("Refund amount must be positive");
7 │ if (request.amount > request.orderTotal) throw new Error("A partial refund cannot exceed the order total");
8 │ }
… 4 more lines (--full, or: safran read payments-api src/refund/policy.ts --lines 1-12 --profile /work/acme/safran.yaml)
1 hit (limit 1; raise it with --limit)A Turkish question found English code without a glossary here because the default model is multilingual; non-English tickets explains what the glossary adds.
6. Pull the work history
$ safran links refresh
payments-api 1 pull request read
repo pull requests with a ticket detail
✔ payments-api 3 2
✔ ledger 0 0
3 pull requests read, 2 with a ticket, in 11 mssafran links refresh reads merged pull requests from the code hosts and stores which ticket
changed which files. The first run of a repository looks 12 months back and stores at most 500
new pull requests per repository; a repository with more is marked "history not fully fetched
yet" and the next run continues. It needs a code host that lists pull requests (azure-repos,
github, gitlab); a local host has none, and discovery then has no history to work with.
The "with a ticket" column is the one to look at. If it is near zero, either the project keys are missing from the profile (step 1), or the company does not put ticket keys in pull request titles, branches or descriptions, and discovery will have little to say about teams.
7. Discover
$ safran discover
…
Safran discovery — draft for review (statistics and heuristics, no language model)
2 repos (2 cloned), 3 merged PRs read, 2 used, 2 with a ticket (0% without), 2 ticket titles
sampled.
Ignored PRs: 1 by bots.
Legend: + added to the draft, · observation only; [high] [med ] [low ] = confidence.
Coverage (2)
· [high] pull requests ignored as noise
1 of 3 merged PRs were ignored: 1 by bot accounts, 0 merge/revert PRs, 0 mass changes, 0
naming many tickets at once, 0 repeats of the same change to another branch.
· [low ] ticket references in merged PRs
All 2 merged PRs read reference a ticket.
Repo groups (2)
+ [low ] ledger → other
Could not be classified (no language, name or manifest signal); placed in "other".
+ [low ] payments-api → backend
name contains "api".
Teams (1)
· [low ] repos with too little history
Not enough history for 1 repo: fewer than 3 ticket-linked PRs per project (payments-api).
They were not assigned.
Glossary candidates (1)
· [low ] glossary candidates
0 recurring terms in 2 sampled ticket titles: 0 already appear in code or changed paths,
0 have too few focused PRs to compare, 0 have no path word that stands out, 0 point at a
code word a commoner term already took; 0 proposed. Single words only; expect misses and
some wrong pairs.
Languages (1)
· [low ] languages.tickets
1 of 2 sampled ticket titles look Turkish, 1 English, 0 another language, 0 undecided.
Too few to say (10 classified titles needed). Language detection is a heuristic
(Turkish-only letters and small word lists for tr/en). `languages.tickets` was left as it
is.
Added to the draft: 0 project key(s), 2 grouped repo(s), 0 team(s), 0 repo(s) on existing teams, 0
glossary candidate(s), 0 convention(s).
Findings by confidence: 1 high, 0 medium, 6 low.
✔ Wrote the draft to safran.draft.yaml
→ It is a draft, not your profile. Review it (start with the items marked low),
then rename it over safran.yaml and run `safran profile check --profile /work/acme/safran.yaml`.safran discover refreshes the link store itself (pass --no-refresh to use it as it is),
reads the repositories, the tracker's projects and a sample of ticket titles, and writes
safran.draft.yaml next to the profile. It never touches safran.yaml unless you pass
--write --force. It is counting and heuristics, not a language model, and with three pull
requests it says so: on the toy setup every finding but one is low, no team was assigned and
no glossary term was proposed. A company with a year of ticket-linked pull requests gets more;
discovery explained covers what is inferred, how, and the thresholds.
8. Review the draft and merge it
The draft is your profile, unchanged, plus what was inferred. Its header says how to read it:
# DRAFT profile written by `safran discover`. Review it before use.
#
# What you wrote was kept as it was. Everything else was inferred from tracker and code-host
# data with counting and heuristics (no language model), so some of it is wrong.
# Added: 2 repo(s) in new groups.
#
# How to review:
# 1. Lines ending in `# discovered`, teams with `confidence:` / `source:` and glossary entries
# whose `note:` starts with "discovered" are guesses. `low` means: do not trust until checked.
# 2. `safran discover` printed 7 finding(s) with the numbers behind every guess; read the
# low-confidence ones first. Glossary candidates are co-occurrence, not translation.
# 3. Fix or delete what is wrong. Once a team is confirmed, remove its `confidence` and `source`.
# 4. Run `safran profile check`.
groups:
backend:
- payments-api # discovered (low)
other:
- ledger # discovered (low)What to look at, in this order:
- Repo groups. Every line marked
# discovered. Groups are what people and agents filter by (--group backend), so name them the way the company speaks, and empty theothergroup by hand: hereledgerbelongs inbackend. - Teams. A team with
confidence: lowis a guess from few ticket-PR links (itssourcesays how many). Ask someone on that team. Agents are told the confidence, so a wronglowis less harmful than a wrong team you confirmed without checking. - Glossary candidates. Entries whose
notestarts with "discovered" pair a ticket word with a code word because they occur together, not because one translates the other. Keep the pairs a developer of that code recognises, delete the rest, and add the ones you know (glossary). - Conventions. Sentences inferred from samples (branch naming, title language). Keep the ones that are real rules; add the rules nobody can infer.
languagesand added project keys, if the draft changed them.
When the draft says what you would say, remove confidence and source from what you
confirmed, rename it over the profile and validate:
mv safran.draft.yaml safran.yaml
safran profile checkFor acme, the reviewed profile ends up like this:
version: 1
company: acme
languages:
tickets: tr
code: en
trackers:
- id: jira
type: jira
url: https://acme.atlassian.net
email_env: JIRA_EMAIL
token_env: JIRA_TOKEN
projects: [PAY, MOB, WEB]
code:
hosts:
- id: azure
type: azure-repos
organization: acme
project: Platform
token_env: AZURE_DEVOPS_PAT
groups:
backend: [payments-api, ledger]
mobile: [acme-ios, acme-android]
frontend: [web-app, admin-panel]
teams:
- name: Payments
projects: [PAY]
repos: [payments-api, ledger]
- name: Mobile
projects: [MOB]
repos: [acme-ios, acme-android]
confidence: low
source: 9 ticket-PR links
- name: Web
projects: [WEB]
repos: [web-app, admin-panel]
glossary:
- term: Sepet
code: [basket, cart]
- term: İade
code: [refund, chargeback]
conventions:
- Task titles are written in English.
- Branch names follow feature/<TICKET-KEY>-short-description.
embeddings:
type: ollama
model: bge-m3The Mobile team keeps confidence: low on purpose: nobody has confirmed it yet, and the
profile says so.
What needs a new sync after the merge
| You changed | What to run | Why |
|---|---|---|
code.groups, teams, glossary, conventions | Nothing | They are read from the profile at query time. Group filters are resolved from the profile, not from the index. |
include / exclude on a code host, or added a host | safran sync | New repositories must be cloned and indexed; repositories no host lists any more are dropped from the index by a full sync. |
trackers[].projects | safran links refresh --since <date> | Ticket keys are extracted when a pull request is stored. An explicit --since re-reads its window with the new keys. From the SDK, safran.links.relink() does the same without a network call. |
embeddings | safran sync | Vectors of two models cannot be compared; see changing the embedder. |
A running MCP server read the profile when it started: restart it (or the Claude Code session that owns it) after you change the profile.
9. Connect the agents
Two ways, both described in full in the Claude Code section:
# skills + MCP server, from the Safran checkout
claude --plugin-dir ./plugin
# or only the MCP server
claude mcp add --transport stdio safran -- /opt/safran/bin/safran mcp --profile /work/acme/safran.yaml/opt/safran stands for wherever the Safran checkout is. Register the server through
bin/safran with an absolute --profile, never as a bare bun run started inside a project:
see the plugin, the MCP server
and the security model. Then ask the agent for a ticket it should
know, for example with the technical-analysis skill on PAY-1423, and check that it calls
get_company_profile first and cites files that exist.
10. Evaluate
Before anyone relies on the answers, measure code search on the company's own history. The golden set is built from the link store: each item is a ticket title (the question) and the files its pull requests changed (the known answer).
$ safran eval golden
reading ticket titles 1/2
reading ticket titles 2/2
pull requests 3
items kept 2
dropped no ticket 1
ticket titles 2 read
languages tr 2
✔ Wrote 2 items to data/eval/golden.json
→ Measure with `safran eval retrieval --profile /work/acme/safran.yaml`.
$ safran eval retrieval
running queries 1/2 config default
running queries 2/2 config default
2 items from data/eval/golden.json · index ollama:bge-m3, 5 chunks · 51 ms
Retrieval evaluation: 2 golden items, 1 configuration, k = 10
config slice n err hit@1 hit@5 hit@10 recall@10 MRR nDCG@10 p50 ms p95 ms
------- ------- - --- ----- ----- ------ --------- ----- ------- ------ ------
default overall 2 0 1.000 1.000 1.000 1.000 1.000 0.960 9.6 18
n = queries scored; err = failed searches, excluded from the means.Keep the first result. From then on, run safran eval retrieval before and after any change
that touches retrieval (the glossary, the embedder, a Safran upgrade); a regression blocks the
change. Metrics, comparisons and the replay evaluation are in
evaluation explained.
11. Keep it fresh
The index answers from the last sync, and the link store from the last refresh. Schedule both
(safran sync and safran links refresh) as described in
keeping the index fresh, and run safran discover again when teams
or repositories change: it keeps what you wrote and only proposes additions.
Checklist
safran.yamlholds the tracker (with itsprojects), the code host and the embedder; no secret is in it..envnext to the profile holds the tokens and is not committed anywhere.safran profile check --onlineshows a✔for every connector.safran doctorends without failures.safran syncreports every repositoryok;safran searchfinds a file you know.safran links refreshshows a believable share of pull requests "with a ticket".- Every
# discoveredline, everyconfidence: lowteam and every discovered glossary entry in the draft was confirmed, fixed or deleted by a person. - The merged profile passes
safran profile check. - An agent connected through the plugin or the MCP server answers a question about a known ticket with real file paths.
- A first
safran eval retrievalresult is saved as the baseline. safran syncandsafran links refreshare scheduled.
Common mistakes
- Running
safran discoveron a seed profile withoutprojects. No ticket key is recognised, so no team can be mapped. Add the keys, thensafran links refresh --since <date>. - Expecting discovery to work over
localhosts. A local folder has no merged pull requests. Search, grep and reading files work; history, discovery of teams and the golden set do not. - Copying the draft over the profile unread. Everything inferred is marked so that a person
reads it.
--write --forceexists for scripted setups, not to skip the review. - Committing
safran.yaml,.envordata/. The profile names internal systems,.envholds tokens anddata/holds source code and ticket titles. They are git-ignored in the Safran checkout for that reason.
When a step fails, start with safran doctor, then
troubleshooting.