Skip to content

fix(claude-code): make install work + hook never crashes the session#39

Merged
imran-siddique merged 2 commits into
mainfrom
fix/claude-code-install-and-hook-hardening
Jul 16, 2026
Merged

fix(claude-code): make install work + hook never crashes the session#39
imran-siddique merged 2 commits into
mainfrom
fix/claude-code-install-and-hook-hardening

Conversation

@imran-siddique

Copy link
Copy Markdown
Contributor

Pre-launch hardening pass on the claude-code plugin. Found and fixed one install blocker and five hook crash vectors before real users hit them.

🔴 Install blocker

The README tells users to run /plugin marketplace add agentrust-io/integrations then /plugin install agentrust-claude-code, but there was no .claude-plugin/marketplace.json at the repo root, so nobody could install the plugin. Added it (single entry, source: ./claude-code). Passes claude plugin validate ..

🟠 SessionStart hook crashes (broke the "never blocks session start" promise)

Each of these threw an uncaught traceback; all now degrade gracefully and exit 0:

Trigger Before After
malformed settings.json (JSON typo) crash benign msg, exit 0
permissions not a dict crash benign msg, exit 0
.claude.json mcpServers wrong shape crash benign msg, exit 0
~/.claude/skills is a file crash benign msg, exit 0
corrupted baseline.json crashed every future session self-heals next run

Fixes: input-hardened _policy / _mcp_from_config / _skills / _load, plus a last-resort try/except in cmd_hook so any unexpected failure still emits valid SessionStart output and exits 0. _policy still hashes the real file bytes, so a hand-edit is detected as drift even when the JSON is broken.

🟡 UX

/trace and approve --sign without the crypto packages now print a pip install -r requirements.txt hint instead of a raw ModuleNotFoundError.

Validation

  • pytest claude-code/tests/test_capture.py -> 13 passed (added 6 regression tests).
  • ruff check ... --select E,F,W --ignore E501 -> clean.
  • claude plugin validate . -> passed.
  • Re-ran the full crash battery: every vector exits 0 with a benign message; corrupt baseline self-heals on the next session; drift detection still fires.
  • Full 0.3.0 signing path still green: report -> TRACE suite PASS (8/8), manifest validates under agent-manifest 0.3.0.

Also passed (no change needed)

First-run empty home, missing/partial settings, empty skill folders, unicode + emoji names, non-JSON hook stdin, corrupt session-latest.json (verify re-snapshots).

🤖 Generated with Claude Code

imran-siddique and others added 2 commits July 16, 2026 09:25
… installed

The claude-code README documents `/plugin marketplace add agentrust-io/integrations`
+ `/plugin install agentrust-claude-code`, but no `.claude-plugin/marketplace.json`
existed at the repo root, so both commands failed and nobody could install the
plugin. Adds the manifest listing the single plugin (source ./claude-code).
Passes `claude plugin validate .`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Hardens the capture engine so malformed on-disk state degrades gracefully
instead of dumping a traceback at session start:

- _policy: tolerate malformed settings.json and a non-dict permissions block;
  still hash the real file bytes so hand-edits are detected as drift.
- _mcp_from_config: tolerate malformed or misshaped ~/.claude.json (e.g.
  mcpServers as a list).
- _skills: tolerate ~/.claude/skills being a file, and unreadable SKILL.md.
- _load: treat a corrupt baseline/latest as absent so a truncated baseline.json
  (crash mid-write, disk full, racing sessions) self-heals on the next run
  instead of bricking every future session.
- cmd_hook: wrap the body in a last-resort guard that always emits valid
  SessionStart output and exits 0.
- sign_all: a clear "pip install -r requirements.txt" message when the crypto
  packages are absent, instead of a raw ModuleNotFoundError.

Adds 6 regression tests (13 total). Verified: every crash vector now exits 0
with a benign message, a corrupt baseline self-heals, drift detection still
fires, and the full 0.3.0 signing path still passes the TRACE suite.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit a2101ef into main Jul 16, 2026
5 checks passed
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.

1 participant