file-access-control

file-access-control is a skill for Claude Code, Codex from liuqihonggit/mcp-cli-bridge. It costs 45 tokens per session (2,819 once invoked), scanned A, original, MIT.

A file-locking procedure for agents that read or write files. It uses a C# script lock with a five-second acquisition timeout and automatic expiry after 30 seconds.

In plain words
What is it for?
Use it when agent operations may read or write shared files and need the required locking workflow.
Why use it?
It helps prevent two operations from accessing the same file at once, which can cause race conditions or lost changes. The lock is acquired before file access and released afterward.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/liuqihonggit/mcp-cli-bridge/file-access-control
Any agent
npx skills add liuqihonggit/mcp-cli-bridge --skill file-access-control
Clone the repo
git clone --depth 1 https://github.com/liuqihonggit/mcp-cli-bridge

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for file-access-control

README.md
[![agentmods](https://agentmods.dev/badge/skills/liuqihonggit/mcp-cli-bridge/file-access-control.svg)](https://agentmods.dev/skills/liuqihonggit/mcp-cli-bridge/file-access-control)
Your own site
<a href="https://agentmods.dev/skills/liuqihonggit/mcp-cli-bridge/file-access-control"><img src="https://agentmods.dev/badge/skills/liuqihonggit/mcp-cli-bridge/file-access-control.svg" alt="Measured on agentmods" height="20"></a>
Per session 45 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,819 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00045 $0.02819
Opus 5 $0.00023 $0.01409
Sonnet 5 $0.00009 $0.00564
Haiku 4.5 $0.00005 $0.00282

Measured 4d ago against content hash 1685195d261b, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

file-access-control scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.trae/skills/file-access-control/SKILL.md · 411 lines

How it starts

The opening of the file, as written. The whole thing — 411 lines — stays where its author put it; the contents beside it link to each section on GitHub.

File Access Control

This skill enforces mandatory file locking before any file access operations to prevent race conditions and ensure data integrity.

Workflow

访问文件前
    ↓
检查 .csx 锁脚本是否存在?
    ↓ 否
创建锁脚本 (子智能体)
    ↓
调用 .csx 脚本获取文件锁
    ↓
5秒内获取成功?
    ↓ 否                    ↓ 是
委派子智能体做其他事情    执行文件操作
                          ↓
                          释放锁

命名规范

锁脚本名称

常量 说明
LockScript.FileName FileAccessGuard.csx 文件访问守卫脚本
LockScript.Directory .trae/skills/file-access-control/ 脚本存放目录

Rules

1. 锁脚本检查与创建

访问任何文件前,必须先检查锁脚本是否存在:

// 使用 nameof 和 typeof 避免硬编码
public static class LockScript
{
    public const string FileName = nameof(FileAccessGuard) + ".csx";
    public const string Directory = ".trae/skills/file-access-control/";
    public static readonly string FullPath = Path.Combine(Directory, FileName);
}

// 检查脚本是否存在
if (!File.Exists(LockScript.FullPath))
{
    // 委派子智能体创建锁脚本 FileAccessGuard.csx
    // 不要自己创建,让子智能体来做
}

2. 调用锁脚本获取锁

# 使用 dotnet-script 运行 .csx 脚本
dotnet script .trae\skills\file-access-control\FileAccessGuard.csx -- "C:\path\to\file.txt" acquire

3. 锁脚本标准接口

锁脚本必须支持以下命令:

命令 功能 返回值
acquire <filepath> 获取文件锁 SUCCESS / TIMEOUT / ERROR
release <filepath> 释放文件锁 SUCCESS / ERROR
status <filepath> 检查锁状态 LOCKED:<pid> / FREE / EXPIRED

锁脚本实现 (FileAccessGuard.csx)

#!/usr/bin/env dotnet-script
#r "System.IO.FileSystem"

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

// 配置
const int ACQUISITION_TIMEOUT_SECONDS = 5;  // 5秒抢不到就放弃
const int LOCK_EXPIRY_SECONDS = 30;         // 锁30秒自动过期
const int RETRY_INTERVAL_MS = 100;          // 重试间隔100毫秒

// 命令行参数解析
if (Args.Count < 2)
{
    Console.WriteLine("ERROR: Usage: dotnet script FileLock.csx -- <command> <filepath>");
    Console.WriteLine("Commands: acquire, release, status");
    Environment.Exit(1);
}

string command = Args[0].ToLower();
string targetFilePath = Args[1];
string lockFilePath = $"{targetFilePath}.scx.lock";

switch (command)
{
    case "acquire":
        Environment.Exit(await AcquireLockAsync() ? 0 : 1);
        break;
    case "release":
        Environment.Exit(ReleaseLock() ? 0 : 1);
        break;
    case "status":
        Console.WriteLine(GetLockStatus());
        Environment.Exit(0);
        break;
    default:
        Console.WriteLine($"ERROR: Unknown command '{command}'");
        Environment.Exit(1);
        break;
}

// 获取锁
async Task<bool> AcquireLockAsync()
{
    var startTime = DateTime.UtcNow;

    while ((DateTime.UtcNow - startTime).TotalSeconds < ACQUISITION_TIMEOUT_SECONDS)
    {
        // 清理过期锁
        await TryRemoveExpiredLockAsync();

        try
        {
            // 尝试独占创建锁文件
            using var fs = new FileStream(
                lockFilePath,
                FileMode.CreateNew,
                FileAccess.Write,
                FileShare.None,
                bufferSize: 4096,
                useAsync: true);

            using var writer = new StreamWriter(fs);
            await writer.WriteLineAsync($"PID:{Environment.ProcessId}");
            await writer.WriteLineAsync($"Time:{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}");
            await writer.WriteLineAsync($"ExpirySeconds:{LOCK_EXPIRY_SECONDS}");
            await writer.FlushAsync();

            Console.WriteLine("SUCCESS");
            return true;
        }
        catch (IOException)
        {
            // 锁被占用,等待重试
            await Task.Delay(RETRY_INTERVAL_MS);
        }
    }

    // 5秒超时
    Console.WriteLine("TIMEOUT");
    return false;
}

// 释放锁
bool ReleaseLock()
{
    try
    {
        if (File.Exists(lockFilePath))
        {
            File.Delete(lockFilePath);
            Console.WriteLine("SUCCESS");
            return true;
        }
        Console.WriteLine("SUCCESS: Lock not found");
        return true;
    }
    catch (Exception ex)
    {
        Console.WriteLine($"ERROR: {ex.Message}");
        return false;
    }
}

// 获取锁状态
string GetLockStatus()
{
    if (!File.Exists(lockFilePath))
        return "FREE";

    try
    {
        var lines = File.ReadAllLines(lockFilePath);
        DateTime? lockTime = null;
        double expirySeconds = LOCK_EXPIRY_SECONDS;
        string? pid = null;

        foreach (var line in lines)
        {
            if (line.StartsWith("PID:"))
                pid = line[4..].Trim();
            if (line.StartsWith("Time:") && DateTime.TryParse(line[5..].Trim(), out var lt))
                lockTime = lt.ToUniversalTime();
            if (line.StartsWith("ExpirySeconds:") && double.TryParse(line[14..].Trim(), out var exp))
                expirySeconds = exp;
        }

        // 检查是否过期
        if (lockTime.HasValue && (DateTime.UtcNow - lockTime.Value).TotalSeconds > expirySeconds)
            return "EXPIRED";

        return pid != null ? $"LOCKED:{pid}" : "LOCKED:UNKNOWN";
    }
    catch
    {
        return "ERROR";
    }
}

// 清理过期锁
async Task TryRemoveExpiredLockAsync()
{
    if (!File.Exists(lockFilePath))
        return;

    try
    {
        var lines = await File.ReadAllLinesAsync(lockFilePath);
        DateTime? lockTime = null;
        double expirySeconds = LOCK_EXPIRY_SECONDS;

        foreach (var line in lines)
        {
            if (line.StartsWith("Time:") && DateTime.TryParse(line[5..].Trim(), out var lt))
                lockTime = lt.ToUniversalTime();
            if (line.StartsWith("ExpirySeconds:") && double.TryParse(line[14..].Trim(), out var exp))
                expirySeconds = exp;
        }

        if (lockTime.HasValue && (DateTime.UtcNow - lockTime.Value).TotalSeconds > expirySeconds)
        {
            File.Delete(lockFilePath);
        }
    }
    catch { /* 忽略清理错误 */ }
}

Read the full file on GitHub · 411 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 411 lines · 45 tokens per session scan A 1685195d261b

Subscribe to this mod's changes

file-access-control is a skill published in the GitHub repository liuqihonggit/mcp-cli-bridge (0 stars, last pushed 3mo ago), licensed MIT. It adds 45 tokens to every session and 2,819 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

local-ai-agents

Build local-first AI agents that run entirely on a developer workstation with Microsoft Foundry Local and Qwen function-calling models. Covers Small Language Models (SLMs), the OpenAI-compatible local endpoint, sandboxed local tools, local RAG with Chroma, local MCP servers, hybrid cloud/local routing, and the…

microsoft/ai-agents-for-beginners · 200 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

next-cache-components-optimizer

Drive a Next.js route to instant navigation by setting up an agentic loop, under Cache Components / PPR, on initial load (hard navigation) and client-side navigation (soft navigation). Encode the goal as a failing @next/playwright instant() e2e and work it to green, one verified route at a time; the shipped test then…

vercel/next.js · 170 tokens

next-partial-prefetching-adoption

Turn on Partial Prefetching in a Next.js app and work through the insights it surfaces. Use when the user wants to enable or adopt Partial Prefetching, flip the partialPrefetching flag, opt routes in with export const prefetch = 'partial', audit Link prefetch={true} behavior, preserve existing prefetched UI with…

vercel/next.js · 103 tokens

chronicle

Analyze Copilot session history for standup reports, usage tips, session search, and session reindexing. Use when the user asks for a standup, daily summary, usage tips, workflow recommendations, wants to search or find past sessions by keyword/file/PR, wants to reindex their session store, or asks about deleting…

microsoft/vscode · 72 tokens