Skip to content
safran

Type to search. Enter opens the first result.

    CLI overview

    The safran command is a thin shell over the same factory the SDK exposes: it reads one profile, builds the connectors and prints what they return. This page covers everything the commands share: how to start the CLI, the global options, where the profile and the data directory come from, the --json contract, exit codes and the argument syntax. The commands themselves are on five pages: set up, daily use, agent jobs, maintain and measure.

    Running the CLI

    Safran runs from a checkout of its repository with Bun. There are two ways to start it.

    From inside the checkout, use the package script. The working directory is the checkout, so the default profile is safran.yaml in the checkout and relative paths resolve against it:

    cd /work/safran
    bun run safran status

    From any other directory, use the launcher bin/safran. It is a POSIX sh script that finds the checkout it lives in (through symlinks), so you can link it onto your PATH once and type safran everywhere:

    ln -s /work/safran/bin/safran /usr/local/bin/safran
    cd /work/acme
    safran status

    The launcher exists for a security reason, not for convenience. Bun reads .env and bunfig.toml from its working directory before any Safran code runs. Started inside a project, a .env planted there could set a proxy that tracker requests (with their tokens) pass through, and a planted bunfig.toml could preload code. bin/safran therefore starts Bun with its working directory set to the Safran checkout and hands the directory you are really in to the CLI in SAFRAN_INVOKE_DIR. Relative paths on the command line and the default ./safran.yaml resolve against that directory, so the command behaves as if it ran where you typed it.

    The examples on the CLI pages were captured in /work/acme, through the launcher, with the profile named by SAFRAN_PROFILE=safran.yaml. That is why commands the CLI prints back (→ safran sync --profile safran.yaml) carry the profile: a printed command is meant to work when pasted.

    The overview

    Without a command, safran prints the command list and the global options:

    $ safran
    safran — company context for coding agents, from one profile file
    
    Usage  safran <command> [options]
    
    Set up
      init             Write a starter profile (interactive, or from flags with --yes)
      profile check    Validate the profile and build every connector
      profile set      Change values of the profile through the validator
      profile unset    Remove values or list entries from the profile
      profile add      Add a team, a glossary term, a convention or a repo group to the profile
      doctor           Check the environment: Bun, git, profile, tokens, embedder, index, writes
      plugins          List plugins by kind, and the tools of the profile's tool packs
      discover         Draft groups, teams, glossary and conventions from merged pull requests
      setup claude     Print (or with --run, run) the command that registers Safran in Claude Code
    
    Daily use
      search           Search the indexed code by meaning and by words
      grep             Find an exact string or a regular expression in the indexed repos
      read             Print a file (or a line range) from an indexed repo
      ticket           Show one ticket
      tickets          Search tickets by text
      home             My work: assigned, waiting on my review, blocked, recently changed
      me               Alias of `safran home`
      work             The ticket table: filter, sort and group work without writing a query
      boards           List the boards of the trackers, pinned ones first
      board            One board as columns: counts, WIP limits and cards
      iterations       List the iterations (sprints) of a board
      iteration        How one iteration is going: progress, load, blocked, stale, scope, tickets
      standup          What changed since the last working day, per person
      teams            The profile's teams with their open work, or one team in detail
      epics            Open epics, or one epic with its children and their progress
      pulls find       Find the pull request for a URL, a ticket or a branch
      pulls list       List pull requests as they are now, across the code hosts
      pulls show       Show one pull request; on request its files, review threads and diff
      links show       Show which pull requests changed what, by ticket, repo or file
      owns             Which team owns a repo or a tracker project
      repos            List the repositories the code hosts provide
      status           One screen: profile, connectors, index, link store, writes
      dashboard        Open the local dashboard: status, code search, tickets, history, evaluation
    
    Agent jobs
      harness project  Add a repository as a harness project: its setup and gates, read from its files
      harness add      Queue jobs for the agent: ticket keys, or a sentence saying what to do
      harness run      Work the queue: an agent per job, checked, reviewed, left as a branch
      harness list     The jobs and where each one is
      harness waiting  The jobs that wait for you, and what each one asks
      harness show     One job: the request, the agent's report, the checks and the review
      harness diff     What a job changed, against the commit it started from
      harness approve  Accept a job that waits for you
      harness back     Send a job back to the agent with a note saying what to change
      harness retry    Queue a failed or cancelled job again
      harness cancel   Stop a job and remove its worktree
      harness pause    Stop new jobs from starting (running ones finish)
      harness resume   Let the queue start jobs again, after a pause or a usage limit
      harness doctor   Check that jobs can run: the agent, each project's repository, the gates
    
    Maintain
      sync             Clone or fetch the repositories and index what changed
      links refresh    Pull merged pull requests into the local ticket ↔ code store
      links status     Size and age of the ticket ↔ code store
      mcp              Serve the profile to coding agents over MCP (stdio, or --http)
      writes status    Whether agents may write through Safran, which kinds, and why not
      writes log       The audit log of previewed, committed and failed writes
    
    Measure
      eval golden      Build a golden set (question → files) from merged pull requests
      eval retrieval   Measure code search against the golden set
      eval replay      Replay finished tickets with agent commands and score the files they touch
    
    Global options
      --profile <file>  Profile file (default: ./safran.yaml, or $SAFRAN_PROFILE)
      --data-dir <dir>  Where clones and the index live (default: data/ next to the profile)
      --allow-plugins   Trust the `plugins:` of a profile found in the current directory
      --allow-writes    Apply the `writes:` section of a profile found in the current directory
      --json            One JSON document on stdout; no colours, no progress
      --no-color        Plain output (NO_COLOR and pipes do the same)
      --verbose         Debug logs on stderr; stack traces for unexpected errors
      -h, --help        Show help
      -V, --version     Print the version
    
    Run `safran <command> --help` for the options of one command and an example.
    GroupCommandsPage
    Set upinit, profile check, profile set, profile unset, profile add, doctor, plugins, discover, setup claudeSet up
    Daily usesearch, grep, read, ticket, tickets, links show, owns, repos, statusDaily use
    Daily usepulls find, pulls list, pulls showPull requests
    Daily usedashboardMaintain, next to the other long-running server
    Agent jobsharness project, harness add, harness run, harness list, harness waiting, harness show, harness diff, harness approve, harness back, harness retry, harness cancel, harness pause, harness resume, harness doctorAgent jobs
    Maintainsync, links refresh, links status, mcpMaintain
    Maintainwrites status, writes logWrites
    Measureeval golden, eval retrieval, eval replayMeasure

    safran <command> --help (or safran help <command>) prints one command's usage, its own options, the global options and an example. A family name on its own lists its subcommands:

    $ safran links --help
    Usage  safran links <show | refresh | status> [options]
    
      links show     Show which pull requests changed what, by ticket, repo or file
      links refresh  Pull merged pull requests into the local ticket ↔ code store
      links status   Size and age of the ticket ↔ code store
    
    Run `safran links <subcommand> --help` for details.

    safran --version prints safran 0.2.0; with --json it prints {"version":"0.2.0"}.

    Global options

    Every command accepts these.

    OptionValueDefaultMeaning
    --profile <file>path./safran.yaml, or $SAFRAN_PROFILEThe profile to work on. Naming it also means you trust its plugins: and apply its writes: section (see Plugin modules).
    --data-dir <dir>pathdata/ next to the profileWhere clones, the code index and safran.db (link store, write audit log, plugin store) live.
    --allow-pluginsnoneoffTrust the plugins: of a profile that was found in the current directory rather than named.
    --allow-writesnoneoffApply the writes: section of a profile that was found in the current directory rather than named. See writes and trust.
    --jsonnoneoffOne JSON document on stdout; no colours, no progress. See JSON mode.
    --no-colornoneoffPlain output. NO_COLOR and pipes do the same.
    --verbosenoneoffDebug and info logs on stderr; the stack trace of an unexpected error.
    -h, --helpnoneShow help for the command, or the overview.
    -V, --versionnonePrint the version. Only without a command.

    How the profile is found

    The profile path is the first of these that is set:

    1. --profile <file>.
    2. For safran profile check only: the file given as an argument (safran profile check other.yaml).
    3. The environment variable SAFRAN_PROFILE, when it is not empty.
    4. safran.yaml in the directory you ran the command in.

    A relative path resolves against the directory you ran the command in. A profile that does not exist is an error for every command that needs one:

    $ safran repos --profile nope.yaml
    ✘ Profile not found: /work/acme/nope.yaml
    → Create one with `safran init`, or copy safran.example.yaml to safran.yaml.

    Two commands work without a profile: safran init writes one, and safran plugins lists the built-in plugins when there is none.

    The data directory

    --data-dir <dir> (relative paths resolve like the profile's) sets where clones, the index and the link store live. Without it the data directory is data next to the profile file. Everything in it can be deleted and rebuilt with safran sync and safran links refresh, with one exception: harness/ holds the queue and the records of the job harness and is not a cache.

    The .env file next to the profile

    Before a command runs, the CLI reads the file .env in the profile's directory, if there is one, and adds its variables to the environment it hands to the connectors. This is where the tokens the profile names (token_env: JIRA_TOKEN) usually live; see secrets.

    • A variable that is already set in your shell, even to an empty string, is never overridden: the shell wins over the file.
    • Lines are KEY=value, optionally prefixed with export. # starts a comment. Single-quoted values are literal; double-quoted values understand \n, \t, \r, \" and \\; an unquoted value ends at #. Lines that are not assignments are skipped.
    • Values are never printed. Commands report names and whether they are set.
    .env
    JIRA_EMAIL=bot@acme.test
    JIRA_TOKEN='the token'
    AZURE_DEVOPS_PAT="the token"

    Plugin modules and trust

    A profile can list modules under plugins:, and loading a module runs its code. The CLI therefore distinguishes a profile you named (--profile, SAFRAN_PROFILE, or the argument of profile check) from one it merely found as ./safran.yaml. A found profile may not load plugin modules:

    $ safran status
    ✘ safran.yaml lists plugin modules (./plugins/acme-tracker.ts), and it was picked up from the current directory, not named by you
    → Plugin modules run as code on this machine. If you trust this profile, name it (--profile safran.yaml) or pass --allow-plugins; otherwise remove its `plugins:` entries.

    The exit code is 1 and the error code is FORBIDDEN. Say you trust the file in one of the two ways the hint names. Writing your own plugins is covered in the SDK guide.

    Writes and trust

    The same rule covers the profile's writes: section. A found profile may enable writes in its text, but the CLI does not apply that until you name the file or pass --allow-writes: a safran.yaml that merely happens to be in the directory does not get to post anywhere. Nothing fails; the section is ignored and every command that reports the state says why:

    $ safran writes status
    ✔ Writes are off: Safran only reads.
      Why: the profile enables writes, but it was picked up from the current directory, not named by you.
      → If you trust this profile, name it (--profile safran.yaml) or pass --allow-writes.
      The profile would permit: ticket.comment.

    --allow-writes grants nothing by itself: the profile still has to say writes.enabled: true and list the kinds. See write commands.

    JSON mode

    With --json, a command writes exactly one JSON document to stdout and nothing else: no colours, no progress lines, no interactive questions. Scripts can pipe it straight into a JSON parser.

    • Keys are snake_case. Library objects use camelCase (startLine); the CLI converts them (start_line). Objects that are keyed by user data pass through untouched: a ticket's fields (keyed by the tracker's own field names), files_skipped of a sync result (keyed by skip reason), and the profile and finding detail objects of safran discover.
    • Third-party text is not altered, but control and invisible format characters are written as \uXXXX escapes, so the document is inert when printed to a terminal and parses to the same value.
    • Warnings and debug logs still go to stderr; they are not part of the document.
    • The exit code is the same as in human mode.

    When a command fails, the document on stdout is an error object instead:

    {
      "error": {
        "code": "NOT_FOUND",
        "message": "Ticket PAY-9999 not found in jira",
        "hint": null
      }
    }
    FieldMeaning
    codeA Safran error code, or one of two the CLI adds: USAGE (the command line was wrong, exit 2) and INTERNAL (an unexpected error, exit 1).
    messageWhat went wrong. An interrupted command always says Interrupted.
    hintWhat to do next, or null.
    problemsOnly when the error carries a list, such as the individual problems of an invalid profile.

    A profile that fails validation shows all four fields:

    {
      "error": {
        "code": "PLUGIN_CONFIG_INVALID",
        "message": "The profile has 3 configuration problems:\n  - trackers.0.url: Invalid input: expected string, received undefined\n  - trackers.0.token_env: Invalid input: expected string, received undefined\n  - trackers.0: Unrecognized key: \"urll\"",
        "hint": "Fix these entries in the profile. `safran plugins` lists the available types and their fields.",
        "problems": [
          "trackers.0.url: Invalid input: expected string, received undefined",
          "trackers.0.token_env: Invalid input: expected string, received undefined",
          "trackers.0: Unrecognized key: \"urll\""
        ]
      }
    }

    --json is recognised anywhere on the command line (before a --), so even a mistyped command is reported as JSON. When you start the CLI with bun run safran, Bun echoes the script line ($ bun packages/cli/src/index.ts …) on stderr; stdout still holds only the document.

    Human output

    • Streams. A command's result goes to stdout. Errors, warnings, notes and progress go to stderr, so safran search … | less and safran sync 2> sync.log both behave.
    • Colour. Used only when the stream is a terminal, and turned off by --no-color, by --json, by a non-empty NO_COLOR and by TERM=dumb. Stdout and stderr decide separately. 24-bit colour is used when COLORTERM is truecolor or 24bit, basic ANSI colours otherwise. The glyphs carry the meaning, colour is secondary: ✔ ok, ! warning, ✘ failure.
    • Width. Tables fit the terminal and stop growing at 160 columns; when stdout is a pipe, 120 columns are assumed. On a narrow terminal the less important columns are dropped first.
    • Progress. On a terminal, long commands rewrite one line in place. Elsewhere they print a line only when a step advances, so a log gets a handful of lines per repository.
    • Third-party text is made printable. Ticket titles, file contents, author names, repo names and upstream error messages can contain terminal escape sequences. They are stripped before anything is coloured or printed; only the CLI's own colour codes reach the terminal.
    • Errors are one ✘ line with the message and, when there is one, a → line that says what to do next. --verbose adds the stack trace of the underlying cause.

    Exit codes

    CodeWhen
    0The command did what it was asked. Also when a reader closed the pipe early (safran search … | head).
    1The command failed: a Safran error (profile invalid, token missing, not found, upstream failure …), an unexpected error, or a command-specific failure: a failed check in safran doctor, a failed connector in safran profile check --online, a repository that failed in safran sync or safran links refresh, an unreadable store in safran links status.
    2The command line was wrong: unknown command or option, missing or malformed value, options that exclude each other. Nothing was done.
    130Interrupted by Ctrl-C or SIGTERM. The first signal asks the command to stop cleanly; sync and links refresh still print what they finished. A second signal exits at once.

    safran mcp and safran dashboard are the exception to the last row: stopping a server with Ctrl-C is its normal end and exits with 0.

    Environment variables

    These are the variables the CLI itself reads. Connector tokens are separate: the profile names them, and they are looked up in the environment plus the .env next to the profile.

    VariableEffect
    SAFRAN_PROFILEProfile file when --profile is not given. Counts as naming the profile, so its plugins: are trusted and its writes: section applies.
    SAFRAN_INVOKE_DIRSet by bin/safran to the directory you ran it in. When it holds an absolute path, relative paths and ./safran.yaml resolve against it. You do not set it yourself.
    NO_COLORAny non-empty value turns colour off.
    TERMdumb turns colour off.
    COLORTERMtruecolor or 24bit selects 24-bit colours.
    HOMEOnly for display: paths under it are shown with ~.
    PATHsafran doctor looks for git on it.

    safran mcp --http --token-env <NAME> additionally reads the variable you name.

    Argument syntax

    • Options can stand anywhere, before or after the command and its arguments.
    • Values: --name value and --name=value are the same. A boolean option takes no value (--json=1 is an error). A number must be a number (--limit abc is an error).
    • Short forms exist only for -h, -V and, in safran init, -y. They cannot be combined.
    • Repeatable options are marked with … in the help. For the filters (--repo, --group, --lang, --project, --status), repeating the option and a comma list mean the same: --repo payments-api --repo ledger or --repo payments-api,ledger. --set, --plugin and --allow-host are repeatable but take one value each time (a --set value may itself contain commas).
    • -- ends the options. Everything after it is an argument, which is how you search for text that starts with a dash: safran grep -- "--force".
    • A lone - and negative numbers are arguments, not options.
    • Multi-word queries need no quotes: safran search retry policy for webhooks searches for the four words. Quote when the shell would otherwise interpret a character.

    An unknown command or option is never guessed at. The CLI stops with exit code 2 and names the closest match:

    $ safran serch refund
    ✘ Unknown command "serch"
    → Did you mean `safran search`?
    
    $ safran search refund --limt 3
    ✘ Unknown option --limt
    → Did you mean --limit?

    The same goes for values with a fixed set of choices:

    $ safran search refund --mode fuzzy
    ✘ --mode must be one of auto, hybrid, dense, lexical; got "fuzzy"

    Common mistakes

    • Running from the wrong directory. bun run safran … looks for safran.yaml in the checkout. For a profile elsewhere pass --profile, set SAFRAN_PROFILE, or use the launcher from the profile's directory.
    • Expecting --json on stderr. Errors in JSON mode are documents on stdout, with a non-zero exit code. Check the exit code, then parse.
    • Parsing human output. Tables adapt to the terminal width and drop columns. Use --json in scripts.
    • A .env that seems ignored. A variable already present in the shell wins, even when it is empty. safran doctor shows which names are set.