niyam
niyam (नियम, rule) was named process-rules until 0.6.3. Its repository moved
from athya-hq/process-rules to veda-hq/niyam, and GitHub forwards the old
address. Since P-57 no release reads or writes the old names: see
Renamed from process-rules.
Work rules for a repository that tracks its work in GitHub Issues and a GitHub
Project, with an owner account that approves and an agent account that builds.
Any repository can adopt it. No server, database or dashboard: a CLI, git
hooks and a shared GitHub Actions workflow.
Status
Early. The CLI runs machine, doctor, session-start, guard, onboard, propose, upgrade and owner-step. What comes next, and in what
order: the Slice issues under
niyam roadmap v1,
on the Project process-rules work (its title from before the rename);
docs/roadmap.md keeps version v1 as approved. Decisions:
docs/decisions.md. Traps learned while building it:
docs/lessons.md.
GitHub means github.com: it is the only supported host. GitHub Enterprise
Server and GitHub Enterprise Cloud with data residency (GHE.com) are not
supported yet; every GitHub address in the CLI comes from one host constant,
so a host setting can be added later.
Claude Code is one agent runner among others. Its SessionStart hook gives a
session the agent identity and the GitHub lock; an agent run from any other
tool on a Mac (Codex, Cursor, Copilot's agent, Aider, a plain script) gets
the same through niyam env (see Agents outside Claude Code below).
Agent identity on a Mac
macOS is the supported platform: the agent's token lives in the macOS
keychain. On any other platform machine and doctor refuse, and
session-start keeps GitHub locked out of the session; Claude cloud sessions
need no keychain and work as before, and doctor runs its cloud checks there
(see Claude cloud sessions below). The token is read and stored through
one token-store interface (src/token-store.ts), so a Linux or Windows store
can be added there when an adopter needs one.
The adopting repo names its accounts in .github/niyam.json:
{ "owner": "example-owner", "agent": "ExampleBot" }
Each of "owner" and "agent" is a login or a non-empty list of logins,
such as "owner": ["example-owner", "second-owner"]; no account may be both.
Every check accepts anyone in a list: an approval, a 👍 or a Decision:
comment from any owner counts, and proposals, commits, pushes and pull
requests from any agent count as agent work. A Mac's agent sessions work as
one agent: the only one listed, or else the one listed that machine set up
on that Mac; with none of them set up there, or more than one, session-start
keeps GitHub locked out rather than guess. Messages that send someone to fix
a setup name the first owner. onboard writes the one-login form, and on a
repo whose settings list several it works as the owner named, else the
one the run's browser sign-in is, which must be listed, and the agent named,
else the one set up on the Mac; it leaves the lists as they are.
niyam machine ExampleBot, run once per Mac and agent account (inside
an adopting repo the name can be left out), needs no client repo. It makes the
agent's signing key (~/.ssh/<agent, lowercased>_signing), opens GitHub's
classic-token page with the scopes filled in (repo, workflow, read:org,
project, write:ssh_signing_key) and reads the token through a hidden prompt
into the keychain (service niyam), refusing a fine-grained token,
missing scopes or no expiry. It then registers the key as the agent's signing key, writes
~/.config/niyam/<agent, lowercased>/session.sh, and writes the
launcher ~/.config/niyam/bin/niyam, which the Claude Code
hooks and the pre-push git hook run. Releases before P-55 wrote both under
~/.config/process-rules/, which nothing reads since P-57: machine removes
that folder, whole, once it has written the new one, and deletes the keychain
entry under the service process-rules once the niyam one holds the same
token (see Renamed from process-rules). The launcher names the node that ran machine by its real path (not a version
manager's per-shell one, which the Claude app's hooks may not have), so the
hooks need no node on their PATH. Why a classic token: docs/decisions.md.
machine first works out what it would change, changing nothing, and shows
one plan, in the same layout as onboard, listing only what changes. Then it
asks once:
◆ niyam machine AGENT
│
◇ This Mac
│ signing key ~/.ssh/agent_signing (new)
│ token classic, in the keychain (new)
│ session file new
│ launcher ~/.config/niyam/bin/niyam
│
◇ GitHub — as AGENT
│ signing key register
│
◆ Go ahead? ● Yes ○ No
No changes nothing. --yes goes ahead without asking, and --dry-run shows
the plan and stops. When nothing would change, it asks nothing and says
◇ This Mac is set up for AGENT, with or without a terminal. Otherwise,
with no terminal it refuses in one line unless given --yes or --dry-run.
A stored token GitHub refuses, or one that ends within 14 days, shows in the
plan as replaced. After the yes, each step shows as one ◇ line, or ■
with why when it fails. The token's step opens GitHub's page, says in a few
short lines what to do there, and asks for the paste, hidden. A failed key,
token or key registration stops the run there, and nothing after it changes.
A failed lockout step stops nothing and goes under "Worth fixing". A run
that finishes ends with that group of ▲ lines, each with its one-line fix,
and └ AGENT is ready on this Mac. The SessionStart hook sources the
session file, so nothing is left to do by hand.
The trade-off, for adopters: the agent account holds one classic token, and
its repo scope reaches every repository the agent account can access, not
only the adopting one. Invite a dedicated agent account to the repositories
it works in and nothing else; the expiry bounds the rest. It is classic for
now because a fine-grained token waits on an organisation owner's approval
wherever the organisation requires it, reaches no repository where the agent
is only an outside collaborator, takes one token per organisation, and
cannot register the agent's signing key when an organisation owns it. An organisation or
enterprise that blocks classic tokens cannot adopt niyam yet:
onboard names the block and that an organisation owner can allow classic
tokens under Settings → Personal access tokens. A fine-grained token or a
GitHub App waits for adoption outside Athya.
A client's .claude/settings.json locks GitHub out of every session before
any hook runs: its env holds the lock's variables (a GH_TOKEN GitHub
refuses, no credential helper, GitHub's SSH remotes on HTTPS and every other
SSH remote refused), so a session whose hook never ran or failed reaches
GitHub as nobody, never as the owner. In a Claude cloud session the
SessionStart hook lifts it only once GitHub says the session is the agent
(see Claude cloud sessions below).
In Claude Code, the client's SessionStart hook runs niyam session-start. It appends a lock to CLAUDE_ENV_FILE: a token GitHub refuses,
no credential helper, nothing inherited that could bring one back (git -c
injection, GIT_CONFIG, askpass), GitHub's SSH remotes on HTTPS and every
other SSH remote refused. Then, when this Mac has the session file machine
wrote for the agent the repo's settings name, exactly as machine writes it,
it appends that file, which replaces the lock with the agent's identity. Any
other outcome leaves GitHub locked out and says why, so a session never falls
back to the owner's login. When the CLI is missing or fails, the hook still
tells the session to stop, with what the CLI printed.
The line that tells a local session it works as the agent also tells it to
turn Auto-fix on for each pull request it opens. The Claude desktop app's
Auto-fix wakes a session on CI failures, merge conflicts and review comments,
and the app turns it on for a new pull request by itself only while that
session is open on screen, so a session started in the background (as a
coordinator starts its slice sessions) opens its pull request with Auto-fix
off. So after gh pr create, when the app's ccd_pr tools are there and
get_status shows auto_fix off, the session turns it on with
set_monitor. The app checks that the session opened the pull request and
that its gh login wrote it, which holds for the agent's own pull requests.
In auto mode the classifier refuses those calls unless the repo's
.claude/settings.json allows them, so onboard adds mcp__ccd_pr__bind_pr,
mcp__ccd_pr__get_status and mcp__ccd_pr__set_monitor to its
permissions.allow, and doctor warns under "This repo" (▲) about each
one an onboarded repo's file lacks. They reach the app only, not GitHub.
Claude Code applies deny before allow, so where the file's
permissions.deny matches one of the tools (by its name, mcp__ccd_pr,
mcp__ccd_pr__* or another glob after mcp__ccd_pr__, mcp__* or *),
onboard adds no rule for it and says so in its plan, and doctor marks it
denied on purpose (✓). A group denied whole leaves nothing to fix; in a
group denied in part, doctor still warns (▲) about each other rule the
file lacks.
Before each Bash command, the client's PreToolUse hook runs niyam guard: a command running gh or a git command that reaches a remote (push,
fetch, pull, clone, ls-remote, submodule, and remote update, prune, show (not -n),
add -f/--fetch (unless a later --no-fetch) and set-head -a/--auto;
not remote get-url and the other local remote subcommands) is refused,
with the reason,
unless session-start gave this session the agent identity. Hooks cannot see
the variables session-start gives the session's shells, so session-start
records how it left each session in
~/.config/niyam/sessions/<session id>.json and the guard reads that.
A command not naming gh or git as a word goes ahead without starting the CLI;
when the CLI cannot run, every command naming either is refused.
The guard also reads each comment an agent session posts or edits through
gh: gh issue comment, gh pr comment, and gh api on a comments
endpoint or in a GraphQL comment mutation, its body inline, in a heredoc, in
$(cat file), or from --body-file, -F body=@file or --input. A
comment that asks the owner (it opens with Needs you: or Proposal:, past
any Markdown emphasis, or names an owner login, with or without @) must
link a published page (https://claude.ai/artifact/… or
https://claude.ai/code/artifact/…) and fit 500 characters; otherwise it is
refused, naming the rule and the fix: publish the page, then post the
question, the link and how to answer. In auto mode the classifier refuses
the publish as communication unless the repo's .claude/settings.json
allows it, so onboard adds mcp__claude-artifacts__publish_version,
mcp__claude-artifacts__publish_files and
mcp__claude-artifacts__edit_version to its permissions.allow (none
where mcp__claude-artifacts or mcp__claude-artifacts__* allows the whole
server), and doctor warns (▲) about each one an onboarded repo's file
lacks. A repo that publishes its pages another way may deny the artifacts
server on purpose. Where the file's permissions.deny matches one of the
three, as for the Auto-fix rules above, onboard adds no rule for it and
its plan says so, and doctor marks it denied on purpose (✓). A deny of
the built-in Artifact tool matches all three: the Claude CLI then never
adds the artifacts server to a session (artifact_tool_denied,
veda-hq/veda#677), so Artifact alone is enough. Only the bare name
counts, not Artifact(…) or ArtifactData. A new page is private to its owner; a republish to a page already
shared changes what its readers see, with no prompt. A body the guard cannot read in full
(a variable, a command substitution other than cat) is judged by what it
spells out; where that asks the owner, or the body opens with the unknown
part, it is refused with how to write it so the guard can read it; so is a comment with no body in the command, which gh would take from an editor, a prompt or the browser. Commands inside $(…), backquotes and sh -c are read too. propose
posts through GitHub's API, not through gh, so this check does not see
it; propose holds its own comments to the same rule before posting them.
The session file holds no secret: GH_TOKEN is read from the keychain on each
use, and is a value GitHub refuses when the keychain has none. Git gets a
credential helper that drops every earlier one and hands the agent's token to
github.com only, commits as the agent's no-reply address and signs with its
key.
The lock lives in the session's environment, which a session that ignores it
could change. So machine also locks the owner away, as optional hardening
for a machine that runs agents. Its plan lists signing gh out of every
account other than the agent's, active or not, and removing a git password
for github.com saved in the macOS keychain. The one yes covers them, and a no
leaves them in place with everything else. On a laptop you also use for your
own work, saying yes signs you out of your own GitHub tooling. The stronger
alternative is a separate macOS user that runs only the agent sessions: none
of your logins, keychain or SSH keys are in it, and nothing of yours is signed
out. A sign-out that fails stops nothing; it goes under "Worth fixing". So
does each SSH key in ~/.ssh with no passphrase, with
ssh-keygen -p -f <key> to add one; agents' signing keys are left out,
since sessions sign with them and they have no passphrase on purpose. The owner's SSH access is left alone,
since it is the owner's own way to GitHub (docs/decisions.md). Agent sessions
send GitHub over HTTPS and refuse SSH, and the pre-push hook refuses their
pushes over SSH. doctor names the account SSH reaches GitHub as without
asking (a key in the SSH agent or the keychain), as fine.
Releases before 0.5.21 asked about each lockout step on its own, and recorded
what was declined in
~/.config/niyam/<agent, lowercased>/lockout-declined.json (under
~/.config/process-rules/ before P-55, which nothing reads since P-57).
doctor reports a login or password in that record as your choice instead of
warning, and an account signed in later is still a warning. Once a machine
run locks them away, the record goes.
When machine signs an account out of gh, "Worth fixing" ends with two
steps only you can take. Restart the Claude desktop app: it keeps the gh
token it read before the move until it restarts, so until then its own
GitHub actions (Auto-fix, the PR bar) run as you, and Auto-fix refuses the
agent's pull requests. And revoke the old token on GitHub (Settings →
Applications → Authorized OAuth Apps → GitHub CLI): gh auth logout deletes
it from the Mac but does not revoke it. machine records the move in
~/.config/niyam/<agent, lowercased>/gh-moved.json, and doctor
repeats both steps while the desktop app was started before it. doctor
cannot see whether the token was revoked, so once the app has restarted it
no longer reminds you to revoke it.