Skip to content
safran

Type to search. Enter opens the first result.

    The job harness

    This guide takes you from a repository to an approved branch with the job harness (@safran/harness, the safran harness commands): how a repository becomes a project, what happens to a job layer by layer, what the profile section holds, what the agent is allowed to run, and where the harness stops. You give it ticket keys or a sentence; for each job it starts one agent session in a worktree of its own, checks the result itself, has a second session review it, and leaves you a local branch to approve.

    It is not an agent and it does not make an agent smarter. It is slower and costs more than sitting in a session yourself. What it buys is that you can hand over ten jobs and come back to ten branches whose "done" was decided by something other than the agent that did the work.

    From a repository to an approved branch

    The whole path, as commands. Each step is explained below with its output.

    safran harness project payments-api --tickets PAY   # write the project into the profile
    safran harness doctor --gates                       # do the gates pass on the base branch?
    safran harness add PAY-1423                         # one job, branch feature/pay-1423
    safran harness run                                  # works the queue until Ctrl-C
    safran harness waiting                              # what waits for you, and what each job asks
    safran harness show 1                               # the report, the checks, the review
    safran harness diff 1
    safran harness approve 1                            # or: safran harness back 1 "what to change"
    safran harness show 1 --pr                          # the pull request text; pushing is yours

    1. Make the repository a project

    A harness project is a repository plus the commands that prove a change works there. safran harness project reads the top of the repository and proposes them; it runs nothing.

    $ safran harness project payments-api --tickets PAY
    ✔ Added harness project payments-api  bun · repos/payments-api
      base          the repository's default branch
      setup         bun install
      gates         lint (bun run lint), test (bun run test)
      context       AGENTS.md
      tickets       PAY
      also allowed  Bash(bun run:*)  Bash(bun test:*)
    → Read the entry in safran.yaml, then check the gates on the base branch: `safran harness doctor --gates --profile safran.yaml`.

    The repository is named as safran repos names it and must be cloned (safran sync); --checkout <dir> points at a checkout of your own instead. What was written to the profile:

    harness:
      agent:
        allowed_tools:
          - Bash(bun run:*)
          - Bash(bun test:*)
      projects:
        - name: payments-api
          tickets:
            - PAY
          setup:
            - - bun
              - install
          gates:
            - name: lint
              command:
                - bun
                - run
                - lint
            - name: test
              command:
                - bun
                - run
                - test
          context:
            - AGENTS.md

    Read it before the first job. The proposal comes from file names and script names (package.json and its lock file, a .sln, go.mod, Cargo.toml, pyproject.toml); it cannot know that your real test command is another one. --dry-run shows the same output and writes nothing.

    2. Check the gates on the base branch

    A gate that fails on the base branch fails every job, whatever the job did. Find out before the first one:

    $ safran harness doctor --gates
    ✔ agent (claude-code)  0.0.0 (fake agent)
    ✔ permissions  acceptEdits: the agent may run its project's gates, git's views of the worktree, and what `allowed_tools` names (2 patterns)
    ✔ project payments-api  branches from main (9f1ee3a19f), 2 gates, reviewed
    
    On the base of payments-api  main (9f1ee3a19f)
      ✔ setup  bun install
      ✔ lint  passed · 15 ms
      ✔ test  passed · 13 ms

    --gates runs setup and every gate in a throwaway worktree of the base and removes it afterwards. Without the flag, safran harness doctor checks only that the agent program answers, which permission mode is in force, and that each project's repository and base can be found. When a gate fails here, the end of its output is printed under it: fix the gate, remove it, or list the tests that already fail under known_failures (with fail_pattern).

    3. Queue a job

    $ safran harness add PAY-1423
    ✔ job 1 queued  payments-api · feature/pay-1423  PAY-1423
    → Work the queue with `safran harness run --profile safran.yaml`.

    One job is one branch and one worktree. A line of only ticket keys is a job (two keys on a line are one job for both tickets); anything else is one job whose first line is its title:

    safran harness add PAY-1423 PAY-1500                 # one job for both tickets
    safran harness add "Refuse refunds that are not whole kuruş" --kind fix
    safran harness add -f jobs.txt --dry-run             # several jobs from a file, previewed

    The branch follows from the request, so the same request twice is the same job and nothing is doubled:

    $ safran harness add PAY-1423
    ! already job 1 (queued)  payments-api · feature/pay-1423  PAY-1423

    Nothing has run yet, and nothing has been read from the tracker: the job is known by its key until the runner reads the ticket.

    4. Work the queue

    safran harness run stays in the foreground and works the queue until Ctrl-C; --once stops when the queue is empty. Its lines go to stderr:

    $ safran harness run --once
    harness: 1 job queued
    job 1  Attempt 1 of 1 started
    job 1  Setting up: bun install
    job 1  Work session started
    job 1  Sent back by the rules check: [focused-test] src/refund/policy.test.ts:16: A test is focused, so the rest of its file no longer runs. Remove the focus.
    job 1  Fix round session started
    job 1  Review session started
    job 1  Ready for you on branch feature/pay-1423 (b4ef3a2aee)

    (The lines a session prints about its own tool calls are left out: here they came from the stand-in.)

    What happened: the first session reported the job as done, both gates passed, and then the diff audit found a focused test (test.only) in the change. The finding went back into the same session, the fix round removed the focus, every check ran again, the review passed, and the harness committed the change on the job's branch. The agent never committed anything: the guard refuses git commit in a session.

    5. Read what waits for you

    $ safran harness waiting
    job 1  waiting for you  PAY-1423: Kısmi iade işlemi İstanbul şubesinde başarısız oluyor  feature/pay-1423
      ! Not verified by the agent: The three payments seen in production can now be refunded (no access to production data)
      ! Decision made for you: Every branch code is folded by Turkish rules, not only İstanbul. the ticket names one branch; treating it differently from the others would be a special case
      · Assumed: Branch codes hold only Turkish and ASCII letters
      · The review notes: A branch whose code has a capital I without a dot would stop matching its lower-case spelling.
    
    → safran harness show --profile safran.yaml <job> · safran harness approve --profile safran.yaml <job> · safran harness back --profile safran.yaml <job> "<what to change>"

    Only what nobody independent confirmed is listed. The two checks the review confirmed are not questions. What is left for you:

    MarkLineMeaning
    !Not verified by the agent: …The agent could not verify the requirement, and the review did not confirm it either.
    !The review could not verify: …The agent says it holds; the review could not try it.
    !No review ran: … / The review gave no verdict: …Nobody independent looked at this check.
    !Differs from the request, by the agent's decision: …The review found the change differs from what was asked, deliberately.
    !Decision made for you: …A choice the request left open and the agent made.
    ·Assumed: …, The review notes: …, The diff audit warns: …Worth knowing; nothing to decide.

    A job in which the review confirmed every check says so in one line: Every check was confirmed by the review. Nothing to decide but approve. A failed job is listed here too, with its reason.

    safran harness show prints the whole job, and safran harness diff the change against the commit the job started from:

    $ safran harness show 1
    job 1  waiting for you  PAY-1423: Kısmi iade işlemi İstanbul şubesinde başarısız oluyor
      project   payments-api
      branch    feature/pay-1423  from main
      attempts  1 of 1
      tickets   PAY-1423
      commit    b4ef3a2aee6d
      worktree  data/harness/worktrees/payments-api/job-1
    
    The agent reports
      Branch codes are now compared with Turkish case folding, so "İSTANBUL" from the terminal and "istanbul" from the back office are the same branch and the partial refund goes through.
      ✔ A partial refund of a payment taken at the İstanbul branch succeeds  agent: met · review: ok
      ✔ Other branches behave as before  agent: met · review: ok
      ! The three payments seen in production can now be refunded  agent: unverified · review: unverifiable
    
    Gates
      ✔ lint  passed · 12 ms
      ✔ test  passed · 11 ms
    
    The review says
      Ran the tests and tried both spellings and a mixed one; the comparison holds. Production payments could not be looked at from here.
    
    For you
      ! Not verified by the agent: The three payments seen in production can now be refunded (no access to production data)
      ! Decision made for you: Every branch code is folded by Turkish rules, not only İstanbul. the ticket names one branch; treating it differently from the others would be a special case
      · Assumed: Branch codes hold only Turkish and ASCII letters
      · The review notes: A branch whose code has a capital I without a dot would stop matching its lower-case spelling.
    
    Sessions: work ok → fix ok → review ok
    
    → safran harness diff 1 --profile safran.yaml · safran harness approve 1 --profile safran.yaml · safran harness back 1 --profile safran.yaml "<what to change>"

    6. Approve, or send it back

    $ safran harness approve 1
    ✔ Job 1 is done. Its work is on branch feature/pay-1423; nothing was pushed.

    The job is done, its worktree is removed and its branch stays. In the repository there is now one commit on feature/pay-1423 (Compare branch codes with Turkish case folding); the checkout itself is still on main and was never edited. safran harness show 1 now ends with what is yours to do:

    → Yours to do: git push -u origin feature/pay-1423, then open the pull request (safran harness show 1 --pr --profile safran.yaml prints its text).

    safran harness show 1 --pr prints a title, a blank line and a Markdown body made from the agent's report: the summary, the checks as a task list (unverified ones unticked), the decisions, the assumptions and the review's summary.

    When the work is not what you wanted, send it back with a note instead:

    $ safran harness back 2 "Also refuse NaN, with a test"
    ✔ Job 2 is queued again with your note.

    The next safran harness run starts a fresh session in the same worktree, with your note and the earlier session's hand-off. Every check and the review run again on the whole job, not on the fix. Sending a job back grants it one more attempt.

    What happens to a job

    1. Intake. The branch follows from the request: harness.branch_template (default feature/{keys}) for ticket jobs, harness/<title>-<hash> for a sentence. A job is known by its project and branch. A branch that already exists in the repository and was not made by the job is never taken over and never renamed around: the job fails and says so.
    2. Worktree. Cut from the project's base with --no-track, under <data dir>/harness/worktrees/. The checkout it is cut from is never edited. setup commands run once, in the new worktree.
    3. Work session. The agent gets the request, every ticket with its comments (wrapped as untrusted text), the project's context files and notes, and an evidence directory outside the worktree. It ends with a structured result: a list of checks (each requirement, how it was verified, met / not_met / unverified, the evidence files), the decisions it made where the request was open, its assumptions and a hand-off.
    4. Checks, whatever the agent claims. In this order, stopping at the first that refuses:
      • output: the result has the expected shape;
      • changes: something changed (a research job may change nothing);
      • gates: the project's commands, run by the harness. A gate whose every failing test is listed under known_failures passes; the gates after a failed one are reported as not run, never as passed;
      • rules: the diff audit. Built in and blocking: a focused test, a skipped test, a silenced type check (@ts-ignore, @ts-nocheck), a deleted test file. Built in as warnings: a lint rule switched off, a cast to any. Plus the project's own rules. warn rules do not block and are shown to the reviewer and to you;
      • evidence: no check is not_met, every met check says how it was verified, every cited file exists in the evidence directory and is not empty, and no two checks cite byte-identical files.
    5. Independent review. A fresh session with no edit tools. It derives the requirements from the raw sources itself, tries each check, tries to break it, then reads the diff. It gives a verdict per check (ok, differs, wrong, unverifiable), requirements the worker missed, and findings. The harness ignores the review's overall verdict and blocks on what is concrete: a wrong check, a missing requirement, a blocking finding. A review that hands back nothing usable is tried once more and then fails the job; silence is never approval. review: false on a project skips this layer.
    6. Fix rounds. Whatever a layer refused goes back into the worker's own session, at most max_fix_rounds times (default 2). The same failure twice ends the attempt early. After a fix, everything runs again and the review looks at the whole job.
    7. Delivery. One commit on the job's branch, made by the harness (or, with deliver: staged, the changes left staged in the worktree). It is exactly the change the checks saw: what a gate or the review leaves in the worktree afterwards stays out, and a staged change that was altered during the review is not delivered at all. The job now waits for you.
    8. You. safran harness waiting, then approve or back.

    Nothing in this path pushes, opens a pull request or posts to a tracker. safran harness show <job> --pr prints a text; the push command is printed for you to run.

    What does not cost an attempt

    A job has max_attempts fresh sessions (default 1) before it is handed to you as failed. Three kinds of failure are kept apart, and only one of them is the agent's:

    What happenedWhat the harness does
    The account's usage limit was reachedThe job goes back to the queue with its attempt; the queue waits until the limit lifts. A usage warning is not a limit.
    Something every job would trip over: a gate that cannot be started, a failing setup, a tracker that cannot be read, an agent session that started without the guardThe queue pauses with the reason and the job keeps its attempt. Fix it, then safran harness resume.
    The review produced no verdict twice, the job's branch already existed, or the harness itself failedThe job fails; the attempt is not counted.
    safran harness run was stopped, or diedJobs in flight go back to the queue. Their worktrees may hold half-finished changes, and the next session is told so.

    An agent error, a timeout, a job the agent reports as impossible, and fix rounds that run out do cost the attempt.

    A pause looks like this. The gate below names a program that is not installed:

    $ safran harness run --once
    harness: 1 job queued
    job 1  Attempt 1 of 1 started
    job 1  Work session started
    job 1  The queue is paused: The gate "lint" could not be started (acme-lint: Executable not found in $PATH: "acme-lint")
    ! The queue is paused: The gate "lint" could not be started (acme-lint: Executable not found in $PATH: "acme-lint")

    The job is queued again with attempts 0 of 1, safran harness list and safran harness doctor repeat the reason, and safran harness run --once exits with 1 because the queue stopped with a job still in it. After the fix, safran harness resume opens the queue.

    The profile section

    Everything company-specific is in the profile, under harness. A fuller example than the one safran harness project writes:

    version: 1
    company: acme
    harness:
      agent:
        command: [claude]
        permission_mode: acceptEdits
        allowed_tools: ["Bash(bun run:*)", "Bash(bun test:*)"]
        max_budget_usd: 25
      concurrency: 1
      max_fix_rounds: 2
      projects:
        - name: payments-api
          base: origin/main
          tickets: [PAY]
          setup: [[bun, install]]
          gates:
            - { name: lint, command: [bun, run, lint] }
            - { name: test, command: [bun, run, test], fail_pattern: "^\\(fail\\) (.+)$", known_failures: ["refund > flaky bank"] }
          context: [AGENTS.md]
          rules:
            - { name: no-console, level: warn, message: "Use the logger, not console.", added: "console\\.log" }
    KeyMeaning
    agent.commandThe agent program, as a list of words. One driver is built in: Claude Code, headless.
    agent.model, agent.review_model, agent.effortPassed to the agent. The review model defaults to model.
    agent.permission_mode, agent.allowed_toolsSee Permissions.
    agent.mcp_configAn MCP configuration file for the agent. Without it the agent gets no MCP server, whatever is configured on the machine.
    agent.max_budget_usd, agent.timeout_minutesPer session. The timeout defaults to 60 minutes; there is no default budget.
    agent.strip_envEnvironment variables removed before anything starts, on top of every *_env the profile names.
    concurrency, max_attempts, max_fix_rounds, branch_templateThe queue: jobs at the same time (1), fresh sessions per job (1), fix rounds per session (2), the branch of a ticket job (feature/{keys}).
    projects[].name, repo, checkoutThe repository as safran repos names it (repo defaults to name), or an absolute path of a checkout to branch from.
    projects[].baseThe ref jobs branch from. Default: the remote's copy of the default branch, then the default branch.
    projects[].ticketsTracker project keys whose tickets belong here, so safran harness add needs no --project.
    projects[].setup, gatesCommands as lists of words. No shell reads them.
    projects[].context, notesFiles the agent is told to read first, and free text for its instructions.
    projects[].rules, builtin_rulesThe diff audit: added matches added lines, new_file matches the path of new files, files limits by glob.
    projects[].secret_files, projects[].commit_excludeFiles the agent may not read or write (on top of .env files); files never staged.
    projects[].review, deliver, max_parallel, projects[].commit_messagePer project: skip the review, deliver a commit or a staged change, jobs of this project at the same time, the commit message template.

    Every key with its type, default and limits is in the profile reference.

    setup, gates and the agent command run as programs on this machine. A profile that was merely found in the current directory may list and queue jobs, but nothing it lists is executed until you name it (--profile, SAFRAN_PROFILE) or pass --allow-plugins. It is the same rule as for plugin modules:

    $ safran harness run --once
    harness: 1 job queued
    ✘ This profile was picked up from the current directory, not named by you, so the harness will not run the commands it lists
    → The agent command, `setup` and `gates` run as programs on this machine. If you trust the profile, name it with --profile or pass --allow-plugins.

    Permissions

    Nobody is there to answer a permission prompt, so what the agent may run is decided before it starts.

    permission_modeWhat a session may do
    acceptEdits (default)Edit files, and run only the commands that are allowed by name. Anything else is denied.
    default, planPassed to the agent CLI as they are. As under acceptEdits, only what is allowed by name runs, because a prompt is never answered.
    bypassPermissionsRun whatever the guard does not refuse.

    Under every mode except bypassPermissions, a session is allowed three things:

    • Its project's gates, exactly as written in the profile (bun run lint, bun run test). An agent that cannot run the checks it will be held to can only guess, and a review that cannot run them can only read.
    • Git's views of the worktree and staging: git status, git diff, git log, git show, git add. The guard refuses the rest of git that matters.
    • What agent.allowed_tools names, in the agent's own pattern syntax: Bash(bun test:*). safran harness project adds the test and script runners of the stack it detected, so bun test path/to/one.test.ts works and not only the gate as written.

    The session is told this list in its prompt. safran harness doctor prints which mode is in force and how many patterns the profile adds.

    bypassPermissions is what makes an agent able to do anything a job could need. Choose it only on a machine and with tickets you would trust with a shell: the only thing between the agent and that shell is then the guard, and the guard is a text filter.

    A narrow list has a price for the review. A reviewer that wants to try something outside the list is refused and reads the code instead. The harness counts the refused tool calls of a review and tells the person approving; allow the commands a reviewer needs, or its verdicts are a reading.

    What the guard is and is not

    Every harness session loads one hook that sees each tool call before it runs. It refuses:

    • git push, git commit, and the git commands that rewrite a branch or a worktree;
    • sudo, publishing a package, and gh pr create;
    • reading or writing .env files and the project's secret_files, through any tool;
    • for file tools, writing anywhere but the job's worktree and its evidence directory. A reviewer's file tools may write only to the evidence directory.

    It reads a command line the way a shell splits it, so grep "git push" docs and echo "a > b" pass while git -C . push and echo x > /etc/hosts do not. The hook fails closed: a hook that cannot run refuses the call, and a session that starts without it is discarded and pauses the queue.

    Two more things are done for you whatever the mode:

    • No connector token reaches the agent. Every environment variable the profile names as a secret (*_env) is removed from the environment of the agent, of setup and of the gates. The agent reads third-party text; a token it cannot see cannot be talked out of it.
    • Ticket text is data. Descriptions and comments are wrapped as untrusted text with a random tag before they enter a prompt, as everywhere else in Safran. So are gate output and review findings when they go back into a session.

    What is stored

    <data dir>/harness/
      harness.db               jobs, sessions, events and the queue's switches (SQLite)
      runner.lock              the process id of the running `safran harness run`
      worktrees/<project>/job-<n>/
      jobs/<n>/evidence/       what the agent and the reviewer put there
      jobs/<n>/logs/           the raw event stream of every session
      jobs/<n>/gates.log, setup.log

    Unlike the rest of the data directory, this is not a cache. Deleting it deletes the queue and the record of what each job was told and did. Branches live in the repository and survive it.

    Only one safran harness run works a queue. Other commands (add, approve, cancel) may run next to it, and a job cancelled from another terminal is stopped at the runner's next tick.

    Which checks earn their cost

    Every time a layer sends a job back to its agent, the layer is recorded. safran harness doctor prints the count per layer over all jobs:

    $ safran harness doctor
    ✔ agent (claude-code)  0.0.0 (fake agent)
    ✔ permissions  acceptEdits: the agent may run its project's gates, git's views of the worktree, and what `allowed_tools` names (2 patterns)
    ✔ project payments-api  branches from main (9f1ee3a19f), 2 gates, reviewed
    
    Sent back by
      rules  1 time

    A layer that never sends anything back is costing time for nothing, or is not looking. A review that sends back half of the jobs is doing its work. Read the ledger before adding a check, and before removing one.

    Honest limits

    • Exercised live once. On 1 December 2026 one job ran end to end with Claude Code 2.1 on a generated repository, without a tracker (acceptEdits, four allowed tool patterns): work session, gate, review, commit on the branch, approval; it cost $0.27. A second live session confirmed that the guard plugin loads and refuses a write to .env. Everything else is tested with a scripted program in place of the agent. No fix round, no usage limit, no tracker-backed job and no company repository has been exercised live.
    • A review under acceptEdits can run only what is allowed. In the live run the review's own probes (bun -e …) were refused and it said it had read the code instead.
    • The review is a second run of a model, not a calibrated judge. It is a net, not a proof; the gates are the proof.
    • The evidence check is mechanical. It knows that a cited file exists and is not a copy of another; it does not know what the file shows. The review is asked to look.
    • One driver exists, for Claude Code.
    • The loop's position inside a job is not stored. A runner that dies loses the fix round it was in, and the job starts a fresh session on the worktree as it was left.
    • A runner that is killed outright can leave its agent process running. Graceful stops (Ctrl-C) end the whole process group.
    • There is no dashboard screen and no MCP tool for the harness yet. The CLI and createHarness() of @safran/harness are the surfaces.

    Where to go next

    • CLI: agent jobs: every safran harness command with its flags, output, --json shape and exit codes.
    • Profile reference: every key of the harness section.
    • Security: how third-party text is wrapped, and where secrets live.