michael-denyer/pstack-claude / plugins/pstack/skills/reflect
reflect
VerifiedMine the active transcript for durable learnings and route each to a concrete edit on an existing skill. Use when the user says reflect.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.0 KB |
| scripts/claude-project-dir.mjs | script | 4.8 KB |
| scripts/find-transcript.mjsexecutable | script | 7.8 KB |
scripts/claude-project-dir.mjs
View on GitHub#!/usr/bin/env node
// Print Claude Code's transcripts directory for this session.
//
// node claude-project-dir.mjs [workspace]
//
// The directory is <config>/projects/<name>, where <config> is
// $CLAUDE_CONFIG_DIR or ~/.claude. Claude Code sets $CLAUDE_CODE_SESSION_ID in
// its shell, so the directory holding <id>.jsonl or <id>/<id>.jsonl is this
// session's, wherever the shell has moved since; only names are read. With a
// workspace argument, or without a session id, <name> is derived from the
// workspace, the current directory by default, which must be the directory the
// session started in. Claude Code
// derives <name> from that path by turning every character other than an ASCII
// letter or digit into "-". A name longer than 200 characters keeps its first 200 and gains "-"
// and a base-36 hash of the path. $CLAUDE_CODE_PROJECT_DIR_NAME replaces <name>
// when $CLAUDE_CONFIG_DIR is set too and the name is 1 to 64 letters, digits,
// "_" or "-" other than a Windows reserved device name. If the derived
// directory is missing, the one directory that shares the first 200 characters
// is taken instead, so a hash that changes in a later Claude Code release still
// resolves. Exits 1 when no directory exists.
import { existsSync, readdirSync, realpathSync } from "node:fs";
import { homedir } from "node:os";
import { join, resolve } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
const MAX_NAME = 200;
// The names Claude Code 2.1.296 accepts from CLAUDE_CODE_PROJECT_DIR_NAME.
const CHOSEN_NAME = /^[A-Za-z0-9_-]{1,64}$/;
const RESERVED_NAME = /^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])$/i;
// A session id names a file, so it never holds a path separator or "..".
const SESSION_ID = /^[A-Za-z0-9-]+$/;
// Claude Code 2.1.296's string hash, a 32-bit Java-style hash.
function hash(text) {
let h = 0;
for (let i = 0; i < text.length; i++) h = ((h << 5) - h + text.charCodeAt(i)) | 0;
return h;
}
export function projectDirName(workspace) {
const name = workspace.replace(/[^a-zA-Z0-9]/g, "-");
if (name.length <= MAX_NAME) return name;
return `${name.slice(0, MAX_NAME)}-${Math.abs(hash(workspace)).toString(36)}`;
}
function sessionDir(projects, sessionId) {
if (!sessionId || !SESSION_ID.test(sessionId) || !existsSync(projects)) return null;
const dirs = readdirSync(projects, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => join(projects, entry.name));
// A bare <id>/ is not enough: Claude Code's Workflow tool creates one under
// the shell's current project, which may be another project.
const transcript = (dir) =>
existsSync(join(dir, `${sessionId}.jsonl`)) || existsSync(join(dir, sessionId, `${sessionId}.jsonl`));
return dirs.find(transcript) ?? null;
}
export function projectDir(
workspace,
{
config = process.env.CLAUDE_CONFIG_DIR,
home = process.env.HOME,
sessionId = process.env.CLAUDE_CODE_SESSION_ID,
chosenName = process.env.CLAUDE_CODE_PROJECT_DIR_NAME,
} = {},
) {
const projects = join(config || join(home || homedir(), ".claude"), "projects");
const session = sessionDir(projects, sessionId);
if (session) return session;
const chosen = config ? chosenName : undefined;
const valid = chosen && CHOSEN_NAME.test(chosen) && !RESERVED_NAME.test(chosen);
const name = valid ? chosen : projectDirName(workspace);
const derived = join(projects, name);
if (existsSync(derived)) return derived;
if (name.length <= MAX_NAME) return null;
const prefix = `${name.slice(0, MAX_NAME)}-`;
const matches = existsSync(projects) ? readdirSync(projects).filter((entry) => entry.startsWith(prefix)) : [];
return matches.length === 1 ? join(projects, matches[0]) : null;
}
// Claude Code names a session by its start directory's real path, and keeps the
// path as given when that directory has since been removed.
function resolvedPath(path) {
try {
return realpathSync(path);
} catch (error) {
if (error.code !== "ENOENT") throw error;
return resolve(path);
}
}
function main(argv) {
if (argv.length > 1) {
console.error("usage: claude-project-dir.mjs [workspace]");
return 2;
}
const workspace = argv[0] ? resolvedPath(argv[0]) : process.cwd();
// A directory argument asks for that workspace's sessions, not this session's.
const dir = projectDir(workspace, argv[0] ? { sessionId: null, chosenName: null } : {});
if (!dir) {
console.error(`no Claude Code transcripts directory for ${workspace}`);
return 1;
}
console.log(dir);
return 0;
}
// node leaves argv[1] unresolved and may set it to a non-file (`node -e ... arg`).
function invokedDirectly() {
if (!process.argv[1]) return false;
try {
return fileURLToPath(import.meta.url) === realpathSync(process.argv[1]);
} catch {
return false;
}
}
if (invokedDirectly()) {
process.exitCode = main(process.argv.slice(2));
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 469k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |