This document is for contributors who need to modify ClawChain runtime behavior, UI flows, proof export, chain integration, or cross-platform validation.
README is user-facing and deployment-oriented. This file is the engineering reference.
Use this guide when you need detailed information about:
- repository architecture
- the generalized agent-adapter model
- Codex and Claude Code runtime behavior
- setup and bootstrap internals
- proof export expectations
- cross-platform validation and debugging
ClawChain currently has two validated agent paths:
- Codex Preserved through the existing Codex rollout path.
- Claude Code Integrated through the shared shell-agent adapter path.
The runtime is structured so future shell-style agents can be added by extending the profile model instead of duplicating launcher logic.
- Python 3.12
pip install -r requirements.txtpip install -e .- a Conda environment such as
ClawChain
Useful optional tools:
- Foundry:
anvil,forge - Docker as a fallback only
- tmux on Linux
- Claude Code installed and authenticated for real CLI validation
clawchain/agent_profiles.pyAgent profile registry. Extend this first when adding a new shell-style agent.clawchain/shell_agent_integration.pyShared launcher, resume, handoff, environment, and shim generation for shell agents.clawchain/host_monitor.pyLive process discovery, session matching, managed/native state detection, and mixed-session handling.clawchain/agent_proxy_cli.pyMain CLI entrypoint, prepare/onboard/service flow, proof building, and chain commands.clawchain/ui_server.pyUI backend, session views, proof export, restore actions, and mixed-session warnings.clawchain/agent_proxy.pyRuntime bootstrap, Foundry handling, local EVM setup, and proxy helpers.clawchain/agent_proxy_daemon.pyBackground service daemon with Linux/Windows IPC behavior.clawchain/agent_proxy_config.pyStored config model and persistence.
clawchain/codex_integration.pyCodex-specific integration helpers.clawchain/codex_rollout.pyCodex rollout capture model.clawchain/codex_rollout_monitor.pyCodex-specific rollout watcher.
setup_clawchain.cmdWindows one-click setup entrypoint.setup_clawchain.ps1Windows setup implementation.setup_clawchain.shLinux/macOS one-click setup entrypoint.run_clawchain_ui.cmdWindows UI launcher.run_clawchain_ui.shLinux/macOS UI launcher with remote-access logic.
scripts/smoke_claude_adapter.pyClaude-oriented adapter smoke.scripts/platform_smoke.pyCross-platform setup/service/proof smoke driver.scripts/run_linux_smoke.shscripts/run_windows_smoke.ps1scripts/run_windows_smoke.cmdscripts/run_evm_smoke.sh
ClawChain can be understood as two execution families sharing one recovery, proof, and chain backend.
Codex still uses a dedicated rollout monitoring path.
Use this path when:
- you need existing Codex behavior preserved
- the profile uses
watcher_kind = codex-rollout - you are regression-checking shared runtime changes against Codex
Claude Code is the first validated user of the shared shell-agent path.
This path is responsible for:
- launcher generation
- controlled resume and handoff
- environment injection
- dangerous command shims
- managed terminal detection
- mixed native/managed session warnings
Design target:
- future shell-style agents should be added by extending
agent_profiles.py - shared launcher logic should stay in
shell_agent_integration.py - Codex-only rollout assumptions should not leak into the shared adapter path
A profile should define:
- executable name
- agent id
- launcher template
- resume behavior
- handoff behavior
- watcher kind
- agent-specific session-id extraction rules when needed
Do not bury agent-specific identity assumptions inside ui_server.py or agent_proxy_cli.py if they belong in the profile layer.
shell_agent_integration.py should remain the common place for:
- wrapper generation
- controlled PATH and environment setup
- shim installation
- account/session directory layout
- managed launcher creation
Do not fork the launcher flow per agent unless the shared path cannot express the behavior.
If a change is only needed for Codex rollout capture, keep it inside the Codex-specific modules.
Claude integration has a few critical behavior rules.
Claude session matching should prefer real Claude session identifiers instead of path-based placeholders.
Expected sources include:
~/.claude/sessions/<pid>.json- Claude project session files under
~/.claude/projects/...
Goal:
- prefer a real
resume:<session-id>identity when available - avoid collapsing unrelated Claude sessions into the same
path:*fingerprint
Claude can easily end up with both:
- the original native terminal
- the ClawChain-managed terminal after
Join Monitor
A successful Join Monitor does not make commands typed in the old native terminal recoverable. UI and monitoring logic must make this visible.
A Claude session should only be treated as truly routed when the managed process is actually present. If takeover did not succeed, do not mark the session as safely monitored.
setup_clawchain.cmd delegates to setup_clawchain.ps1.
Current PowerShell sequence:
- stop the old service if present
- run
deploywithout starting the service - run
chain-connect --bootstrap-local-evmunless disabled - run
service-start - run
service-status - run
chain-statuswhen chain bootstrap succeeded - launch the UI
Important environment variables:
CLAWCHAIN_ACCOUNT_IDCLAWCHAIN_PASSWORDCLAWCHAIN_WORKSPACECLAWCHAIN_ROOT_PARENTCLAWCHAIN_AUTO_INSTALL_FOUNDRYCLAWCHAIN_ANVIL_PATHCLAWCHAIN_FORGE_PATHCLAWCHAIN_SKIP_CHAIN_BOOTSTRAPCLAWCHAIN_REQUIRE_CHAINCLAWCHAIN_DEPLOYER_PRIVATE_KEY
setup_clawchain.sh mirrors the same sequence with shell-native path handling and remote-friendly UI launch behavior.
Preferred order:
- explicit
anvil_pathandforge_path - managed toolchain under account-local
toolchains/foundry/bin - automatic Foundry download from official releases
- optional Docker fallback where supported
Important principle:
- Docker is not the preferred Windows path
- local Foundry is the intended primary path on all platforms
Current proof export expectations:
exported_atis full ISO 8601, not time-onlysession.evidence.snapshot_locationspoints intorecovery-vault/recovery-snapshots/...session_dangerous_operations[].target_rootmatches the absoluteproof_cards[].target_root- chain state is reflected back into exported proof evidence when available
- fresh Claude and Codex proofs should have the same exported structure once anchored
If the issue is presentation-only, prefer export normalization over changing the recovery model.
python -m py_compile \
clawchain/agent_profiles.py \
clawchain/shell_agent_integration.py \
clawchain/agent_proxy.py \
clawchain/agent_proxy_cli.py \
clawchain/host_monitor.py \
clawchain/ui_server.pypython scripts/smoke_claude_adapter.pybash scripts/run_linux_smoke.sh
bash scripts/run_linux_smoke.sh --bootstrap-local-evmpowershell -ExecutionPolicy Bypass -File scripts/run_windows_smoke.ps1
powershell -ExecutionPolicy Bypass -File scripts/run_windows_smoke.ps1 --bootstrap-local-evmbash scripts/run_evm_smoke.shUse this when changing shared runtime infrastructure to ensure Codex did not regress.
- Run setup for the current platform.
- Confirm
chain-status local-operatorreturnsok: true. - Open the UI.
- Join a fresh Codex session.
- Trigger a delete action.
- Restore it.
- Export the proof log.
- Confirm the proof shows EVM anchor data.
Use this when changing Claude integration, session identity logic, or mixed-session handling.
- Start a fresh Claude Code session.
- Open the UI.
- Click
Join Monitor. - Continue only in the ClawChain-managed Claude terminal.
- Trigger a delete-style destructive action.
- Confirm the action appears in history.
- Restore it.
- Export the proof log.
- Confirm the proof shows a fresh
evm:31337anchor, notlocal-json.
Use this when modifying host_monitor.py or ui_server.py.
- Start a native Claude terminal.
- Join the same session into ClawChain.
- Keep both native and managed terminals alive.
- Confirm the UI marks the session as mixed or warns that commands in the native terminal are not captured.
- Confirm session cards do not jump to unrelated sessions.
For a newly anchored Codex or Claude session proof, all of the following should hold:
format = clawchain-proof-log.v2exported_atis a full ISO 8601 timestampsession.status = monitored- at least one
session_dangerous_operationsentry exists for the delete action restored = truefor the restored operation- snapshot locations point into
recovery-vault/recovery-snapshots session_dangerous_operations[].target_rootmatchesproof_cards[].target_rootproof_cards[].anchor_backend = evm:31337proof_cards[].anchor_mode = evm-anchoredproof_cards[].anchor_status = confirmedproof_cards[].anchor_lookup_found = trueproof_cards[].anchor_field_checks.session_id = trueproof_cards[].anchor_field_checks.batch_seq_no = trueproof_cards[].anchor_field_checks.merkle_root = true
Run:
python -m clawchain.agent_proxy_cli chain-connect local-operator --bootstrap-local-evmInspect:
bootstrap_diagnostics.anvil_pathbootstrap_diagnostics.forge_pathbootstrap_diagnostics.managed_foundry_bin_dirbootstrap_diagnostics.managed_foundry_bin_contentsbootstrap_diagnostics.managed_foundry_install_error
Check:
- whether
~/.claude/sessions/<pid>.jsonexists for the live process - whether the process cwd matches the expected project path
- whether project-session lookup is accidentally borrowing a different workspace session
- whether the UI is displaying an old registry row instead of the current live session
Usually one of these is true:
- the operation was performed in the original native Claude terminal, not the managed terminal
Join Monitordid not complete actual process takeover- the session was detected but still
detected-only, notmanaged
Check live session state before changing recovery logic.
Focus on:
host_monitor.pyfingerprint generation- old
path:*rows in the session registry - UI
session_refgeneration for non-concrete rows - mixed native/managed rows collapsing into the same card
Before publishing significant runtime changes, confirm all of the following:
- Codex regression flow passes
- Claude acceptance flow passes
- Windows setup with chain bootstrap passes
- Linux setup with chain bootstrap passes
- proof export shape remains stable
- README, README.zh-CN, and DEVELOPER docs are updated together
- no Claude-specific workaround has leaked into Codex-only rollout logic