← 返回 Skills 市场
brian-mwirigi

Codesession

作者 brian-mwirigi · GitHub ↗ · v2.5.1
cross-platform ✓ 安全检测通过
2758
总下载
3
收藏
8
当前安装
31
版本数
在 OpenClaw 中安装
/install codesession
功能描述
codesession (codesession-cli, code session, code-session) — Track AI agent session costs, tokens, file changes, and git commits. Works with Claude Code, Open...
使用说明 (SKILL.md)

\r \r

Session Cost Tracking (codesession-cli)\r

\r Track agent session costs, file changes, and git commits. Enforces budget limits and provides detailed session analytics with a full web dashboard.\r \r Latest: v2.5.1 - cs run \x3Ccommand> wraps everything in one step (session + proxy + run + cost summary). cs today for multi-project context. Dashboard Help tab, Codex pricing, security fixes.\r \r 📦 npm • ⭐ GitHub • 📝 Changelog\r \r

Installation\r

\r

# 1. Install the CLI globally from npm\r
npm install -g codesession-cli\r
\r
# 2. Install the OpenClaw skill\r
clawhub install codesession\r
```\r
\r
After installing, the `cs` command is available globally. The OpenClaw agent will automatically use it to track sessions.\r
\r
> **Requirements:** Node.js 18+ and C/C++ build tools (needed to compile the embedded SQLite module).\r
>\r
> | OS | Install build tools |\r
> |---|---|\r
> | **Ubuntu/Debian** | `sudo apt-get install -y build-essential python3` |\r
> | **macOS** | `xcode-select --install` |\r
> | **Windows** | `npm install -g windows-build-tools` or install Visual Studio Build Tools |\r
> | **Alpine** | `apk add build-base python3` |\r
>\r
> Data is stored locally at `~/.codesession/sessions.db`.\r
\r
## When to use\r
\r
- **Always** start a tracked session at the beginning of a multi-step task\r
- **Always** log AI usage after each API call you make\r
- **Always** end the session when the task is complete\r
- Check budget before expensive operations\r
- Use `cs dashboard` to review session data in a browser\r
\r
## Commands\r
\r
### Start tracking\r
```bash\r
# Agent mode (always use --json for structured output):\r
cs start "task description" --json --close-stale\r
\r
# Resume if a session was left open (e.g. after a crash):\r
cs start "task description" --json --resume\r
\r
# Human/interactive mode (stays running with live file watcher):\r
cs start "task description"\r
```\r
\r
> **Agent mode vs interactive mode:** With `--json`, the session is created in the database, JSON is printed, and the process exits immediately -- the session stays "active" and tracks git changes when you run `cs end`. Without `--json`, the process stays running with a live file watcher and git commit poller until you press Ctrl+C or run `cs end` in another terminal.\r
\r
### Log AI usage (after each API call)\r
```bash\r
# With granular tokens (cost auto-calculated from built-in pricing):\r
cs log-ai -p anthropic -m claude-sonnet-4 --prompt-tokens 8000 --completion-tokens 2000 --json\r
\r
# With agent name tracking (NEW in v1.9.1):\r
cs log-ai -p anthropic -m claude-sonnet-4 --prompt-tokens 8000 --completion-tokens 2000 --agent "Code Review Bot" --json\r
\r
# With manual cost:\r
cs log-ai -p anthropic -m claude-opus-4-6 -t 15000 -c 0.30 --json\r
\r
# With all fields:\r
cs log-ai -p openai -m gpt-4o --prompt-tokens 5000 --completion-tokens 1500 -c 0.04 --agent "Research Agent" --json\r
```\r
Providers: `anthropic`, `openai`, `google`, `mistral`, `deepseek`\r
Cost is auto-calculated from a configurable pricing table (21+ built-in models including Codex). Use `cs pricing list --json` to see known models. If a model is unknown, provide `-c \x3Ccost>` manually.\r
\r
**Agent Name (optional):** Use `--agent "Agent Name"` to track which agent performed the work. Perfect for multi-agent systems, A/B testing, and cost attribution. Agent names appear in the dashboard and can be used to filter/analyze costs per agent.\r
\r
### Check current status\r
```bash\r
cs status --json\r
```\r
Returns JSON with current session cost, tokens, files changed, duration. All JSON responses include `schemaVersion` and `codesessionVersion` fields.\r
\r
### End session and get summary\r
```bash\r
cs end -n "completion notes" --json\r
```\r
When ending, codesession automatically scans git for all files changed and commits made since the session started -- even if `--json` mode was used (no live watcher needed).\r
\r
### Web Dashboard\r
```bash\r
cs dashboard\r
# Opens http://localhost:3737 with full analytics UI\r
\r
cs dashboard --port 4000       # custom port\r
cs dashboard --no-open         # don't auto-open browser\r
```\r
\r
The dashboard shows:\r
- **Overview** — KPIs, daily cost/token trends, spend projections, cost velocity\r
- **Sessions** — searchable/sortable table, per-session detail with timeline, files, commits, AI calls, notes\r
- **Models** — per-model & per-provider cost breakdown, token ratios, usage charts\r
- **Insights** — file hotspots, activity heatmap, project breakdown, pricing table\r
- **Alerts** — set daily/total/per-session cost thresholds with alarm mode (sound + browser notifications)\r
- **Start Fresh** — reset all session data from the sidebar\r
\r
### View session details\r
```bash\r
cs show --json --files --commits\r
```\r
\r
### View historical stats\r
```bash\r
cs stats --json\r
```\r
\r
### Export sessions\r
```bash\r
cs export --format json --limit 10\r
cs export --format csv\r
```\r
\r
### Add notes / annotations\r
```bash\r
cs note "Starting refactor phase"\r
cs note "Tests passing, moving to cleanup"\r
```\r
Timestamped annotations appear in `cs show --json` under `annotations`.\r
\r
### Recover stale sessions\r
```bash\r
cs recover --max-age 12\r
```\r
Auto-ends any active sessions older than 12 hours.\r
\r
## Agent Workflow\r
\r
Agents should **always** use `--json` on every command for structured, parseable output.\r
\r
1. At task start: `cs start "Fix authentication bug" --json --close-stale`\r
2. Add context notes: `cs note "analyzing auth flow" --json`\r
3. After each AI call: `cs log-ai -p anthropic -m claude-sonnet-4 --prompt-tokens 8000 --completion-tokens 2000 --agent "Bug Fixer" --json`\r
4. Check spend: `cs status --json` -- read `aiCost` field\r
5. At task end: `cs end -n "Fixed the auth bug, added tests" --json`\r
6. Review past sessions: `cs dashboard`\r
\r
**Tip:** Use the `--agent` flag to identify your agent's work, especially useful in multi-agent systems where different agents handle different tasks (e.g., "Code Review Bot", "Test Writer", "Documentation Agent").\r
\r
## Pricing\r
\r
Pricing is configurable. Run `cs pricing list` to see all known model prices. Override or add models:\r
\r
```bash\r
# Plain model key\r
cs pricing set my-model 5.00 15.00\r
\r
# Provider-namespaced key (avoids collisions)\r
cs pricing set gpt-4o 2.50 10.00 --provider openai\r
```\r
\r
If the model isn't in the pricing table, you must provide `-c \x3Ccost>` when logging.\r
\r
## Proxy mode & cs run (v2.5.0)\r
\r
The fastest way to track any agent run:\r
\r
```bash\r
cs run python my_agent.py\r
# or: cs run --name "fix auth" node agent.js\r
```\r
\r
This starts a session, launches the proxy, runs your command, then ends the session and prints a cost summary. No extra terminals, no env vars to export.\r
\r
If you prefer manual control, start the proxy in one terminal and set env vars:\r
\r
```bash\r
cs proxy --session "my task"   # auto-starts a session too\r
# then in your agent shell:\r
export ANTHROPIC_BASE_URL=http://127.0.0.1:3739\r
export OPENAI_BASE_URL=http://127.0.0.1:3739/v1\r
```\r
\r
The proxy binds to `127.0.0.1` only. It never stores prompt text or API keys — only token counts are written to the session.\r
\r
## Budget awareness\r
\r
If the user has set a budget or you detect high spending:\r
- Check `cs status --json` before expensive operations\r
- Warn the user if `aiCost` exceeds $5.00 in a single session\r
- Suggest cheaper models if costs are escalating\r
\r
## Important\r
\r
- Use `--close-stale` on `cs start` to avoid "session_active" errors from prior crashes\r
- If `cs` is not installed, skip session tracking — don't block the user's task\r
- **Always** use `--json` on every command — agents must use structured output\r
- With `--json`, `cs start` creates the session and exits (no long-running process needed)\r
- Sessions are scoped by **git root** — running from a subdirectory still matches the repo-level session\r
- On errors in `--json` mode, exit code is always `1` and the response has `{ "error": { "code": "...", "message": "..." } }`\r
- Check `schemaVersion` in JSON responses to detect breaking changes\r
\r
## Update check\r
\r
Periodically check if the CLI is up to date (e.g. at session start or once per day):\r
\r
```bash\r
# Compare installed version to latest on npm:\r
cs --version          # installed version\r
npm view codesession-cli version  # latest on npm\r
```\r
\r
If the installed version is behind, notify the user:\r
> "codesession-cli update available: v1.9.4 -> v2.0.0. Run `npm install -g codesession-cli` to update."\r
\r
Don't block the workflow for an update — just inform and continue.\r
\r
## JSON output\r
\r
All commands support `--json` for machine-readable output. Use this when you need to parse session data programmatically.\r
安全使用建议
This skill appears to do what it says: it installs an npm CLI that tracks AI usage and records sessions locally. Before installing, verify the npm package and GitHub repo (links are provided), and be comfortable with a tool that will scan your repository for changes and store session data at ~/.codesession/sessions.db. Note the install requires Node.js and C build tools. If you work with sensitive code or secrets, check whether the CLI has any optional remote syncing or telemetry settings and audit the package sources before installing globally.
功能分析
Type: OpenClaw Skill Name: codesession Version: 2.5.1 The codesession skill is a utility designed to track AI agent session costs, token usage, and file changes using the codesession-cli tool. It provides a structured workflow for agents to log API calls, monitor budgets, and view analytics via a local web dashboard. The skill's instructions (SKILL.md) are transparent and strictly aligned with its stated purpose, and while it utilizes a local proxy and shell wrappers (cs run) to intercept token counts, these behaviors are documented as necessary for its functionality. No evidence of data exfiltration, malicious prompt injection, or unauthorized persistence was found.
能力评估
Purpose & Capability
The name/description claim session-cost and file/git tracking; the skill requires the 'cs' binary and installs the 'codesession-cli' npm package which provides that binary — this is proportionate and expected.
Instruction Scope
Runtime instructions are limited to running the 'cs' CLI (start, log-ai, end, dashboard, etc.). They do instruct automatic scanning of git changes/commits and writing session data to ~/.codesession/sessions.db, which is consistent with the purpose but worth noting because it reads repository content and records local activity.
Install Mechanism
Install uses a public npm package (codesession-cli) which is an expected distribution method for a CLI. The package builds a native SQLite module, so Node.js 18+ and build tools are required — normal but increases install friction.
Credentials
No environment variables, credentials, or unrelated config paths are requested. The data collected is local session metadata (tokens, costs, file/commit lists) stored under the user's home directory, which aligns with the stated function.
Persistence & Privilege
The skill does not request elevated or always-on privileges. It persists session data locally (~/.codesession/sessions.db) and can run a local dashboard server (localhost), so users should be aware of local data storage and any config that might enable remote syncing (not shown in the SKILL.md).
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install codesession
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /codesession 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v2.5.1
**Summary:** v2.5.1 introduces one-line session runs, new dashboard features, and multi-project context. - Added `cs run <command>` for streamlined session tracking, proxying, and cost summary in a single step - Introduced `cs today` for multi-project session context - Dashboard gains a Help tab for easier guidance - Maintains support for Codex pricing, with security and stability fixes - Documentation and descriptions updated to reflect new capabilities
v2.4.0
Codex pricing (codex-mini-latest, gpt-5.1-codex-max, gpt-5.1-codex-mini, gpt-5.3-codex), security fixes, stability improvements
v2.3.0
- Skill description and documentation updated for v2.3.0, including expanded compatibility and feature coverage. - References updated to include integration with Claude Code, OpenClaw, Codex, GPT, Cursor, Windsurf, and Cline. - Added mentions of new features: MCP server support and enhanced integration options. - Removed the redundant _meta.json file.
v2.2.0
Add MCP server for Claude Code integration
v2.1.0
Parallel session support for multi-agent workflows, donate page, auto-log bug fixes
v2.0.1
Remove M-Pesa from donate page, add sponsor links, fix 3 critical auto-log bugs (token loss, TTY hang, position corruption)
v2.0.0
Alerts dashboard, start fresh, insights page, alarm mode, bug fixes
v1.9.8
Bug fixes, removed postinstall script, version sync
v1.9.5
Add GitHub star CTAs to README, post-install message, and dashboard sidebar
v1.9.4
Fix CSV export missing agent data, implement CODESESSION_AGENT_NAME env var fallback, add session ID validation on diff-stats endpoint
v1.9.3
Fix SPA routing on page refresh - /sessions /models /insights now work on refresh
v1.9.2
Updated documentation with agent name tracking examples
v1.9.1
- No changes detected in this release; documentation and features remain unchanged. - Version bump to 1.9.1 with no file or SKILL.md modifications.
v1.8.8
No changes detected in this release. - Version 1.8.8 contains no file changes from the previous release.
v1.8.7
- No user-visible changes in this version. - No file changes detected from the previous release.
v1.8.6
- No changes detected in this version; the SKILL.md file remains unchanged. - This release maintains all previous features and usage instructions.
v1.8.5
- Added an "Update check" section with instructions for periodically verifying if codesession-cli is up to date and non-blocking user notifications for updates. - No changes to functionality or usage instructions; documentation update only.
v1.8.4
- Added explicit installation requirements for C/C++ build tools and platform-specific setup instructions. - Clarified the difference between agent/JSON mode and interactive mode for starting sessions. - Updated all example commands to consistently use --json for structured agent output. - Emphasized that agents should always use --json and that session creation does not require a long-running process. - Improved explanations of how file and commit tracking works in JSON/agent mode. - Removed the emoji from the metadata section.
v1.8.3
- No user-visible changes in this release. - No file changes detected; documentation and functionality remain the same.
v1.8.2
- No file changes detected in this version. - No updates or modifications were made to the skill's documentation or implementation.
元数据
Slug codesession
版本 2.5.1
许可证
累计安装 9
当前安装数 8
历史版本数 31
常见问题

Codesession 是什么?

codesession (codesession-cli, code session, code-session) — Track AI agent session costs, tokens, file changes, and git commits. Works with Claude Code, Open... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 2758 次。

如何安装 Codesession?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install codesession」即可一键安装,无需额外配置。

Codesession 是免费的吗?

是的,Codesession 完全免费(开源免费),可自由下载、安装和使用。

Codesession 支持哪些平台?

Codesession 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Codesession?

由 brian-mwirigi(@brian-mwirigi)开发并维护,当前版本 v2.5.1。

💬 留言讨论