Skip to content

Add Agda typecheck skill + SessionStart hook for Claude Code on the web#1220

Closed
williamdemeo wants to merge 3 commits into
masterfrom
claude/agda-skill-and-session-hook
Closed

Add Agda typecheck skill + SessionStart hook for Claude Code on the web#1220
williamdemeo wants to merge 3 commits into
masterfrom
claude/agda-skill-and-session-hook

Conversation

@williamdemeo

Copy link
Copy Markdown
Member

Adds Claude Code (web) configuration so cloud sessions can typecheck Agda through the project's Nix flake. Tooling only — no changes to the specification, the build, or CI. Only .claude/ files are added.

What this adds

  • .claude/skills/agda-typecheck/SKILL.md — a skill documenting the nix develop --command agda <file> workflow, common Agda error triage, and the project's Agda quality gate (explicit type signatures, named lemmas, where over let, helper functions over with, kramdown {.AgdaFunction} spans in prose, no generated artifacts staged, etc.).
  • .claude/hooks/session-start.sh + .claude/settings.json — a SessionStart hook that, in a remote (web) session, installs nix, enables flakes, configures the cache.nixos.org / cache.iog.io substituters (public keys taken from .github/workflows/ci.yml), and pre-warms nix develop so nix develop --command agda <file> is ready. It is guarded by CLAUDE_CODE_REMOTE, idempotent, and non-fatal: if it can't proceed it logs a clear message and exits 0 without blocking session startup.

Why

Cloud sessions start from a fresh clone with no system agda (the project pins Agda and its libraries via the flake). Without this, Claude Code on the web can't machine-check .lagda.md edits. With it, edited modules can be typechecked in-session before pushing.

Network prerequisite

The hook needs the environment's Network access to allow nixos.org and cache.iog.io. Everything else it uses (*.nixos.org, GitHub) is already in the Trusted default allowlist. Configure this per environment (Custom network access + those two domains, keeping the default package-manager list). Until then the hook logs the missing hosts and skips — harmless.

Notes for reviewers

  • This same commit is also bundled into the LEDGER-pov branch ([Dijkstra] CIP-159-11c: Prove LEDGER preservation of value (#1187) #1203) so the tooling is usable while this PR awaits review; this PR is the canonical place to land it on master.
  • The hook runs synchronously (guarantees the toolchain is ready before the session starts, at the cost of slower startup on a cold cache). It can be switched to async (faster startup, with a startup race-condition caveat) if the team prefers.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Any semantic changes to the specifications are documented in CHANGELOG.md (n/a — no spec changes)
  • Code is formatted according to CONTRIBUTING.md (n/a — shell + markdown config only)
  • Self-reviewed the diff

🤖 Generated with Claude Code
https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA


Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Claude Code (web) configuration to provision Nix in remote sessions and document how to typecheck Agda modules via the project’s Nix flake, enabling in-session verification of .lagda.md / .agda edits without changing spec code, build, or CI.

Changes:

  • Adds an Agda typecheck skill documenting the nix develop --command agda <file> workflow and common error triage.
  • Adds a Claude SessionStart hook to install/configure Nix + caches and pre-warm nix develop in remote (web) sessions.
  • Wires the hook via .claude/settings.json.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
.claude/skills/agda-typecheck/SKILL.md Documents the Nix-flake-based Agda typechecking workflow and local quality gate.
.claude/settings.json Registers a SessionStart hook to run the provisioning script.
.claude/hooks/session-start.sh Installs/configures Nix (flakes + caches) and warms the dev shell for agda in remote sessions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to +70
grep -q 'cache.iog.io' "$NIX_CONF" 2>/dev/null || cat >> "$NIX_CONF" <<'CONF'
substituters = https://cache.iog.io https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
CONF

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cfa8c63 — switched to extra-substituters / extra-trusted-public-keys so the caches/keys are appended without clobbering any existing config (the cache.iog.io guard keeps it idempotent).


Generated by Claude Code

Comment on lines +73 to +75
if [ -n "${CLAUDE_ENV_FILE:-}" ] && [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
echo ". \"$HOME/.nix-profile/etc/profile.d/nix.sh\"" >> "$CLAUDE_ENV_FILE"
fi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cfa8c63 — the append is now guarded by a grep -qF, so re-running the hook (e.g. on session resume) no longer duplicates the line.


Generated by Claude Code

@williamdemeo williamdemeo force-pushed the claude/agda-skill-and-session-hook branch from 74b593c to 336ea9d Compare June 25, 2026 04:16
@williamdemeo williamdemeo changed the base branch from master to claude/conway-pov-cleanup June 25, 2026 04:16
@williamdemeo williamdemeo changed the base branch from claude/conway-pov-cleanup to master June 25, 2026 04:17
claude added 2 commits June 25, 2026 15:40
The project typechecks only via its Nix flake; there is no system agda. To make
Agda checking available to Claude Code (this repo, web sessions):

- .claude/skills/agda-typecheck/SKILL.md: documents the `nix develop --command
  agda <file>` workflow, common Agda error triage, and the project quality gate.
- .claude/hooks/session-start.sh + .claude/settings.json: a SessionStart hook
  that installs nix, enables flakes, points at the cache.nixos.org/cache.iog.io
  substituters (keys from ci.yml), and pre-warms `nix develop`. Guarded by
  CLAUDE_CODE_REMOTE; non-fatal and clearly logged if it can't proceed.

NETWORK PREREQUISITE: the hook needs the environment network policy to allow
nixos.org, cache.nixos.org, cache.iog.io and github.com. The default policy in
this session returns 403 for nixos.org and cache.iog.io, so the hook currently
logs that and exits 0 without provisioning. Once the policy permits those hosts,
the toolchain installs and is cached for subsequent sessions.

https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA
Enabling flakes keyed only on the presence of any experimental-features line,
so a bare `experimental-features = nix-command` would skip enabling flakes and
`nix develop` would still fail. Check for `flakes` specifically and append via
extra-experimental-features, which doesn't clobber an existing setting.

https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA
@williamdemeo williamdemeo force-pushed the claude/agda-skill-and-session-hook branch from 336ea9d to 2eae3d4 Compare June 25, 2026 21:40
…append

- substituters/trusted-public-keys override (last-one-wins) any existing config;
  switch to extra-substituters/extra-trusted-public-keys so the caches/keys are
  added without clobbering the environment's configuration.
- the $CLAUDE_ENV_FILE append was unconditional, so re-running the hook (e.g. on
  session resume) duplicated the line; guard it with a grep so it's idempotent.

https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA
@williamdemeo

Copy link
Copy Markdown
Member Author

Closing this in favor of a lighter-weight approach, per review feedback — thanks, Carlos.

The consensus is that a repo-level SessionStart hook is the wrong tool here: it would make every contributor's web session install Nix, and — as it turns out — the upstream installer doesn't run cleanly as root in the managed container anyway. In testing it consistently failed with:

warning: installing Nix as root is not supported by this script!
error: the group 'nixbld' specified in 'build-users-group' does not exist

so the hook couldn't actually provision the toolchain as written.

Replacement, split by where you actually work:

  • Local development (the common case): just nix develop (or direnv with use flake) and launch your editor/tooling from that shell — Agda is on PATH with no per-call overhead. Now documented in CONTRIBUTING.md via CONTRIBUTING: document single-module Agda type-checking via the Nix dev shell #1245.
  • Web sessions (only if you want Claude Code to type-check in-session): provision via the environment's setup script in the web UI (cached, opt-in per environment), not a repo file.

So the .claude/ hook + settings.json here aren't needed, and the agda-typecheck skill content is folded into the CONTRIBUTING note. (For the record, Copilot's two comments on this PR were addressed in cfa8c63 before closing.)


Generated by Claude Code

williamdemeo pushed a commit that referenced this pull request Jun 30, 2026
…ev shell

Adds a short "Type-checking while you work" subsection: enter `nix develop` and run
`agda <file>` (or `nix develop --command agda <file>`) to type-check a single module
— much faster than `nix build` for iterating on a proof — plus a direnv tip to put
the toolchain on PATH and launch your editor/agent tooling from that shell. This is
the lightweight, no-repo-machinery alternative to a SessionStart hook (see #1220).

https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA
williamdemeo pushed a commit that referenced this pull request Jul 2, 2026
…ev shell

Adds a short "Type-checking while you work" subsection: enter `nix develop` and run
`agda <file>` (or `nix develop --command agda <file>`) to type-check a single module
— much faster than `nix build` for iterating on a proof — plus a direnv tip to put
the toolchain on PATH and launch your editor/agent tooling from that shell. This is
the lightweight, no-repo-machinery alternative to a SessionStart hook (see #1220).

https://claude.ai/code/session_0174ZBS1RKAGSbBXDsESUwoA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants