Installation and self-management
Tirith provides a path from an installed command-line tool to an active shell and AI-tool guard. Its setup commands detect the local environment, create or refresh the needed policy and integration links, check that protection is live, and manage updates without taking ownership of package-manager installs. For the wider command model, see CLI and user workflows; for command checks after setup, see Interactive safety workflows and Command safety engine.
Installation lifecycle
The installation lifecycle separates getting the binary onto a machine from making its safeguards active. After installation, an engineer normally initializes a shell hook, creates or selects a policy, adds any tool integrations, and confirms the result with doctor.
flowchart LR
A[Install Tirith] --> B[Detect environment]
B --> C[Choose policy]
C --> D[Activate shell hook]
D --> E[Configure AI tools]
E --> F[Run doctor]
F --> G[Protected shell and tools]
The lifecycle is designed to be repeatable. Read-only checks can describe the current state before changes, while setup commands avoid replacing existing user configuration unless the operator asks to force an update.
References: crates/…/main.rs• L12-23 crates/…/main.rs• L713-781 crates/…/onboard.rs• L100-137 crates/…/doctor.rs• L7-65
Release installer
The release installer places a Tirith binary in a user-writable bin directory and then prints the shell activation step. It selects a release for Linux or macOS on supported CPU types, or uses the version named by TIRITH_VERSION.
The installer checks the release checksum and requires the release signature by default. TIRITH_ALLOW_UNSIGNED=1 permits checksum-only installation as an explicit supply-chain trade-off. On x86_64 Linux, the binary and its privileged package-approval helper are published as one protected operation; a partial failure attempts to restore both earlier states.
References: scripts/install.sh• L1-14 scripts/install.sh• L165-241 scripts/install.sh• L243-309 scripts/install.sh• L426-553
Onboarding
tirith onboard builds a bounded picture of the current repository and recommends a policy template that fits its use. It considers the shell, editor and AI configuration, package tools, lock files, CI workflows, MCP configuration, and the current Tirith setup state.
The AI configuration signal covers the wider set of agent instruction files and directories used by Tirith. The report also includes a stable JSON form for tools that need to consume the detected state.
The recommendation can be automatic or biased by an explicit operating mode:
| Mode | Purpose |
|---|---|
| Automatic | Selects an AI-agent-heavy template for a strong AI or MCP surface, a CI-strict template for CI, or individual defaults otherwise. |
--repo | Favors a single-repository setup while still recognizing CI. |
--team | Favors shared team defaults. |
--ai-agent-heavy | Favors controls for frequent agent activity. |
The default report does not change files. --apply offers the missing safe steps one at a time and refuses to act when it cannot confirm an interactive terminal. It can install the shell-hook line and create a policy only when no policy exists.
References: crates/…/onboard.rs• L62-118 crates/…/onboard.rs• L140-185 crates/…/onboard.rs• L197-278 crates/…/onboard.rs• L397-482 crates/…/onboard.rs• L547-636
Policy initialization
tirith policy init creates the policy that controls how the safety engine behaves for a repository. It uses the repository root when one is available and otherwise uses the current directory; policy discovery later uses the configured root, the repository walk-up, and the user configuration area.
Policy templates turn common operating goals into starting points. The available families include individual, CI-strict, AI-agent-heavy, OSS maintainer, startup, enterprise, and MCP-strict settings. Initialization is no-clobber by default, so an existing policy must be deliberately replaced.
References: crates/…/policy.rs• L11-18 crates/…/policy.rs• L118-185 crates/…/policy.rs• L255-340 docs/troubleshooting.md• L316-323
Shell integration
The shell integration loads a shell-specific hook into each new interactive session. The hook checks commands and paste actions before they take effect, then exposes the session's protection state for status and recovery workflows.
tirith init prints the activation statement rather than editing a profile. It detects the active shell when no shell is named and supports zsh, bash, fish, PowerShell, and Nushell. The output is safe to evaluate or source in the form expected by each shell.
For POSIX shells, the activation statement also binds the hook to the running Tirith installation. This keeps the shell session tied to the selected binary when a package launcher or version manager would otherwise resolve another executable. On Windows, the hook keeps the shell's normal executable lookup because the POSIX binding contract does not apply.
sequenceDiagram
participant Profile as Shell profile
participant Init as tirith init
participant Hook as Shell hook
participant Check as Tirith check
Profile->>Init: Load activation line
Init-->>Profile: Source shell hook
Profile->>Hook: Start session guard
Hook->>Check: Submit command or paste
Check-->>Hook: Allow, warn, or block
Hook-->>Profile: Continue or stop the action
Hook assets can be found beside an installed binary or materialized into Tirith's data area when needed. A materialized set is checked against the current embedded assets and repaired when it is stale or changed.
References: crates/…/init.rs• L116-155 crates/…/init.rs• L157-297 crates/…/init.rs• L390-406 crates/…/init.rs• L495-725 docs/troubleshooting.md• L3-20
Profile management
tirith setup can add the shell activation line to the detected profile as a managed block. The block has clear markers so repeat runs can update only Tirith's section and preserve the rest of the profile.
The normal setup path is idempotent. A matching block is left alone, changed content requires --force, and malformed or duplicate managed blocks are reported instead of silently removing user content. --dry-run shows the intended change without writing it.
References: crates/…/shell_profile.rs• L70-125 crates/…/shell_profile.rs• L142-190 crates/…/shell_profile.rs• L221-361
Bash protection modes
Bash has two protection modes because not every Bash and Readline pair can safely intercept the Enter key. Enter mode can stop a typed command before execution; preexec mode checks through Bash's debug path and is warn-only unless its stricter conditions are enabled.
Tirith tests Enter delivery for the local Bash environment and caches the result. A failed or uncertain test selects the less strict mode for new shells. A runtime failure can also downgrade the current session and record a safe-mode state until the operator resets it or explicitly requests Enter mode.
References: docs/troubleshooting.md• L138-189 docs/troubleshooting.md• L224-277 crates/…/doctor.rs• L44-50 crates/…/shell_profile.rs• L225-237
Non-interactive zsh guard
AI tools and scripts can start non-interactive zsh -lc sessions without loading the interactive shell hook. The optional zsh environment guard covers that path so direct shell execution does not bypass the configured protection.
tirith setup prints this guard by default for supported tools and installs it only with --install-zshenv. The guard is managed separately in ~/.zshenv, where it preserves surrounding user content and requires --force to repair drift or remove duplicates.
References: crates/…/zshenv.rs• L12-35 crates/…/zshenv.rs• L38-133 crates/…/tools.rs• L15-24 docs/troubleshooting.md• L336-357
Prompt status
The optional --prompt-status output adds a prompt segment that shows the live protection mode. It is separate from command interception, so users can enable visible status without changing the guard's decision rules.
The prompt integration uses the state already maintained by the shell hook and avoids duplicate wrapping when it is loaded more than once. Nushell does not expose the same live non-exported status signal, so its generated guidance does not claim to provide a live status segment.
References: crates/…/init.rs• L128-138 crates/…/init.rs• L299-388 crates/…/main.rs• L820-844 docs/troubleshooting.md• L67-71
Shell completions
tirith completions <shell> prints completion definitions from the same command model that drives the CLI. This keeps shell tab completion aligned with the commands and options accepted by the running binary.
The command is a generator rather than a profile editor. The operator directs its output into the completion mechanism used by the selected shell, so installation and reload remain under the shell's normal rules.
References: crates/…/completions.rs• L1-9 crates/…/main.rs• L1474-1480 crates/…/main.rs• L8181-8185
AI-tool setup
tirith setup <tool> connects Tirith to supported AI coding tools by placing the tool's hook or extension and merging the tool's configuration. The goal is to cover the tool's command path and, where supported, its MCP path rather than rely on the user's interactive shell alone.
The supported host set includes Claude Code, Cline, Codex, Copilot CLI, Continue, Cursor, fx, Gemini CLI, Grok Build, Kiro, OMP, OpenClaw, OpenCode, OpenHands, Pi CLI, Prime Agent, Roo Code, VS Code, and Windsurf. The command checks required host dependencies before it writes generated configuration. It records an absolute validated Tirith path in generated hooks and configurations.
| Setup concern | Result |
|---|---|
| Hook or extension | Tool actions can be checked before execution. |
| JSON or tool configuration | Tirith entries are merged with existing settings where the tool supports merging. |
| MCP registration | Supported tools can route MCP traffic through Tirith. |
| Scope | Project or user settings determine who receives the protection. |
| Refresh | --update-configs refreshes generated hooks and gateway config without re-registering MCP or changing shell profiles. |
--update-configs is a refresh operation. It replaces stale generated files while leaving registration and shell integration steps out of that run. --with-mcp is limited to integrations that need that explicit choice; other hosts register MCP as part of their normal setup or do not support that option.
References: crates/…/mod.rs• L39-89 crates/…/mod.rs• L139-155 crates/…/mod.rs• L158-257 crates/…/tools.rs• L402-496 crates/…/main.rs• L1151-1187
Project and user scopes
Project scope keeps integration files with one repository, while user scope applies them across the user's tool sessions. The default is project scope for most tools, but the supported hosts define their own limits.
| Scope rule | Hosts |
|---|---|
| Both project and user | Claude Code, Cursor, Gemini CLI, Grok Build, Kiro, OpenClaw, OpenCode, OpenHands, and Pi CLI. |
| Project only | Copilot CLI, Continue, Roo Code, and VS Code. |
| User only | Cline, Codex, fx, OMP, Prime Agent, and Windsurf. |
An engineer should choose project scope when the repository owns the workflow and user scope when the guard must follow the developer across repositories. A project-scoped integration can contain machine-specific paths for some tools, so it may not be suitable for committing to a shared repository.
References: crates/…/mod.rs• L57-89 crates/…/mod.rs• L193-256 crates/…/mod.rs• L259-282 crates/…/tools.rs• L402-415
MCP and gateway links
For MCP-aware tools, setup can register Tirith as the local server or gateway that stands between the tool and its upstream MCP server. This extends protection beyond shell text to the tool-call route used by the AI client.
The gateway configuration is copied into the user configuration area. Codex receives an immutable, content-addressed gateway generation before its registration changes, while other tools merge the expected server entry into their own configuration shape. Existing entries are checked for drift and are not replaced without force.
References: crates/…/mod.rs• L518-676 crates/…/tools.rs• L499-705 crates/…/tools.rs• L735-784 crates/…/merge.rs• L7-92 crates/…/main.rs• L1046-1069
Package installation safeguards
tirith install adds a safety step before a package manager or remote install script changes the machine. It analyzes the requested install, shows the result, records the transaction, and runs the real action only after the applicable decision and approval.
The package-manager form is analysis plus a recorded transaction. It does not sandbox the package manager. The URL form also reviews the downloaded script and runs it through the same contained path used for remote scripts.
Package-manager transactions
The package-manager form supports npm, pip, Cargo, apt, Homebrew, dnf, yum, pacman, Scoop, Docker, and Go. Analysis is offline by default; --online adds registry signals, while --offline and TIRITH_OFFLINE keep the analysis local.
The command can stop after analysis with --no-exec. A warning needs acknowledgement, while a block refuses the install unless the configured bypass rules apply. The real package manager is run directly rather than through a shell, and the transaction is recorded even when execution is refused after analysis.
References: crates/…/install.rs• L47-73 crates/…/install.rs• L1801-1836 crates/…/install.rs• L2390-2614 crates/…/install.rs• L2714-2783
Remote install scripts
The URL form first analyzes the URL as a download and then analyzes the script body after download. A blocked preflight stops before the download; an inspection run with --no-exec records the reviewed result without running the script.
Live URL execution is not available as a mixed JSON-and-child-output mode. JSON is therefore inspection-only for a live URL run, which keeps the output a single trusted document. On Unix, an allowed script runs through the verified contained executor and produces a receipt.
References: crates/…/install.rs• L3774-4007 crates/…/install.rs• L4096-4129 crates/…/install.rs• L4395-4469
Health checks
tirith doctor explains whether the installation is ready and whether the current shell is actively protected. It combines local install facts with hook state, policy discovery, threat-data state, shell compatibility signals, runtime containment coverage, and recent detection coverage so an engineer can separate a missing setup step from a live session downgrade.
The full report bounds its audit-log inspection. When the recent log tail is too large, it marks the detection-coverage result as partial instead of presenting the analyzed records as the full history. The report also distinguishes hidden findings in the records it could analyze from a claim about all past commands.
The main diagnostic is read-only. --fix offers confirmed repairs for missing hooks, stale hook assets, absent policy, detected AI-tool setup, threat data, and Bash safe mode. It returns a failure status when one or more selected repairs fail, while PATH-shadow findings remain guidance for a manual fix. --compat focuses on shell and terminal interaction, while --bundle writes a redacted report for support work.
References: crates/…/doctor.rs• L7-65 crates/…/doctor.rs• L72-227 crates/…/doctor.rs• L949-1065 crates/…/doctor.rs• L1258-1398 crates/…/doctor.rs• L2494-2954
Quick health checks
tirith doctor --quick is a small, read-only status view for tools that poll protection often. It reports the live protection mode, the policy selected for the current directory, and whether the shell profile is configured.
Quick mode skips large or slow sources such as the audit log, threat database, anomaly baseline, PATH shadow search, and Bash capability cache. Its JSON shape is stable and is suitable for an editor integration that needs a frequent status check.
References: crates/…/doctor.rs• L1166-1238 docs/doctor-modes.md• L3-31 docs/doctor-modes.md• L33-68
Diagnostic recovery
Doctor results distinguish requested settings from live hook state. This matters when a hook has downgraded during a session or when doctor runs in a process that never sourced the hook.
Common recovery actions are to start a fresh interactive shell after changing the binary or profile, re-measure Bash Enter delivery with --simulate-enter, reset persistent Bash safe mode when appropriate, and inspect alternate Tirith binaries when PATH shadowing is reported. A doctor bundle can be attached after review because it masks secrets and the literal home path.
References: crates/…/doctor.rs• L829-866 crates/…/doctor.rs• L2494-2708 crates/…/doctor.rs• L3050-3132 docs/troubleshooting.md• L73-75 docs/troubleshooting.md• L114-136
Compatibility and support reports
doctor --compat narrows the report to shell, terminal, requested mode, effective mode, and live protection status. doctor --bundle writes a redacted support file that includes the useful setup state without dumping the full environment or exposing the home-directory name.
These reports serve different audiences. Compatibility output helps an operator fix the active shell, while the bundle gives support staff a reviewable artifact for a wider installation problem.
References: crates/…/doctor.rs• L1816-1832 crates/…/doctor.rs• L1834-1889 crates/…/doctor.rs• L2187-2227 crates/…/doctor.rs• L2243-2459
Self-update lifecycle
Tirith treats the installed binary's ownership as part of the update decision. version --provenance reports local build and install facts without network access; verify-self performs an explicit release check; update changes the binary only when Tirith owns that installation.
flowchart TD
A[version --provenance] --> B{Need full check?}
B -->|Yes| C[verify-self]
B -->|No| D[Continue locally]
C --> E{Install method}
E -->|Package manager| F[Print package-manager upgrade]
E -->|Self-managed| G[Download latest release]
G --> H[Verify checksum and signature]
H --> I[Atomic binary replacement]
I --> J[Keep previous binary]
J --> K[update --rollback if needed]
Network access is explicit for verification and update. A release checksum mismatch or failed signature check stops an update. A checksum-only update requires the explicit --allow-unsigned choice.
References: crates/…/selfupdate.rs• L1-32 crates/…/selfupdate.rs• L454-535 crates/…/selfupdate.rs• L1098-1115 crates/…/selfupdate.rs• L1171-1261
Install provenance
version --provenance identifies the running binary, its release target, its digest when available, and the detected install method. It also identifies Hermes-managed private release caches when their ownership and path remain proven. Its verification result is local and honest: it does not claim a release match when the check needs the network or when the binary is a development or source-built variant.
verify-self goes further by obtaining the matching release assets, checking the archive checksum, checking the release signature when possible, and comparing the release binary to the running bytes. It reports an unverified state when verification is not possible and a failure when a check proves a mismatch.
References: crates/…/selfupdate.rs• L190-227 crates/…/selfupdate.rs• L262-452 crates/…/selfupdate.rs• L570-597 crates/…/selfupdate.rs• L645-696
Package-managed updates
Package-manager installations are never replaced by tirith update. The command identifies the install method and prints the matching upgrade action so the package manager keeps ownership and its records remain correct.
This rule also applies when the install method is unknown. Tirith refuses to guess that it owns the binary, which avoids turning an uncertain installation into a self-managed one by accident.
References: crates/…/selfupdate.rs• L1171-1185 crates/…/selfupdate.rs• L1542-1599 crates/…/selfupdate.rs• L46-64
Self-managed updates and rollback
A self-managed installation can update in place after the latest release is found and verified. The replacement is atomic, so the installed path presents either the old or new binary rather than a partial file.
The previous binary is kept as the rollback point created by the last successful self-managed update. tirith update --rollback restores that point only for a self-managed installation; package-managed installs must use their package manager to select an older version. --dry-run shows the planned action without changing the binary.
On x86_64 Linux, updates for supported release-based installs also keep the package-approval helper in step with the main binary. If that paired state is missing or ambiguous, the update or rollback stops instead of selecting only one side.
References: crates/…/selfupdate.rs• L1297-1463 crates/…/selfupdate.rs• L1601-1680 crates/…/selfupdate.rs• L1733-1959 crates/…/selfupdate.rs• L2901-2988
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the shell names and activation forms aligned between
init, profile setup, and the materialized hook set. - Treat changes to the managed profile or zsh environment markers as a compatibility change for existing user files.
- Keep the
setuphost list, scope rules, generated executable-path contract, Python dependency binding, and per-tool configuration shapes aligned. - Keep
onboardrecommendation names aligned with the policy template names accepted bypolicy init, and keep its AI/MCP detection surface aligned with the rest of Tirith. - Preserve the distinction between quick doctor fields and the full diagnostic so polling clients do not start reading expensive or unstable data.
- Keep the full doctor coverage report honest about bounded audit-log reads and partial history before changing its finding summary.
- Keep install-method detection aligned with the update rule that forbids self-replacement of package-managed binaries, including the separate proof for Hermes-managed caches.
- Keep release verification, atomic replacement, backup naming, paired Linux helper state, and rollback behavior aligned as one lifecycle contract.
- Keep package-install source names, online/offline behavior,
--no-execoutcomes, registry coverage, and direct execution rules aligned. - Keep the release installer’s checksum/signature policy aligned with the self-update verification policy and its paired binary/helper rollback path.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A different tirith binary shadows the active one on PATH | A profile or tool can load the wrong program and show misleading setup results. | init and doctor report shadow binaries; inspect PATH and restart the shell after correction. |
| A launcher or version manager hides the native binary behind another process | A POSIX shell hook can lose the identity of the installation that initialized the session. | init binds POSIX shell hooks to the running Tirith executable; restart the shell after correcting the installation. |
| Hook assets are missing or stale | A profile may load no guard or an older guard. | doctor detects materialization state; --fix can refresh the assets. |
| A managed profile block is changed or unbalanced | Setup refuses to replace it to avoid deleting user content. | Review the profile and use --force only after repairing or accepting the drift. |
| Bash Enter delivery is broken or becomes unsafe | The session falls back to preexec warn-only protection. | Capability self-tests, visible downgrade state, doctor --simulate-enter, and safe-mode reset. |
| An existing AI-tool or MCP entry differs from Tirith's expected entry | Setup stops before silently changing another integration. | Review the entry and use --force for an intentional replacement. |
| A generated hook cannot use the validated Tirith or Python executable path | The setup refuses to write a configuration that could resolve a different program later. | Fix the executable path or dependency, then rerun setup from a trusted environment. |
| A package-manager executable or source configuration changes between analysis and execution | The requested package operation is refused rather than redirected to new program or source bytes. | Restore the approved executable and source state, then rerun tirith install. |
| An install URL is blocked during preflight | No remote script is downloaded or run. | Review the finding and use a trusted, reviewed source if the install is intentional. |
| JSON is requested for a live URL install | Tirith refuses the mixed-output mode before contacting the URL. | Use --no-exec for JSON inspection or run the live install without JSON. |
| The audit history exceeds the bounded doctor read | The coverage view describes only the inspected recent tail and cannot support a claim about older records. | Treat the truncation notice as a scope limit and inspect the full audit data separately when needed. |
| A selected doctor repair fails | The command can leave setup incomplete while a zero exit status would hide the failure. | doctor --fix returns non-zero when any remediation fails; review the failed action and rerun it. |
| The release installer cannot verify a checksum or required signature | The binary is not installed; on a paired Linux update, the earlier state is restored when possible. | Correct the release or verification environment; use checksum-only mode only as an explicit informed choice. |
update cannot classify the install as self-managed | Tirith does not replace the binary. | Update through the original package manager or reinstall from a trusted source. |
| Release checksum or required signature verification fails | The update stops before replacing the working binary. | Correct the release or verification environment and retry; do not bypass a mismatch. |
| The paired Linux package-approval state is missing or ambiguous | Update or rollback refuses to change only part of the installation. | Restore or reinstall the matching helper and main binary as one release pair. |
Key files
| File | Why to read it |
|---|---|
| scripts/install.sh | Explains release download, checksum and signature checks, first installation, and paired Linux publication recovery. |
| crates/…/main.rs | Defines the public lifecycle commands and connects CLI arguments to their command handlers. |
| crates/…/init.rs | Explains shell detection, activation output, native executable binding, hook lookup, materialization, and prompt integration. |
| crates/…/onboard.rs | Shows the first-run environment report, policy recommendation, and guarded apply flow. |
| crates/…/policy.rs | Defines policy initialization and the available starter policy families. |
| crates/…/mod.rs | Defines supported AI tools, setup scope rules, generated executable paths, and refresh behavior. |
| crates/…/tools.rs | Shows how tool-specific hooks, configurations, MCP links, and zsh guards are coordinated. |
| crates/…/shell_profile.rs | Defines safe, repeatable shell-profile integration. |
| crates/…/zshenv.rs | Defines protection for non-interactive zsh sessions. |
| crates/…/install.rs | Defines package-manager and URL install analysis, approval, recording, and execution boundaries. |
| crates/…/doctor.rs | Defines full, quick, compatibility, repair, bounded coverage, and diagnostic-bundle health views. |
| crates/…/completions.rs | Defines generated shell completion output from the CLI command model. |
| crates/…/selfupdate.rs | Defines provenance reporting, release verification, package-manager-aware updates, atomic replacement, and rollback. |
| docs/doctor-modes.md | Gives the operator-facing contract for full and quick doctor checks. |
| docs/troubleshooting.md | Describes recovery paths for shell hooks, Bash modes, PATH shadowing, and tool integration failures. |