Skip to content

Support omp (oh-my-pi) sessions: history import and host detection #166

Open

Description

@tejasach06

Problem. Running under omp (it loads Claude Code plugins and sets CLAUDE_PLUGIN_ROOT), the plugin reports host claude and te history import finds nothing: ClaudeCode.history() only reads ~/.claude/projects, while omp keeps sessions in ~/.omp/agent/sessions/<cwd-folder>/<timestamp>_<id>.jsonl.

The omp log is Pi-style (tree of id/parentId entries, toolCall/toolResult, same usage fields), with two differences:

  • the first line is {"type":"title",...}, so pi_session_header (which only checks entry 0) returns {};
  • extra entry types (custom, custom_message, developer, credential_pin, model_change, ...) that must be ignored.

Proposal.

  1. trace/pi.py: make pi_session_header scan the first few entries for type == "session"; have pi_session_to_claude write timestamp and cwd on user lines (needed by claude_log_head / history import).
  2. plugin/hosts.py: add Omp(Pi) with keeps_history = True and a history() that lists omp's session dir, converting each log with pi_session_to_claude into a cache under state_root() (keep the source mtime so the "recent"/"too_old" filters work). Register in HOSTS; add omp to --host.
  3. Host detection: pick omp rather than claude when running under omp (needs a discriminator from omp's hook env; I haven't confirmed which var).
  4. Tests: fixture omp log starting with a title line; assert history lists it and pi_prompt_count ignores non-message entries.

Verified locally with a minimal patch of 1 + a history() hook on ClaudeCode: te history import --dry-run went from nothing to "2 earlier session(s) would be read", and te status showed +2 from earlier history, 44 prompts. Happy to send a PR for 1, 2, 4 if the approach is acceptable; 3 needs maintainer input.

Activity

  1. tejasach06 commented on Nov 8, 2026

    @tejasach06
    Author

    Correction after a closer look: omp does not run the plugin as Claude Code. It loads the Pi extension (plugin/pi/tokeneconomizer.ts), so live sessions are folded under host pi. Its shell sets OMPCODE=1 and PI_SESSION_ID, plus CLAUDECODE=1, and that last one is why te defaults to claude. So the fix belongs on the Pi host:

    • Pi.keeps_history = True, with Pi.history() listing ~/.pi/agent/sessions and ~/.omp/agent/sessions (files are named <timestamp>_<id>.jsonl, and the id comes after the last _).
    • A new Host.log_head(): the default is claude_log_head, and Pi reads pi_session_header. history.plan uses ctx.host.log_head and ctx.host.prompt_count, and replay_envelope reads ctx.host.mechanism_trace(...), so raw Pi logs get folded natively.
    • _still_eligible also accepts *_<sid>.jsonl.
    • pi_session_header scans past omp's leading title line.
    • default_host: OMPCODE=1 means pi, checked before CLAUDECODE.

    I have this on a local branch with a fail-before/pass-after test (tests/test_pi_history.py). The full suite gives 829 passed, 24 skipped on Windows. 2 test_history_import tests fail with or without the patch because of Windows path length (WinError 206). Smoke on a real machine: the 3 omp sessions of a repo were imported under pi, and a real te_bootstrap.py hook --host pi SessionStart→PostToolUse→Stop→SessionEnd cycle folded a session with token usage. I can open a PR.

  2. SakshamUboweja commented on Nov 8, 2026

    @SakshamUboweja
    Collaborator

    Thanks for the detailed write-up and for the follow-up correction. You're right that omp loads the Pi extension, so the fix belongs on the Pi host as you laid out in your comment, including the OMPCODE=1 check before CLAUDECODE in default_host.

    Please go ahead and open the PR with that change and tests/test_pi_history.py. If you can, also include a short note on the omp sessions you checked it against (how many sessions, and what te history import --dry-run and te status showed). That makes it easier to review.

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