Skip to content

feat(claude-code): symmetric onboard/uninstall + new tj reset (resolves #117, #118, #121) - #442

Merged
anshss merged 10 commits into
mainfrom
cc-install-remove
Jul 9, 2026
Merged

anshss merged 10 commits into
mainfrom
cc-install-remove

Conversation

@anshss

@anshss anshss commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Combines three merged-ready fixes into one symmetric install/remove flow for the Claude Code integration, then redesigns the removal UX into two clearly-named commands:

Uninstall/reset redesign: two commands, no flag

Per product decision, replaced the --purge/--remove-package flag model with two clearly-named commands:

  • tj uninstall → full removal by default: the Layer-2 config/daemon/wiring teardown (MCP dereg, ~/.zshrc OTEL block + claude() wrapper, per-project settings, daemon) plus Layer-1 package removal (what --purge used to gate). This is now the single symmetric counterpart to tj onboard. Installer-aware behavior is preserved: pipx/uv-tool installs auto-run their uninstall; a plain pip/venv install only gets the exact command printed (never guessed); an ephemeral runner (uvx/pipx run) is a safe no-op with an explanation.
  • tj reset (new) → Layer-2 teardown only — package stays installed, ready to tj onboard again. Useful for reconfiguring or pausing without reinstalling the CLI.
  • The shared Layer-2 teardown was extracted into _teardown_side_effects() in cmd_uninstall.py (pure refactor) so both commands call the same code path.
  • --purge, --remove-package, and the old second "also remove the package?" prompt are gone. The single top-level confirmation for tj uninstall now states both consequences (config + package removal) up front.
  • npx tokenjam uninstall / npx tokenjam reset both work through the existing generic npm-wrapper passthrough — no wrapper changes needed.
  • Docs (docs/claude-code-integration.md, docs/cli-reference.md) updated to the new model.

Greptile fixes applied

  • [P1] _is_ephemeral_runner() in cmd_uninstall.py no longer misclassifies uv-managed Python runtimes (.../uv/python/cpython-.../bin/python3) as ephemeral — it now only matches uv's cache dirs (/uv/archive-, /uv/builds-, .cache/uv/), so tj uninstall's package-removal step no longer silently no-ops for a pip install-into-uv-managed-Python setup.
  • _strip_zshrc_otel_blocks() in cmd_onboard.py — both the sentinel-block and legacy-marker regexes required a trailing \n after the end marker, so a managed block that was the last line of a file with no final newline was left behind (leaking a bearer token). Trailing newline is now optional.
  • _unwire_claude_wrapper() in cmd_onboard.py — same class of bug on the wrapper's end marker; fixed the same way.
  • Package-removal tests now mock _installed_via_uv_tool/_is_ephemeral_runner (not just _installed_via_pipx) so they no longer depend on the CI runner's own sys.executable.

Supersedes #439, #441, #440 — those are the per-ticket branches now folded into this single PR.

Test plan

  • python -m pytest tests/unit/ tests/integration/ -q → 2102 passed, 1 skipped, 2 warnings in 40.37s
  • ruff check clean on all touched files
  • Verified zero leftover <<<<<<</>>>>>>>/======= conflict markers across both the three-way feature merge and the later main sync merge
  • Verified zero remaining --purge/--remove-package/--keep-package references anywhere in tokenjam/, tests/, docs/ (grep-confirmed)
  • Manually confirmed tj uninstall --help / tj reset --help show the new command surface with no stale flags

🤖 Generated with Claude Code

anshss and others added 8 commits July 10, 2026 00:17
#117)

`tj onboard --claude-code` writes a `claude()` shell function into
~/.zshrc (and ~/.bashrc) via `_install_claude_wrapper()`, but
`tj uninstall` had no counterpart removal path — leaving a `claude()`
function that calls `tj` on every launch, which errors once the
package is uninstalled. Add `_unwire_claude_wrapper()` (marker-delimited
removal, mirroring the install path) and call it from `cmd_uninstall`.
Also wire in the existing but never-called `_unwire_claude_output_cap_hook()`
so an opted-in PostToolUse cap hook is cleaned up too.

Co-Authored-By: Claude <[email protected]>
…t; document symmetric npx remove (#121)

Extends `tj uninstall`'s existing --remove-package opt-in (#430) to make
`npx tokenjam uninstall` a complete, symmetric counterpart to `npx tokenjam
onboard`: detect uv-tool installs (not just pipx/pip) and auto-run the
matching removal command, and detect ephemeral runners (uvx/pipx run) to
make --purge a safe no-op with an explanation instead of guessing at a
removal command that doesn't apply. --purge is added as an alias for
--remove-package so existing scripts/tests keep working.

Co-Authored-By: Claude <[email protected]>
…ip legacy markers (#118)

The ~/.zshrc OTEL export block was keyed on a single-line comment marker
that had itself already drifted once in this repo's history: the ocw->tj
rebrand (commit 281275f) renamed "# ocw harness observability" to
"# tj harness observability" but never migrated already-onboarded users'
shell rc files. A block written under the older marker was invisible to
both re-onboard's "replace in place" (which only matched the current
marker) and `tj uninstall`'s removal — so re-onboarding APPENDED a second
block with a fresh bearer token instead of replacing the stale one, and
uninstall left old-marker blocks behind.

Replace the marker with a stable, content-based sentinel pair
(">>> tokenjam OTEL (managed) >>>" / "<<< tokenjam OTEL <<<") that will
never be renamed. onboard now strips ALL managed blocks — the sentinel
pair plus every known legacy marker — before appending exactly one fresh
block; uninstall strips the same set. The removal routine
(_strip_zshrc_otel_blocks) is shared between both commands.

Co-Authored-By: Claude <[email protected]>
…ent marker (#118)

Promotes the #118 root cause into Critical Rules so future onboard/uninstall
dotfile-writing features (zshrc blocks, shell wrappers, etc.) use a stable
sentinel + strip-all-legacy-markers pattern from the start, instead of
re-discovering the same marker-drift bug.

Co-Authored-By: Claude <[email protected]>
Applies four fixes found while combining #117/#118/#121 into one branch:

- _is_ephemeral_runner() no longer misclassifies uv-managed Python
  runtimes (.../uv/python/...) as ephemeral — only uv's cache dirs
  (archive-/builds-/.cache/uv/) count, so `tj uninstall --purge` no
  longer silently no-ops for pip-into-uv-python installs (P1).
- _strip_zshrc_otel_blocks() and _unwire_claude_wrapper() both required
  a trailing newline after their end marker, so a managed block that
  was the last line of a file with no final newline was left behind
  (leaking a bearer token). Trailing newline is now optional.
- test_remove_package_flag_non_pipx_prints_command now mocks
  _installed_via_uv_tool/_is_ephemeral_runner so it no longer depends
  on the CI runner's own sys.executable.

Co-Authored-By: Claude <[email protected]>
@anshss
anshss requested a review from anilmurty as a code owner July 9, 2026 19:07
ruff F401 — all real usages go through uninstall_mod.subprocess (patching
the module's own import), not the top-level `subprocess` name.

Co-Authored-By: Claude <[email protected]>
@greptile-apps

greptile-apps Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR completes the symmetric install/remove flow for the Claude Code integration by folding three separate fixes into one coherent change. It correctly resolves stale bearer-token accumulation in ~/.zshrc (#118), the missing _unwire_claude_wrapper counterpart that broke claude after tj uninstall (#117), and the uv-tool / ephemeral-runner detection gap in tj uninstall --purge (#121).

  • cmd_onboard.py: introduces stable sentinel delimiters (_ZSHRC_OTEL_START/END) and a shared _strip_zshrc_otel_blocks() that erases every managed block (current sentinel + both legacy markers) before writing exactly one fresh block; adds _unwire_claude_wrapper() as the symmetric counterpart to _install_claude_wrapper(), with a correctly optional trailing-newline regex on the end marker.
  • cmd_uninstall.py: adds _installed_via_uv_tool() / _is_ephemeral_runner() (with a deliberately narrow cache-dir match to avoid mis-classifying uv-managed Python runtimes), wires both into _remove_package and the interactive prompt, and exits early for ephemeral runners so --purge is a safe no-op.
  • Tests: three new unit-test files plus two new integration tests cover the sentinel/legacy-strip round-trip, all sys.executable path shapes, the no-trailing-newline edge cases, and end-to-end wrapper removal — and test_remove_package_flag_non_pipx_prints_command is made hermetic by mocking all three detection functions.

Confidence Score: 5/5

Safe to merge — the three bug fixes are well-scoped, the regexes are correct (sentinel DOTALL non-greedy, optional-trailing-newline on both remove paths), and every new code path is covered by at least one targeted test.

All three onboard/uninstall mutations (_strip_zshrc_otel_blocks, _unwire_claude_wrapper, ephemeral-runner detection) are implemented correctly, the critical no-trailing-newline edge cases are explicitly tested, and the test_remove_package_flag_non_pipx_prints_command hermeticity fix removes a real CI-environment dependency. No new unguarded paths were introduced.

No files require special attention. The one style note (redundant /uv/tools/ check in _is_ephemeral_runner) is dead code with no runtime impact.

Important Files Changed

Filename Overview
tokenjam/cli/cmd_onboard.py Adds _zshrc_otel_block, _strip_zshrc_otel_blocks, and _unwire_claude_wrapper; refactors zshrc write to strip-then-write with stable sentinels; all three helpers carry correct optional-trailing-newline regexes.
tokenjam/cli/cmd_uninstall.py Adds _installed_via_uv_tool, _is_ephemeral_runner, ephemeral-runner early-exit, and uv-tool branch in _remove_package; drops the now-unused re import; all hint helpers updated for the new install type.
tests/unit/test_onboard_zshrc_otel.py New unit-test file; covers sentinel block, both legacy-marker variants, no-trailing-newline edge cases, and full onboard/uninstall round-trip semantics for _strip_zshrc_otel_blocks.
tests/unit/test_uninstall_runner_detect.py New unit-test file; exhaustively covers all sys.executable path shapes (pipx, uv-tool, uvx cache, pipx run cache, plain pip, uv-managed Python runtime) and the uv-runtime non-ephemeral regression.
tests/unit/test_uninstall_wrapper.py New unit-test file; covers _unwire_claude_wrapper (round-trip, idempotent, no-trailing-newline edge case, bashrc co-cleanup) and an end-to-end CLI test asserting no claude() / tj residue after tj uninstall.
tests/integration/test_cli_uninstall.py Drops the subprocess import that's now unused; makes test_remove_package_flag_non_pipx_prints_command hermetic by also mocking _installed_via_uv_tool and _is_ephemeral_runner; adds uv-tool, ephemeral-runner, and prompt-suppression test cases.
tests/integration/test_cli.py Adds MagicMock import and two integration tests for the zshrc OTEL sentinel/legacy-strip behaviour on both onboard and uninstall paths.
CLAUDE.md Adds rule 21 documenting the sentinel-block invariant and the migration lesson from the ocw->tj rebrand for future managed-dotfile-block features.
docs/claude-code-integration.md Rewrites the Uninstalling section to document the symmetric one-command pair, --purge detection logic, and ephemeral-runner behaviour.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant CLI
    participant onboard as cmd_onboard
    participant uninstall as cmd_uninstall
    participant zshrc as ~/.zshrc / ~/.bashrc
    participant settings as ~/.claude/settings.json

    Note over User,settings: tj onboard --claude-code (install)
    User->>CLI: tj onboard --claude-code
    CLI->>onboard: _onboard_claude_code()
    onboard->>zshrc: _strip_zshrc_otel_blocks (remove sentinel + legacy markers)
    onboard->>zshrc: write one fresh sentinel-delimited OTEL block
    onboard->>onboard: _install_claude_wrapper()
    onboard->>zshrc: append claude() wrapper block
    onboard->>settings: write OTEL env vars and hooks

    Note over User,settings: tj uninstall (symmetric remove)
    User->>CLI: tj uninstall --purge --yes
    CLI->>uninstall: cmd_uninstall()
    uninstall->>settings: remove OTEL env vars, resume-brief hook, output-cap hook
    uninstall->>onboard: _strip_zshrc_otel_blocks (sentinel + all legacy blocks)
    onboard->>zshrc: regex-remove managed OTEL block
    uninstall->>onboard: _unwire_claude_wrapper()
    onboard->>zshrc: regex-remove WRAPPER_MARKER block
    uninstall->>uninstall: _is_ephemeral_runner()?
    alt ephemeral runner uvx or pipx run
        uninstall->>User: nothing persistent to remove, purge is no-op
    else pipx or uv-tool install
        uninstall->>User: auto-runs pipx or uv tool uninstall tokenjam
    else plain pip install
        uninstall->>User: prints pip uninstall tokenjam command
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant CLI
    participant onboard as cmd_onboard
    participant uninstall as cmd_uninstall
    participant zshrc as ~/.zshrc / ~/.bashrc
    participant settings as ~/.claude/settings.json

    Note over User,settings: tj onboard --claude-code (install)
    User->>CLI: tj onboard --claude-code
    CLI->>onboard: _onboard_claude_code()
    onboard->>zshrc: _strip_zshrc_otel_blocks (remove sentinel + legacy markers)
    onboard->>zshrc: write one fresh sentinel-delimited OTEL block
    onboard->>onboard: _install_claude_wrapper()
    onboard->>zshrc: append claude() wrapper block
    onboard->>settings: write OTEL env vars and hooks

    Note over User,settings: tj uninstall (symmetric remove)
    User->>CLI: tj uninstall --purge --yes
    CLI->>uninstall: cmd_uninstall()
    uninstall->>settings: remove OTEL env vars, resume-brief hook, output-cap hook
    uninstall->>onboard: _strip_zshrc_otel_blocks (sentinel + all legacy blocks)
    onboard->>zshrc: regex-remove managed OTEL block
    uninstall->>onboard: _unwire_claude_wrapper()
    onboard->>zshrc: regex-remove WRAPPER_MARKER block
    uninstall->>uninstall: _is_ephemeral_runner()?
    alt ephemeral runner uvx or pipx run
        uninstall->>User: nothing persistent to remove, purge is no-op
    else pipx or uv-tool install
        uninstall->>User: auto-runs pipx or uv tool uninstall tokenjam
    else plain pip install
        uninstall->>User: prints pip uninstall tokenjam command
    end
Loading

Reviews (2): Last reviewed commit: "Merge branch 'main' into cc-install-remo..." | Re-trigger Greptile

Comment thread tokenjam/cli/cmd_uninstall.py Resolved
@anshss
anshss merged commit df2e4bf into main Jul 9, 2026
4 checks passed
@anshss anshss changed the title feat(claude-code): complete symmetric install/remove flow (resolves #117, #118, #121) feat(claude-code): symmetric onboard/uninstall + new tj reset (resolves #117, #118, #121) Jul 9, 2026
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