Skip to content

install-hooks and doctor report the Claude Code hook as installed when Claude Code does not apply the settings file #166

Closed

Description

@aminueza

keyfence install-hooks claude-code and keyfence doctor treat the hook as installed once keyfence's entry is in settings.json. They do not check whether Claude Code applies that file. Claude Code ignores the whole file when any PreToolUse entry in it cannot be loaded. keyfence then reports a hook and 42 deny rules that are not in force, and nothing tells the user.

Claude Code's side

Checked with claude doctor, which reads the settings files without signing in, on Claude Code 2.1.317. A file with one PreToolUse entry it cannot load gets this:

.claude/settings.json › hooks.PreToolUse.0: Hook matcher must be an object; received a string — a
PreToolUse/PermissionRequest hook that cannot be loaded may be what guards the permissions declared
beside it, so nothing it sits in is applied until the entry is fixed or removed.

The same "nothing it sits in is applied" text appears for:

PreToolUse entry claude doctor
"x" Hook matcher must be an object; received a string
{"hooks": "y"} Hook matcher "hooks" must be an array of hook entries
{"matcher": "Read", "hooks": [null]} Hook entry must be an object; received null
{"matcher": 5, "hooks": [{"type": "command", "command": "true"}]} Invalid hook matcher (matcher: … expected string, received number)
{"matcher": "Read", "hooks": [{"type": "command"}]} Invalid command hook (command: … expected string, received undefined)

Other bad values cost only themselves, and keyfence already handles those correctly:

  • UserPromptSubmit entry: a malformed entry is reported as matcher ignored; only that entry is dropped.
  • deny value: a non-string value is reported as Non-string value in deny array was removed; only that value is dropped.

The settings docs describe the same split. A value the schema rejects is a Settings Error: in an interactive session Claude Code offers to continue without the broken settings, and a -p run skips them silently.

keyfence's side

On main at 247c418, the last two shapes in the table install without complaint. The first three end in a traceback, which #164 turns into a successful install. In a project directory:

$ printf '{"hooks":{"PreToolUse":[{"matcher":5,"hooks":[{"type":"command","command":"true"}]}]}}' > .claude/settings.json
$ keyfence install-hooks claude-code --project
Hook installed in .../.claude/settings.json for this project.
...
$ keyfence doctor
ok    Claude Code hook: installed (project)
ok    Claude Code prompt hook: installed (project)
$ claude doctor
... hooks.PreToolUse.0: Invalid hook matcher ... nothing it sits in is applied ...

The user sees a hook and deny rules that Claude Code is not applying. In a keyfence session, the Python hook does not run and the .env deny rules are off.

doctor has a related gap. It shows info Claude Code hook: not installed for a file it cannot read at all (invalid JSON, or a section of the wrong type after #165). It does not say why, and a user who knows the hook is in the file has nothing to act on.

Scope

#164, with the change requested in its review, makes install-hooks stop on the three entry shapes keyfence already parses: an entry that is not an object, hooks that is not a list, and a hook that is not an object. This issue covers the rest: entries that are structurally fine for keyfence but that Claude Code's schema rejects, such as the matcher and command cases above. keyfence cannot mirror Claude Code's whole schema, and the schema changes between releases, so a fix should not try to.

Possible directions

  • Point at the authority. After install-hooks claude-code, and in doctor when a Claude Code hook is found, print a line saying claude doctor confirms whether Claude Code applies the file. This is cheap and always correct, but it relies on the user running it.
  • Ask Claude Code. When claude is on PATH, doctor runs claude doctor and reports a FAIL if the settings file it checked is listed under "Invalid settings". In my runs it finished in a few seconds without a login. The output is plain text with no stable format, so a parse failure must degrade to the hint above, never to a false ok.
  • Say why doctor cannot read a file. For an unreadable file, replace not installed with cannot read <path>: <reason>. This changes the current invalid-JSON output, which Read a malformed settings file in doctor like one that is not JSON #165 left alone on purpose.

Acceptance criteria

  • With a PreToolUse entry that Claude Code rejects, keyfence doctor does not print ok for the Claude Code hook in that scope.
  • keyfence install-hooks claude-code either refuses such a file or says after install that Claude Code may not apply it, and how to check.
  • For a settings file it cannot read, keyfence doctor names the file and the reason.
  • If claude doctor is used, a missing claude binary, a timeout or unrecognised output leads to the hint, never to a false ok or a traceback.
  • Tests cover the matcher and command shapes above, plus a UserPromptSubmit entry that is malformed, which must not trigger the warning because Claude Code drops only that entry.

Follows the reviews of #164 and #165.

Activity

  1. self-assigned this
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions