Skip to content

An interrupted --install leaves ~/.claude/settings.json.openrepotools.XXXXXX behind: hook_write_settings' temporary is in no trap's reach, before or after #250's #332

Open

Description

@brettheap

What happens

hook_write_settings writes ~/.claude/settings.json through a temporary beside it (openRepoTools:3548-3560 at main 33ce26d): mktemp makes settings.json.openrepotools.XXXXXX (:3552), cp fills it (:3554), chmod 600 (:3556), and mv -f moves it into place (:3558). It removes the temporary on each failure it sees, in the three || { rm -f -- "$hook_tmp"; die … } arms (:3555, :3557, :3559). Those arms run only when the command fails and the shell goes on. A run killed by a signal between the mktemp and the mv never reaches them, as the probe below shows.

Nothing else knows its name. The only trap is the EXIT trap workdir sets (:248-253): rm -rf -- "$WORKDIR"; [ -z "$PLACING" ] || rm -f -- "$PLACING"*. PLACING (:85) is set only by place_by_rename (:2027) and cleared after its mv (:2062), so it is empty when hook_write_settings runs, and hook_write_settings never sets it. The next --install makes a new temporary and looks at none of the old ones: the template appears in code at :3552 and nowhere else. hook_write_settings is reached from both hook arms (:3610, :3636) and from wip init through place_hook_pair (:4223).

Measured (main 33ce26d, bash 5.2.21; an --install run from an export of that commit, which fetches nothing; a sandbox HOME, CLAUDE_USER_DIR and TMPDIR; a hook target that answers guard; a cp first on PATH that sleeps 3 s when handed a settings.json.openrepotools.* path; SIGINT to the process group, as Ctrl-C sends it, once the temporary exists)

  • The run dies of SIGINT (the harness reports -2), the EXIT trap removes the workdir, and ~/.claude/settings.json.openrepotools.X600kT is left behind: empty, at 0600.
  • With chmod as the stalled tool instead, so the signal lands after cp: the leftover is 528 bytes at 0600 and holds the merged settings, hooks key included.

SIGTERM and SIGHUP take the same path by reading; they were not probed.

Does #250 change it? No. #250's branch (14695e1; issue #250 is still open) adds an INT trap (:289) that runs remove_workdir (:281-284) and then dies of the signal as before. remove_workdir removes $WORKDIR and $PLACING*, the same two things main's EXIT trap removes. hook_write_settings is the same text at 14695e1 (:3614-3626) and sets no PLACING. The same probe at 14695e1 left the same file: killed by SIGINT, the workdir gone, and settings.json.openrepotools.hhXzCu behind. The comment there names what the trap leaves, the $(…) waits and the SIGTERM window (14695e1:openRepoTools:262-277), and not this write. #250's title, "A SIGINT at any instant of --install's placement ends the run and leaves no temporary", is true of place_by_rename's temporaries and not of this one.

Why it matters

Low. No installed state is wrong: settings.json itself is only ever renamed over, so it is whole or untouched. What remains is a file named like a temporary in ~/.claude, one per interrupted run, which no later run removes. Where the signal lands after the cp, it is a full copy of the person's merged settings, at 0600 because mktemp made it so. It is the fault #167 closed for place_by_rename's temporaries; this is the one temporary --install makes that the trap was never taught.

Suggested fix (nothing here is decided)

  • Give the temporary a prefix the trap knows, as place_by_rename does (:2027-2062): PLACING="$(dirname -- "$settings")/settings.json.openrepotools.$$." before the mktemp, mktemp -- "${PLACING}XXXXXX", and PLACING="" after the mv and in each failure arm. The pid keeps the prefix this run's own, so the trap's rm -f -- "$PLACING"* cannot take another run's temporary. No test names the settings.json.openrepotools. template (searched tests/ at 33ce26d).
  • Or place the settings through place_by_rename, one temporary mechanism for every file this installer writes. It would also change the temporary's name and add its owner check and refusal text.
  • A case for it: test_a_run_killed_mid_placement_leaves_no_temporary (tests/test_openrepotools_command.py:905) signals as soon as the first *.openrepotools.* appears (SLOW_TOOLS, :888). On a fresh home that is the first bin file's, so the settings write is never where it lands, though placement_temporaries (:535-545) already lists ~/.claude. A second case could run --install twice, with settings.json removed before the second so that the settings temporary is the only one, send SIGINT to the group and SIGTERM to the shell, and assert placement_temporaries(home) == []. It should fail on main and on 14695e1, as the probe does.

Not run: the shell suite; the fix; SIGTERM or SIGHUP at this write; wip init's path; any platform but Linux. The second case above is a sketch, and whether anything else in that second run makes a temporary was not checked.

See also #331, the late-link gap in the same write to settings.json.

Found by: the probe of #250's 14695e1 made while drafting #250's follow-ups (2026-10-23), re-run against main 33ce26d for this issue. Filed on Brett Heap's word of 2026-10-23T18:52:34Z, by multiple choice.

Lane: openRepoTools-5

Activity

  1. brettheap commented on Oct 24, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoTools-5, session 0d83dca2-c18c-4bb0-99ce-896e6cafea02@Eagle, 2026-10-24T14:19:38Z, for #332

    Logged in lanes/log/openRepoTools-5.md at 9e4a3521ca05f865d7bbc58e7b435bdbb8e32b5c.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoTools#332:
       none
    2. `gh pr list --repo opensoft/openRepoTools --state all --search "#332"`, kept where the row or its body names `#332`:
       none
    3. `git ls-remote --heads [email protected]:opensoft/openRepoTools` branches naming `332` as a whole token:
       none
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions